开发者

Getting child window's handle C\C++

开发者 https://www.devze.com 2023-02-19 07:30 出处:网络
I\'ve tried searching here and on google, i ended up with the \"GetDlgItem\" method, but it doesn\'t work.

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 =开发者_如何学Go 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.


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().


GetDlgItem takes the ID of a control. 0x00030756 already looks like a handle, so what exactly are you trying to obtain?

hwnd_Child = (HWND)0x00030756;

(Of course, this is just an example. It doesn't help to hard-code handle values anyway.)


Call GetDlgCtrlID first with the HWND to get the Control ID

int GetDlgCtrlID(HWND controlHandle);

then use the CWnd function GetDlgItem

CWnd* GetDlgItem(int controlID);
0

精彩评论

暂无评论...
验证码 换一张
取 消