tags:

views:

396

answers:

2

Hi. 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  A: 

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.

Aaron
You can get parent/child windows to chain message handling. You have to watch out for recursive event handling though.
Kelly French
You can use SetFocus to set the window you want to get keyboard focus. Standard controls (like edit boxes) will draw a focus rect around themselves and display a caret to show that they are *the* window that will receive keyboard input.
Chris Becke
A: 

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:

Kelly French