关键是SendMesage()函数中的第一个参数怎么得到,着急,谢谢大家。

解决方案 »

  1.   

    首先说,应该用PostMessage,因为SendMessage可能带来死锁。第一个参数,也就是窗口句柄,可以作为参数传递给工作者线程。
      

  2.   

    以下是MSDN中关于AfxGetMainWnd的介绍:
      If AfxGetMainWnd is called from the application's primary thread, it returns the application's main window according to the above rules. If the function is called from a secondary thread in the application, the function returns the main window associated with the thread that made the call.
     也许在线程中调用该函数就行了,不过我没试过。另外建议你多研究一下MSDN文档,很多问题都能在里面找到答案。
      

  3.   

    已经得到正解,用GetSafeHwnd()就可以得到对话框窗口的句柄了。还有一个问题就是我把此句柄当作参数传递给工作线程的时候,这是函数里面的转换语句,怎么就不对了?DWORD WINAPI CDia1Dlg::add(void *thisHwnd)
    {
    int retValue = 0;
    HWND hDlg = reintepret_cast<HWND>(thisHwnd);
             SendMessage(hDlg,WM_MY,0,0);
    ...省略掉了}