要在Java中调用Windows API,最简单的方法就是使用JNative.jar中提供的接口。该库已经对Linux和Windows系统中的API进行了封装,

例如对Windows,使用它里面的接口调用就和在Delphi等开发工具中的调用方法是一样的,因为函数的名字和参数都是一样的。下面说明其用法。


安装方法:将JNative.jar加到classpath中即可。

假如现在要给QQ的窗口发送消息,程序如下:

import org.junit.Test;
import org.xvolks.jnative.misc.basicStructures.HWND;
import org.xvolks.jnative.misc.basicStructures.LPARAM;
import org.xvolks.jnative.misc.basicStructures.UINT;
import org.xvolks.jnative.misc.basicStructures.WPARAM;
import org.xvolks.jnative.util.User32;

public class JNativeLearning {
	
	@Test
	public void sendMessage() throws Exception{
		HWND hWnd = User32.FindWindow("TXGuiFoundation", "QQ2010");
		if(hWnd.getValue()>0){
			System.out.println("window exists");
			User32.SendMessage(hWnd, new UINT(0x10), new WPARAM(0), new LPARAM(0));
		}else{
			System.out.println("window doesn't exists");
		}
	}

}

其它接口请参见其JavaDoc:http://jnative.free.fr/docs/

转载: http://qujianfeng.iteye.com/blog/1258363


GitHub 加速计划 / li / linux-dash
7
1
下载
A beautiful web dashboard for Linux
最近提交(Master分支:5 个月前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐