Re[2]: Опять про потоки.
От: Tarantul Украина  
Дата: 23.11.03 19:54
Оценка:
Здравствуйте, vadim77, Вы писали:

V>Try MsgWaitForMultipleObjectsEx


V>This is code snippet from the book "MS Press — Programming Applications for MS Windows 4th Edition" by Jeffry Richter


V>BOOL fQuit FALSE; //Should the loop terminate?


V>while (!fQuit)

V>{

V>//Wake when the kernel object is signaled OR

V>//if we have to process a UI message.
V> DWORD dwResult = MsgWaitForMultipleObjectsEx(1, &hYourThreadHandle,
V> INFINITE, QS_ALLEVENTS, MWMO_INPUTAVAILABLE);

V> switch(dwResult)

V> {
V> case WAIT_OBJECT_0: // The event became signaled.
V> break;

V> case WAIT_OBJECT_0 + 1: //A message is in our queue.


V> //Dispatch all of the messages.

V> MSG msg;
V> while(PeekMessage(&msg, NULL, 0, 0,PM_REMOVE))
V> {
V> if(msg.message==WM_QUIT)
V> {
V> //A WM_QUIT message, exit the loop
V> fQuit = TRUE;
V> }
V> else
V> {
V> //Translete and dispatch the message.
V> TranslateMessage(&msg);
V> DispatchMessage(&msg);
V> }
V> }// Our queue is empty.
V> break;
V> }
V>}//End of while loop

Если MsgWait... действительно пропускает виндовс-сообщения, то это как раз то, что надо.
На данный момент в главном потоке я остановился на таком _рабочем_ варианте:
void CMainFrame::OnCmdStopScan()
{
    if(pScanThread!=NULL)    
    {
        m_pReportDlg->m_pPS->m_SearchPP.m_ScanLocker.ExitFromThread();

        bool fWaiting=true;
        while(fWaiting)
        {
            if(WaitForSingleObject(pScanThread->m_hThread,0)==WAIT_TIMEOUT)
            {
                MSG msg;
                if(PeekMessage(&msg, NULL, 0, 0,PM_REMOVE))
                {
                    TranslateMessage(&msg);
                    DispatchMessage(&msg);
                }
            }
            else fWaiting=false;
        }
    }
}

Всем спасибо.
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.