CreateWindow() [Win32 API] : Only parent window gets

微笑、不失礼 提交于 2019-12-25 01:31:09

问题


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


回答1:


It sounds like you're expecting the WM_KEYDOWN message twice... That won't happen. Only the window with key focus will get the WM_KEYDOWN message.




回答2:


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:




回答3:


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.



来源:https://stackoverflow.com/questions/1708499/createwindow-win32-api-only-parent-window-gets

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!