扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:宋宝华 来源:天极开发 2007年10月16日
关键字:
![]() 图6.4 含"自定义"菜单的单文档/视图架构MFC程序 |
//视图中的消息映射和处理函数 BEGIN_MESSAGE_MAP(CExampleView, CView) //{{AFX_MSG_MAP(CExampleView) ON_COMMAND(IDM_SELF, OnSelf) //}}AFX_MSG_MAP END_MESSAGE_MAP() void CExampleView::OnSelf() { // TODO: Add your command handler code here AfxMessageBox("消息在视图中处理"); } //框架窗口中的消息映射和处理函数 BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ON_COMMAND(IDM_SELF, OnSelf) //}}AFX_MSG_MAP END_MESSAGE_MAP() void CMainFrame::OnSelf() { // TODO: Add your command handler code here AfxMessageBox("消息在框架窗口中处理"); } |
BOOL CFrameWnd::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) { // pump through current view FIRST CView* pView = GetActiveView(); if (pView != NULL && pView->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) return TRUE; // then pump through frame if (CWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) return TRUE; // last but not least, pump through app CWinApp* pApp = AfxGetApp(); if (pApp != NULL && pApp->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) return TRUE; return FALSE; } BOOL CView::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) { // first pump through pane if (CWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) return TRUE; // then pump through document BOOL bHandled = FALSE; if (m_pDocument != NULL) { // special state for saving view before routing to document _AFX_THREAD_STATE* pThreadState = AfxGetThreadState(); CView* pOldRoutingView = pThreadState->m_pRoutingView; pThreadState->m_pRoutingView = this; bHandled = m_pDocument->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo); pThreadState->m_pRoutingView = pOldRoutingView; } return bHandled; } |
//文档的消息映射和处理函数 BEGIN_MESSAGE_MAP(CExampleDoc, CDocument) //{{AFX_MSG_MAP(CExampleDoc) ON_COMMAND(IDM_SELF, OnSelf) //}}AFX_MSG_MAP END_MESSAGE_MAP() void CExampleDoc::OnSelf() { // TODO: Add your command handler code here AfxMessageBox("消息在文档中处理"); } //应用的消息映射和处理函数 BEGIN_MESSAGE_MAP(CExampleApp, CWinApp) //{{AFX_MSG_MAP(CExampleApp) ON_COMMAND(IDM_SELF, OnSelf) //}}AFX_MSG_MAP END_MESSAGE_MAP() void CExampleApp::OnSelf() { // TODO: Add your command handler code here AfxMessageBox("消息在应用中处理"); } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。