请问在线程中如何使用MFC类创建对话框?
我的做法如下:
1.CreateThread(NULL,0,monitor_get_event_control,&m_hWnd,NULL,&ThreadId);
2.DWORD WINAPI  monitor_get_event_control(void* param)
{
CTestMsgDlgDlg *Dlg = (CTestMsgDlgDlg*)param;
Dlg->DisplayIncomingMsgDlg();
return 0;
}
3.void CTestMsgDlgDlg::DisplayIncomingMsgDlg()
{
        pMsgDlg=new CIncomingMsgDlg(this); CIncomingMsgDlg& MsgDlg=*pMsgDlg;
FromName = strdup("From:lgg");
MsgDlg.Create(IDD_INCOMINGMSG_DIALOG);
MsgDlg.ShowWindow(SW_SHOW);
MsgDlg.UpdateWindow();
}但是这样做,不能创建对话框,请问如何修改呢?

解决方案 »

  1.   

    &m_hWnd,CTestMsgDlgDlg *Dlg?这两者能转换?还有,你的线程并不是UI线程(你需要有线程中处理消息队列)
      

  2.   

    如果是测试,写着玩那也就算了估计你也是写着玩的MFC本身就不是线程安全的在work thread里创建对话框,在传来传去,等工程大了。你就等着哭吧
      

  3.   

    UINT threadFunc( LPVOID p)
    {
      CAboutDlg Dlg;
    Dlg.DoModal();
    return 1;
    }
    void CMyDlg::OnButton2() 
    {
    // TODO: Add your control notification handler code here
    AfxBeginThread(threadFunc,NULL); //创建线程
    }