MRU Dialog

When you start an AppWizard generated MFC application without any command line arguments a new document is created. If the user doesnt want a new document but wants to edit an existing one, the new document created every time the application starts has no purpose at all. The code presented in this article shows a dialog which, when there are no command line arguments, gives the user the opportunity to either start with a new document, open a document from the MRU list or open another existing document. If the user cancels this dialog an empty workspace is shown. The double click event is also handled so editing a file from the MRU list can be started quickly.

The demo code provided with this article adds this functionality to the famous Scribble Application with these steps:

  1. Add the files FileOpen.cpp and FileOpen.h to your project and paste the IDD_FILEOPEN dialog into your application (you can do this easily by temporary including the demo project in your workspace.) Also create a new icon depicting a new document. This icon will be placed next to the "Create a new ... " text. The rest of the dialog will be filled with the document type information.

  2. Include the header file in your application and derive your application from CMRUWinApp instead of CWinApp:
    #include "FileOpen.h"
    
    class CScribbleApp : public CMRUWinApp
    {
    public:
     CScribbleApp();
    
     //..rest of class
    }
    
  3. In your InitInstance() function swap the processing of the command line info and the creation of the main window and call the new function ParseCommandLineEx instead. This function has the ID of the resources used with the document type and the ID of the icon for new documents as extra arguments.
    // First show the main window
    pMainFrame->ShowWindow(m_nCmdShow);
    pMainFrame->UpdateWindow();
    
    // Parse command line for standard shell commands, DDE, file open
    CCommandLineInfo cmdInfo;
    ParseCommandLineEx(cmdInfo, IDR_SCRIBBTYPE, IDR_SCRIBBNEW );
    
    // Dispatch commands specified on the command line
    if (!ProcessShellCommand(cmdInfo))
       return FALSE;
    

Downloads

Download demo project - 34Kb


Comments

  • Little adjustment

    Posted by Legacy on 11/16/2001 12:00am

    Originally posted by: Gijs Franken

    Very nice indeed. Just a little adjustment.

    Try the followinging sequence of actions:
    1) Select a recent file
    2) Select the "new document" radio option
    3) Select the previous select recent file again (directly, without selecting the "open recent.." radio button first).

    A new document is then created while the App is not supposted to do this. Add a NM_CLICK message to the CListCtrl derived list. Implementation goes like this...

    void CRecentFileDlg::OnClickRecentFileList(NMHDR* pNMHDR, LRESULT* pResult)
    {
    m_nAction = 1;
    m_btnOK.EnableWindow(m_RecentFileList.GetSelectedCount() > 0);
    UpdateData(FALSE);

    *pResult = 0;
    }

    The dialog will now selects the "open recent..." radio and all will workout great.

    First contribution/comment so don't take my english and comments not to seriously...

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Hybrid cloud platforms need to think in terms of sweet spots when it comes to application platform interface (API) integration. Cloud Velocity has taken a unique approach to tight integration with the API sweet spot; enough to support the agility of physical and virtual apps, including multi-tier environments and databases, while reducing capital and operating costs. Read this case study to learn how a global-level Fortune 1000 company was able to deploy an entire 6+ TB Oracle eCommerce stack in Amazon Web …

  • Live Event Date: August 20, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT When you look at natural user interfaces as a developer, it isn't just fun and games. There are some very serious, real-world usage models of how things can help make the world a better place – things like Intel® RealSense™ technology. Check out this upcoming eSeminar and join the panel of experts, both from inside and outside of Intel, as they discuss how natural user interfaces will likely be getting adopted in a wide variety …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds