CreateWindow() [Win32 API] :仅父窗口获取
我问了一个问题,有人评论说我的问题不清楚, 所以这是一个新的。
我正在尝试使用 WIN32 API 创建一个具有多个窗口的应用程序。 我创建了两个窗口,一个是父窗口的子窗口。然后我有一个消息循环, 但不幸的是,只有父级 WndProc 收到消息,而子级则没有。 - 那 wndProc 只被调用一次而不是两次。 (这是预期的行为吗?)
我还尝试为子窗口创建另一个 WndProcChild 函数,并注册其自己的类,但仍然无济于事。
下面是代码摘录(只有子窗口的声明和消息循环)
我是 Win32 新手,所以要温柔...... 谢谢,丹
wcEdit.lpfnWndProc = WndProcChild;
wcEdit.style = CS_HREDRAW | CS_VREDRAW;
wcEdit.cbClsExtra = 0;
wcEdit.cbWndExtra = 0;
wcEdit.hInstance = hInstance;;
wcEdit.hCursor = 0;
wcEdit.lpszMenuName = 0;
wcEdit.lpszClassName = L"child";
RegisterClass(&wcEdit);
edit_hwnd = CreateWindow(L"child", L"child_title", NULL,
0, 0, 0, 0, ParentWindow,
NULL, global_instance, NULL);
UpdateWindow(edit_hwnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
只是再次解释我想要实现的目标 - 我想处理 WM_KEYDOWN 消息两次 - 一次在父窗口中,一次在子窗口中。我实际上不需要它们成为父子关系,只是认为这可以节省我创建两个不同的 wndProcs
I asked a question, and some people commented that my question wasn't clear,
So here is a new one.
I'm trying to create an application with multiple windows using the WIN32 API.
I created two windows, one is a child of the parent. Then i have a message loop,
But unfortunately only the parent WndProc gets message, while the child does not. - that
is the wndProc is being called only once instead of twice. ( is that the expected behaviour? )
I also tried creating another WndProcChild Function for the child window, and registering its own class, but still to no avail.
Below is a code extract ( only the declaration of the child window, and the message loop )
I'm a Win32 newbie, so be gentle...
Thanks, Dan
wcEdit.lpfnWndProc = WndProcChild;
wcEdit.style = CS_HREDRAW | CS_VREDRAW;
wcEdit.cbClsExtra = 0;
wcEdit.cbWndExtra = 0;
wcEdit.hInstance = hInstance;;
wcEdit.hCursor = 0;
wcEdit.lpszMenuName = 0;
wcEdit.lpszClassName = L"child";
RegisterClass(&wcEdit);
edit_hwnd = CreateWindow(L"child", L"child_title", NULL,
0, 0, 0, 0, ParentWindow,
NULL, global_instance, NULL);
UpdateWindow(edit_hwnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
Just to explain again what i want to achieve - i want to handle a WM_KEYDOWN message twice - once in the parent window and once in the child window. I actually don't need them to be parent-child, just thought that would save me creating two different wndProcs
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
听起来您似乎正在等待
WM_KEYDOWN
消息两次...但这种情况不会发生。只有具有按键焦点的窗口才会收到WM_KEYDOWN
消息。It sounds like you're expecting the
WM_KEYDOWN
message twice... That won't happen. Only the window with key focus will get theWM_KEYDOWN
message.继承窗口有两个属性:父窗口和所有者。在 OS/2 中,这些是单独的属性,但在 Win32 中,它们合并为一个。查看此线程:
Inheriting windows have two attributes, the parent and the owner. In OS/2 these were seperate properties but in Win32 they got combined into one. Check out this SO thread:
您可以尝试挂钩或一些类似的方法来解决此问题,因为在 Windows 上没有直接的方法可以实现此目的。基本上,您需要监视拥有另一个窗口的线程上的按键事件并拦截它们。我将从 SetWinEventHook< 开始/a> 函数。
You can try hooks or some similar approach to work around this problem because there is no direct way you can achieve this on Windows. Basically, you need to monitor key down events on the thread owning the other window and intercept them. I'd start with SetWinEventHook function.