想向对话框发送消息。可是不知道该如何操作,请指教!

解决方案 »

  1.   

    可以把对话框的m_hWnd作为全局变量,在线程中用SendMessage
      

  2.   

    也可以把他传进去
    还可以把线程作为类的成员
    定义的时候这样就行了static LRESULT __stdcall a( ... );
      

  3.   

    qunta(旺财1860) ,到底该如何操作,请详细说一下,麻烦你把代码写一下,再有如何定制消息,如何发送参数给对话框,对话框该如何做
      

  4.   

    用全局的::SendMessage并传递对话框的m_hWnd成员给它就OK了..
      

  5.   

    //自己定义的消息
    #define WM_MYMESS WM_USER + 1001
    //全局的对话框窗口句柄
    HWND g_MyhWnd;class CAboutDlg : public CDialog
    {
    public:
    CAboutDlg();
    //线程执行函数,在类里要定义成static,所以它不能访问任何动态的成员变量
    static UINT MyThreadProc( LPVOID pParam );// Dialog Data
    //{{AFX_DATA(CAboutDlg)
    enum { IDD = IDD_ABOUTBOX };
    //}}AFX_DATA // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CAboutDlg)
    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    //}}AFX_VIRTUAL// Implementation
    protected:
    //{{AFX_MSG(CAboutDlg)
    virtual void OnOK();
    //}}AFX_MSG
    //定义消息处理函数
    afx_msg LRESULT OnMyMess(WPARAM wParam, LPARAM lParam);
    DECLARE_MESSAGE_MAP()
    };BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
    //{{AFX_MSG_MAP(CAboutDlg)
    //}}AFX_MSG_MAP
    //消息处理过程手动加入消息映射表
    ON_MESSAGE(WM_MYMESS, OnMyMess)
    END_MESSAGE_MAP()//线程执行函数
    UINT CAboutDlg::MyThreadProc( LPVOID pParam )
    {
    Sleep(2000);
    ::SendMessage(g_MyhWnd, WM_MYMESS, 0, 0);//发自己的消息,有什么参数可以自己加
    return 1;//线程退出
    }void CAboutDlg::OnOK() 
    {
    // 启动线程
    g_MyhWnd = this->GetSafeHwnd();
    AfxBeginThread(CAboutDlg::MyThreadProc, NULL);
    }//对话框处理消息
    LRESULT CAboutDlg::OnMyMess(WPARAM wParam, LPARAM lParam)
    {
    AfxMessageBox("I Get this Message.");
    return 0;
    }