我一直在尝试让 wndproc 成功接收来自消息队列的消息并根据我的代码处理它们,但它没有按照我想要的方式工作,我希望它做的是确定接收到哪个窗口WM_DESTROY 或 WM_CLOSE 并调用特定于哪个窗口关闭的代码,但由于某种原因,目前它什么也没做。经过大量实验后,我已经让它以不同的方式部分发挥作用,但似乎每个实现都不能以正确的方式发挥作用。这是我最新的不成功代码:
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;
}
这是我尝试使用多个窗口过程的代码
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;
}