我想在一个长时间的循环中让程序能响应消息,又不想用多线程。
CB和VB中都有强迫消息处理的方法,不知VC中如何实现?

解决方案 »

  1.   

    MsgWaitForMultipleObjects
    The MsgWaitForMultipleObjects function returns when one of the following occurs: 
    Either any one or all of the specified objects are in the signaled state. The objects can include input event objects, which you specify using the dwWakeMask parameter. 
    The time-out interval elapses. DWORD MsgWaitForMultipleObjects(
      DWORD nCount,          // number of handles in array
      CONST HANDLE pHandles, // object-handle array
      BOOL fWaitAll,         // wait option
      DWORD dwMilliseconds,  // time-out interval
      DWORD dwWakeMask       // input-event type
    );
    dwWakeMask choose QS_ALLINPUT
      

  2.   

    不太明白.我的意思是,我要执行一段计算量比较大的循环操作,可能要几十秒或几分种才能完成,此时希望程序不要象死机一样,还能响应基本的窗口拖动等消息,还可以让用户取消操作.
    在CB中,只要在循环中加上一句:
    Application->ProcessMessages();
    即可,不知道VC中是否可以同样实现,(这么简单的功能我不想用多线程)
      

  3.   

    MSG message;
    While(::GetMessage(&message,NULL,0,0)){
    ::TranslateMessage(&message);
    ::DispatchMessage(&message);
    }还可以用PeekMessage
      

  4.   

    那你在你的循环里加上:
    MSG msg ;
    ::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE));
    ::DispatchMessage(&msg) ;
    试试。
      

  5.   

    GETMESSAGE会阻塞, 用PEEKMESSAGE.