c++ - C++ 中的 PeekMessage 函数和命名管道

标签 c++ winapi message named-pipes

关于:

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/

相关文章:

android - 在Android中使用mp.stop()时出现错误

c++ - 如何隐藏链接器警告

c++ - 如何在 C++ 中使用 UAC-shield 创建菜单项?

c++ - 从 GCC 可执行文件中剥离符号和 RTTI 文本

c++ - 如何在Windows服务中检测从 sleep 模式唤醒?

c++ - 如何使用 C++ 判断工作站当前是否连接到域 Controller

java - 为列表中的特定元素设置 ValidationError 消息

c++ - 消息传递协议(protocol)

c++ - GPP 在链接阶段失败 : "undefined reference to [function]" (no makefiles or templates)

c++ - 尝试调用将数据添加到 vector 的函数时出错