视类:CTestView  对话框(模态)CTestDlg中的按钮:button1我想在视类响应按钮的单击消息如何实现?
另外如何在视类中销毁CTestDlg呢?
我要代码,马上给分

解决方案 »

  1.   

    直接在button1  的响应函数中OnOk()结束对话框
      

  2.   

    获得对话框句柄,然后发消息ID_CANCEL啥的就行
    好比在CMainFrm里有对话框定义;
    CTestDlg m_dlg;在view里的响应函数
    AfxGetMainWnd()->m_dlg.SendMessage(WM_CANCEL, NULL, NULL);
      

  3.   

    很多方法嘛:
    1,发送消息处理
    2,对话框放一个视图指针,通过这个指针调用对话框的相应函数
    CMyDialog::CmyDialog(CView * pv){this->m_pView=pv;
    }
    CMydialog::OnButton1()
    {
    //function为视图类的响应函数
    this->m_pView->Function();
    }
      

  4.   


    你可以在CTestDlg对象创建时把视类指针传递过去。
    互相包含头文件(注意在包含VIEW.H前要先包含DOC.H),在CTestDlg头文件里添加视类指针,CTestView *pView;
    在CTestView里添加个BOOL变量btnclick,初始化为false。
    例如:在视类单击鼠标左键时产生CTestDlg对象。
    void CTestView::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    CTestDlg dlg;
    dlg.pView = this;//传递视类指针
    dlg.DoModal();
    }button1单击时在View里输出文本
    void CTestView::OnDraw(CDC* pDC)
    {
    if (btnclick)
    {
    pDC->TextOut(0,0,"btn clicked");
    }
    }模态对话框的button1单击时
    void CTestDlg::OnButton1() 
    {
    pView->btnclick = true;
    CRect rect;
    pView->GetClientRect(&rect);
    ::InvalidateRect(pView->m_hWnd,&rect,true);
    OnCancel();//销毁对话框
    }
    不知道是不是你想要的效果。