MFC: Disable New File and Save File in SDI Application

What would be the easiest way to use commands in your code to programmatically disable these two features in your application? Thanks in advance.

+2
file visual-c ++ mfc


source to share


3 answers


You can handle the update message:



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 );
}

      

+4


source to share


Replace with CWinApp::OnFileNew

your own function as shown below.



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 );

    }


}

      

+1


source to share


Call CMenu::EnableMenuItem

with appropriate menu items and MF_DISABLED

as second parameter. Here's the documentation .

-1


source to share







All Articles
Loading...
X
Show
Funny
Dev
Pics