MRU Dialog | CodeGuru

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 […]

Written By
CodeGuru Staff
CodeGuru Staff
Sep 27, 2000
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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:
  3. #include “FileOpen.h”
    class CScribbleApp : public CMRUWinApp
    {
    public:
     CScribbleApp();
     //..rest of class
    }
    
  4. 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

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.