CListCtrl中选择多项进行下载时的步骤:
void CMainFrame::OnFileDownload() 
{   
POSITION pos = rInfo->m_List_Gps.GetFirstSelectedItemPositionwhile (pos)
{
                ++i;//全局变量,初始化为0   
               if(i!=1)
      {
         hEvent = CreateEvent (NULL, TRUE, FALSE,NULL);//hEvent定义为全局的     WaitForSingleObject(hEvent,INFINITE); 
ResetEvent(hEvent);           
               }
             iIndex = rInfo->m_List_Gps.GetNextSelectedItem(pos);
               FileDown.OnFileDownload(iIndex);//调用另个类的OnFileDownload() }
}LONG CMainFrame::OnCommunication(WPARAM ch, LPARAM port)
{
结束时:
SetEvent(hEvent);
}
OnFileDownload()最后是响应OnCommunication函数进行下载的,但他响应速度不怎么快,我要的就是判断每进行一次OnFileDownload()后,要等这次的OnCommunication响应完后才进行下一次的OnFileDownload(),但我按上面这样做不行啊,比如说两次时,在两次OnFileDownload()之间不会响应OnCommunication(),而是等两次OnFileDownload()响应完后才响应OnCommunication(),请问这是为什么??我用的不对吗???如果用Mutex的话也不行,不知为什么,大哥们帮我分析一下,谢谢!!!

解决方案 »

  1.   

    你在主线程中使用WaitForSingleObject(),消息循环也会被阻塞。
      

  2.   

    还要补充一点,没一次发生OnFileDownload(),OnCommunication是响应n(n>=1000)次的,我只是在其中判断响应的第n次(可能是999次)(结束了传输)时才SetEvent(hEvent);当然了,SetEvent(hEvent)还是响应一次的,是不是因为是这个原因啊??
      

  3.   

    你把这句放在外面
    hEvent = CreateEvent (NULL, TRUE, FALSE,NULL);//hEvent定义为全局的