关于:
PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)
If hWnd is NULL, PeekMessage retrieves messages for any window that belongs to the current thread, and any messages on the current thread's message queue whose hwnd value is NULL (see the MSG structure). Therefore if hWnd is NULL, both window messages and thread messages are processed.
通过命名管道接收的消息是否包含在窗口消息和线程消息中?
最佳答案
绝对不是。命名管道不发送窗口消息。
此上下文中的线程消息比较特殊,与命名管道无关。
使用MsgWaitForMultipleObjects相反。
代码示例:
void MessageLoop(HANDLE hNamedPipe)
{
do {
DWORD res = MsgWaitForMultipleObjects(1, &hNamedPipe, INFINITE, QS_ALLEVENTS, MWMO_INPUTAVAILABLE);
if (res == WAIT_OBJECT_0) {
/* Handle named pipe -- at this point ReadFile will not block */
} else if (res == WAIT_OBJECT_0 + 1) {
MSG msg;
if (!GetMessage(&msg, NULL, 0, 0))
break; /* WM_QUIT */
TranslateMessage(&msg);
DispatchMessage(&msg);
}
} while (1);
}
关于c++ - C++ 中的 PeekMessage 函数和命名管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3544491/