I've been trying to get a wndproc to successfully receive messages from the message queue and process them according to my code but it isn't working the way I want it to, what I'd like it to do is determine which window received WM_DESTROY or WM_CLOSE and call code specific to which window was closed, but for some reason at the moment it's doing nothing. After alot of experimentation I've gotten it to function partially in different ways but it seems like each implementation doesn't function just the right way. Here's my lastest unsuccessful code:
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK Proc2(HWND mainwin, UINT message, WPARAM wParam, LPARAM lParam )
{
switch (message) /* handle the messages */
{
case WM_DESTROY:
const HWND active_window = GetActiveWindow();
if (active_window == mainwin)
{
PostQuitMessage(0);
}
if (active_window == hwnd2)
{
PostQuitMessage(0);
EnableWindow (mainwin, true);
}
break;
}
switch (wParam) /* handle the messages */
{
case ID_2 :
PostQuitMessage(0);
break;
case ID_1 :
ShowWindow (hwnd2, SW_SHOW);
break;
default: /* for messages that we don't deal with */
return DefWindowProc (mainwin, message, wParam, lParam);
break;
}
return 0;
}
Here is the code I tried with multiple window procedures
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK Proc2(HWND mainwin, UINT message, WPARAM wParam, LPARAM lParam )
{
switch (message) /* handle the messages */
{
case WM_DESTROY:
PostQuitMessage(0);
break;
}
switch (wParam) /* handle the messages */
{
case ID_2 :
PostQuitMessage(0);
break;
case ID_1 :
ShowWindow (hwnd2, SW_SHOW);
break;
default: /* for messages that we don't deal with */
return DefWindowProc (mainwin, message, wParam, lParam);
break;
}
return 0;
}
LRESULT CALLBACK Proc3(HWND hwnd2, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_DESTROY:
EnableWindow (mainwin, false);
break;
case WM_CLOSE:
EnableWindow (mainwin, false);
break;
}
switch (wParam)
{
default:
return DefWindowProc (hwnd2, message, wParam, lParam);
break;
}
return 0;
}