开发者

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

开发者 https://www.devze.com 2022-12-10 20:39 出处:网络
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 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";  
Register开发者_JAVA技巧Class(&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


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.


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:


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.

0

精彩评论

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