2009-09-05 56 views

回答

4

你可以处理更新UI消息:

ON_UPDATE_COMMAND_UI(ID_FILE_NEW, OnUpdateFileNew) 
ON_UPDATE_COMMAND_UI(ID_FILE_SAVE, OnUpdateFileSave) 

... 

void CMainFrame::OnUpdateFileNew(CCmdUI *pCmdUI) 
{ 
    pCmdUI->Enable(FALSE); 
} 

void CMainFrame::OnUpdateFileSave(CCmdUI *pCmdUI) 
{ 
    pCmdUI->Enable(FALSE); 
} 
+0

ON_COMMAND_RANGE对我来说效果不太好。 – stanigator 2009-09-06 01:31:23

+0

好的,修复了错字(从现有项目复制完成后,应该正确阅读代码!) – Alan 2009-09-06 08:52:48

-1

请拨打CMenu::EnableMenuItem并附上相应的菜单项,MF_DISABLED作为第二个参数。这是documentation

1

覆盖CWinApp::OnFileNew用自己的功能,如下图所示。

BEGIN_MESSAGE_MAP(CMyApp, CWinApp) 
    ON_COMMAND(ID_APP_ABOUT, &CMyApp::OnAppAbout) 
    // Standard file based document commands 
    **//ON_COMMAND(ID_FILE_NEW, &CWinApp::OnFileNew)** 
    ON_COMMAND(ID_FILE_NEW, &CMyApp::OnFileNew) 
    ON_COMMAND(ID_FILE_OPEN, &CWinApp::OnFileOpen) 
    // Standard print setup command 
    ON_COMMAND(ID_FILE_PRINT_SETUP, &CWinApp::OnFilePrintSetup) 
END_MESSAGE_MAP() 


void CMyApp::OnFileNew() 
{ 
     //Create a static member variable to hold the state. For the first time create a docment. From next time avoid calling CWinApp::OnFileNew(); 
    if(m_bDocCreated == FALSE) 
    { 
     CString strMsg; 
     strMsg.Format(L"Create New DOC"); 
     AfxMessageBox(strMsg); 

     CWinApp::OnFileNew(); 
     m_bDocCreated = TRUE; 
    } 
    else 
    { 
     CFrameWnd* pFrame = (CFrameWnd*)AfxGetMainWnd(); 
     CMyDoc* pDoc = (CMyDoc*)pFrame->GetActiveDocument(); 
     CString strMsg; 
     strMsg.Format(L"Doc ID = %ld",pDoc->m_lIndex); 
     AfxMessageBox(strMsg); 

    } 


} 
相关问题