有我的流程列表:
public class lab2 {
public static void main(String args[]) {
Kernel32 kernel32 = Kernel32.INSTANCE;
User32 user32 = User32.INSTANCE;
Tlhelp32.PROCESSENTRY32.ByReference processEntry = new Tlhelp32.PROCESSENTRY32.ByReference();
WinNT.HANDLE snapshot = kernel32.CreateToolhelp32Snapshot(
Tlhelp32.TH32CS_SNAPPROCESS, new WinDef.DWORD(0));
char path[] = new char[512];
HWND hWnd = User32.INSTANCE.GetWindowModuleFileName(hWnd, path, 512);
try {
while (kernel32.Process32Next(snapshot, processEntry)) {
System.out.println(Native.toString(processEntry.szExeFile)
+ "\t" + Native.toString(path));
}
} finally {
kernel32.CloseHandle(snapshot);
}
}
}
我尝试将变量路径设置为文件的完整路径。我收到错误 @Type mismatch:无法在HWND hWnd = User32.INSTANCE.GetWindowModuleFileName(hWnd, path, 512);
中从int转换为WinDef.HWND @ 我哪里出错了?怎么做对了?谢谢。
答案 0 :(得分:1)
您使用的功能错误。
如,
User32 user32 = User32.INSTANCE;
char path[] = new char[512];
long sleepTime = 2000;
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {}
HWND hWnd = user32.GetForegroundWindow();
user32.GetWindowModuleFileName(hWnd, path, 512);
System.out.println("Foreground Window Module FileName: " +
Native.toString(path));
user32.GetWindowText(hWnd, path, 512);
System.out.println("Window text is: " + Native.toString(path));