我在回调函数中AfxGetMainWnd()->PostMessage(WM_CUSTOM1),在我的CView却拦截不到(我用Spy++可以看到post的WM_CUSTOM1),相应的消息映射我已添加(在CView.h ,CView.cpp中):
1)afx_msg Long OnCustm1(UINT,LONG);
2)ON_MESSAGE(WM_CUSTOM1,OnCustm1)
3)LONG OnCustm1(UINT,LONG) {;}
但我写在CMainFrame里,就可以拦截到。不知为何?请赐教

解决方案 »

  1.   

    AfxGetMainWnd()->PostMessage(WM_CUSTOM1)是给主框架发送消息,在你的cview中当然收不到了
      

  2.   

    消息的传递过程:其实是CFrameWnd得到消息,先不处理,送给viewBOOL CFrameWnd::OnCmdMsg(...)
    {
        // Pump through current view FIRST.
        CView* pView = GetActiveView();
        if (pView != NULL && pView->OnCmdMsg(...))
            return TRUE;    // Then pump through frame.
        if (CWnd::OnCmdMsg(...))
            return TRUE;    // Last but not least, pump through application.
        CWinApp* pApp = AfxGetApp();
        if (pApp != NULL && pApp->OnCmdMsg(...))
            return TRUE;    return FALSE;
    }
      

  3.   

    AfxGetMainWnd()->)是给主框架发送消息
    可以
    ::PostMessage(视图句柄,WM_CUSTOM1)
      

  4.   

    你这个(AfxGetMainWnd()->)是给主框架发送消息
    并不是你想要发给CView的
    所以你收不到
    你可以按crybird(寒号鸟)那样说得做做看