子窗口向父窗口发送消息

1.自定义对话框中,

m_pView 是父窗口的指针

void CEx07cDialog::OnBnClickedOk()
{
    if (m_pView != NULL) {
        // modeless case -- do not call base class OnOK
        UpdateData(TRUE);
         m_pView->PostMessage(WM_GOODBYE, IDOK);
    }
    else {
        CDialog::OnOK(); // modal case
    }
}

2.父窗口响应

 BEGIN_MESSAGE_MAP(CEx07cView, CView)
 ON_WM_LBUTTONDOWN()
 ON_WM_RBUTTONDOWN()
    ON_MESSAGE(WM_GOODBYE, OnGoodbye) //通过这个宏
END_MESSAGE_MAP()

LRESULT CEx07cView::OnGoodbye(WPARAM wParam, LPARAM lParam)
{
    // message received in response to modeless dialog OK
    //  and Cancel buttons
    TRACE("CEx07cView::OnGoodbye %x, %lx/n", wParam, lParam);
    TRACE("Dialog edit1 contents = %s/n",
          (const char*) m_pDlg->m_strEdit1);
    m_pDlg->DestroyWindow();
    return 0L;
}

 

你可能感兴趣的:(null,Class,dialog)