How to get list of list of all child controls (grips) of a given window using java

I want to get all the child handles of the parent window. This can be done in AutoIt script, but we want it in java and this command is not available in AutoItX4Java.jar. I started creating it and took an example of a calculator:

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;
    }
}

      

This code doesn't work and throws some errors.

output:

parent: native @ 0x180d78

child root @ 0x4400f8

zero

Cannot find site controls.

+3


source to share





All Articles