自己创建的一个线程发出消息到主执行线程,主执行线程中收不到消息,而在主执行线程中发出的消息却能够收到,真是搞不懂,我用了PostMessage,SendMessage, PostThreadMesage都不行。不好意思分数不多

解决方案 »

  1.   

    1.给线程发消息用PostThreadMessage
    2.主线程是否有消息循环?
      

  2.   

    消息循环肯定有的,偶尔也能收到消息,但能收到的时候很少,我的软件中有两种状态,另一种状态就能够收到消息!我用几种方法:
       1、theApp.m_pMainWnd->PostMessage(ID_MESSAGE, 100, 200);
       2、::PostMessage(theApp.m_pMainWnd->m_hWnd, ID_MESSAGE, 100, 200);
       3、PostThreadMessage(theApp.m_nThreadID,ID_MESSAGE, 100, 200);
       4、 LPDWORD proc = 0;
    DWORD hThread = GetWindowThreadProcessId(d,proc);
    DWORD x = (DWORD)theApp.m_hThread;
            PostThreadMessage(hThread ,ID_MESSAGE, 100, 200);
         实际上hThread与theApp.m_nThreadID是一样的
      消息的发送肯定没问题;就是为什么消息很少能收到,即使收到也只是一两次。而另一种状态下,100%能收到!
      谢谢
      

  3.   

    还有一种方式就是theApp.m_pMainWnd->SendMessage(ID_MESSAGE, 100, 200);