获取子窗口的句柄 C\C++
我尝试在这里和谷歌上搜索,我最终得到了“GetDlgItem”方法,但它不起作用。
这是我的代码:
HWND hwnd_Parent;
HWND hwnd_Child;
hwnd_Parent = FindWindow(NULL,"MyTitle");
hwnd_Child = GetDlgItem(hwnd, 0x00030756);
hwnd_Parent 没问题(我什至做了一些帖子消息测试),但 hwnd_Child 为空。 所以,你看到的十六进制数字是通过WinSpy++找到的。
我的系统是Windows 7 64位,我的IDE是Code Blocks。
提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要知道窗口的 ID 才能使用
GetDlgItem()
。我怀疑您正在传递从 Spy++ 获得的 HWND。看起来您正在另一个应用程序中闲逛,因为如果它是您自己的应用程序,那么您就不需要调用 FindWindow,并且您会知道控件 ID。
从 FindWindow 获得顶级窗口后,找到此窗口的最简单方法可能是调用
EnumChildWindows()
。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
获取控件的 ID。0x00030756
看起来已经像一个句柄了,那么您到底想获取什么?(当然,这只是一个示例。无论如何,对句柄值进行硬编码没有任何帮助。)
GetDlgItem
takes the ID of a control.0x00030756
already looks like a handle, so what exactly are you trying to obtain?(Of course, this is just an example. It doesn't help to hard-code handle values anyway.)
首先使用 HWND 调用 GetDlgCtrlID 来获取控件 ID
,然后使用 CWnd 函数 GetDlgItem
Call GetDlgCtrlID first with the HWND to get the Control ID
then use the CWnd function GetDlgItem