Understanding MsgWaitForMultipleObjects

后端 未结 1 1573
情歌与酒
情歌与酒 2020-12-30 11:03

I have a main gui thread that I want to remain responsive to the users action such as moving the dialog around, resizing, etc while I have a background thread doing some tas

相关标签:
1条回答
  • 2020-12-30 11:17

    You are not processing the incoming message of the UI thread, take a look at Raymond's blog (also see here) for a sample.

      while (true) {
        switch (MsgWaitForMultipleObjects(1, &h,
                             FALSE, INFINITE, QS_ALLINPUT)) {
        case WAIT_OBJECT_0:
          DoSomethingWith(h); // event has been signalled
          break;
        case WAIT_OBJECT_0+1:
          // we have a message - peek and dispatch it
          while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
            // TODO:  must handle WM_QUIT; see Raymond's blog for details
            TranslateMessage(&msg);
            DispatchMessage(&msg);
          }
          break;
        default:
          return FALSE; // unexpected failure
        }
      }
    
    0 讨论(0)
提交回复
热议问题