在单文档中,我想在CMainFrame中调用CMyView中的函数(消息处理函数),我不知怎么解决,哪位大哥能给我指点。class CMyView : public CListView
{
    ....
    afx_msg void OnDepartReg();
    ...
};CMainFrame::MyFun()
{
   ....
   //我想在这调用OnDepartReg(),怎么解决。用SendMessage()可以吗?
   ....
}

解决方案 »

  1.   

    GetActiveView
    msdn中的例子
    CMDIFrameWnd *pFrame = 
                 (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;// Get the active MDI child window.
    CMDIChildWnd *pChild = 
                 (CMDIChildWnd *) pFrame->GetActiveFrame();// or CMDIChildWnd *pChild = pFrame->MDIGetActive();// Get the active view attached to the active MDI child
    // window.
    CMyView *pView = (CMyView *) pChild->GetActiveView();
    pView->YouFunc();
      

  2.   

    同意楼上:补充一点:
        CDocument* pDoc = ((CFrameWnd*)pChild)->GetActiveDocument();
        CMyDoc = ((CMyDoc *)pDoc);
      

  3.   

    To 楼上 楼主说的是单文档,比较难办,还是SendMessage() 把#define IDM_MSG  WM_USER+1
    afx_msg void OnDepartReg(WPARAM wParam, LPARAM lParam));
    // View.hON_MESSAGE(IDM_MSG, DepartReg) //view.cppCMyView::DepartReg(WPARAM wParam, LPARAM lParam)
    {
    }//view.cppSendMessage(IDM_MSG ..)//frame.cpp
      

  4.   

    应该不行把,你怎么样在frame 类里面定义CMyView * ?你只能定义CView * ,因此你只能用CMyView 里的虚函数.而楼主要用的是一般的成员函数.
      

  5.   

    //stdafx.h
    #define IDM_MSG  WM_USER+1//TestView.h
    class CTestView : public CView
    {
      ...
      protected:
    afx_msg void OnDepartReg(WPARAM wParam, LPARAM lParam);
    DECLARE_MESSAGE_MAP()
      ...
    };//TestView.cpp
    BEGIN_MESSAGE_MAP(CTestView, CView)
      ...
      ON_MESSAGE(IDM_MSG,OnDepartReg)
      ...
    END_MESSAGE_MAP()
      ...
      ...
    void CTestView::OnDepartReg(WPARAM wParam, LPARAM lParam)
    {
      MessageBox("kdsjf");
    }//MainFrame.cpp
    void CMainFrame::OnTest() 
    {
      SendMessage(IDM_MSG);//怎么不调用CTestView::OnDepartReg(),是不是SendMessage()参数不对?????????????
    }
      

  6.   

    你做实验的时候就
    void CMainFrame::OnTest() 
    {
    // TODO: Add your command handler code here
    GetActiveView()->SendMessage(IDM_MSG);//因为你这个消息是在CView 中有映射
    }