我想获取父窗口的所有子句柄。这可以在AutoIt脚本中完成,但是,我们希望在java中使用此命令,并且此命令在AutoItX4Java.jar中不可用。我开始创建它,并以计算器为例:
public static HWND GetWindow( WinDef.HWND hWnd, WinDef.DWORD uCmd) {
User32 user32 = (User32) Native.loadLibrary("user32", User32.class);
return user32.GetWindow(hWnd, uCmd);
}
public static void main(String[] args) {
WinDef.HWND hWnd = User32.INSTANCE.FindWindow("CalcFrame", "Calculator");
WinDef.DWORD a = new WinDef.DWORD(5); // child 5
System.out.println("parent : " + hWnd);
WinDef.HWND hWnd3 = GetWindow ( hWnd , a );
System.out.println("child " + hWnd3);
WinDef.DWORD b = new WinDef.DWORD(2); // next 2
WinDef.HWND hWnd2= GetWindow ( hWnd3 , b );
System.out.println(hWnd2);
int x = 0;
while (hWnd2 != null ) {
x++;
System.out.println(hWnd2);
hWnd2= GetWindow ( hWnd , b );
if (x>30)
break;
}
}
此代码无效并引发一些错误。
输出:
parent:native @ 0x180d78
child native @ 0x4400f8
空
找不到兄弟控件。