我有以下界面:
public interface User32 extends W32APIOptions {
User32 instance = (User32) Native.loadLibrary("user32", User32.class,
DEFAULT_OPTIONS);
boolean EnumWindows(WNDENUMPROC lpEnumFunc, Pointer arg);
void GetWindowText(int h, StringBuilder s, int nMaxCount);
}
我正在尝试列出当前可见的所有窗口标题:
final User32 user32 = User32.instance;
user32.EnumWindows(new WNDENUMPROC() {
@Override
public boolean callback(HWND hWnd, Pointer data) {
LOG.debug("callback {}", hWnd);
byte[] windowText = new byte[512];
user32.GetWindowTextA(hWnd, windowText, 512);
String wText = Native.toString(windowText);
LOG.debug("FOUND! {} {}", hWnd, wText);
return true;
}
}, null);
此代码在Windows 7(Apache v6.0,jre6)上运行良好,我列出了所有窗口。
但同样的战争在Windows 8(Apache v6.0,jre6)上不起作用。我得到了一些令人厌倦的标题(“theAwtToolkitWindow”,“internel window”,“Wmi提供者主机”,......)但从来没有我正在寻找的窗口。
知道为什么,以及如何解决它?
- ==编辑== -
在此处找到:http://msdn.microsoft.com/en-us/library/windows/desktop/ms633497%28v=vs.85%29.aspx
Note For Windows 8 and later,
EnumWindows enumerates only top-level windows of desktop apps.
所以我想我需要去更低级别的窗户..但是怎么样?
- ==编辑== -
我试图深入了解:
user32.EnumWindows(new MyWNDENUMPROC(0, 3), null);
public class MyWNDENUMPROC implements WNDENUMPROC {
public int level = 0;
public int maxLevel;
public MyWNDENUMPROC(int level, int maxLevel) {
this.level = level;
this.maxLevel = maxLevel;
}
@Override
public boolean callback(HWND hWnd, Pointer data) {
if (maxLevel < level) { //Max level reached..
return false;
}
// Enu les child windows:
user32.EnumChildWindows(hWnd, new MyWNDENUMPROC(level + 1, maxLevel), null);
byte[] windowText = new byte[512];
user32.GetWindowTextA(hWnd, windowText, 512);
String wText = Native.toString(windowText);
if (wText != null && wText.length() > 0) {
LOG.debug("level {} wText {}", level, wText);
}
return true;
}
}
在Windows 7中,它确实达到了更深层次,但在Windows 8中它保持在0级。