Search code examples
c++cwinapiparent-childhandle

Getting child window's handle C\C++


I've tried searching here and on google, i ended up with the "GetDlgItem" method, but it doesn't work.

Here is my code:

HWND hwnd_Parent;
HWND hwnd_Child;

hwnd_Parent = FindWindow(NULL,"MyTitle");
hwnd_Child = GetDlgItem(hwnd, 0x00030756);

hwnd_Parent is ok (i even did some post message tests), but hwnd_Child is null. So, the hex number you see was found through WinSpy++.

My system is Windows 7 64 bits, my IDE is Code Blocks.

Thanks in advance.


Solution

  • You need to know the ID of the window to use GetDlgItem(). I suspect you are passing in an HWND that you got from Spy++.

    It looks like you are poking around in another app because if it was your own app then you wouldn't need to call FindWindow, and you'd know the control ID.

    Probably the easiest way to find this window, once you have got the top-level window from FindWindow, is to call EnumChildWindows().