Click here to Skip to main content
13,347,998 members (64,083 online)
Click here to Skip to main content
Add your own
alternative version


12 bookmarked
Posted 1 May 2003

Additional Combo MRU for Doc/View architecture

, 1 May 2003
Rate this:
Please Sign up or sign in to vote.
Doc/View MRU reflected in a ComboBox on the document form view


One day I had to create an SDI application that requires an MRU feature implemented in a combo box on the document form view. I'm not an advanced VC programmer so I don't pretend that this is the best solution. This article is for beginners that search for such an example.

What is to be done ?

Create an usual SDI application using VC wizard. For my project I specified an MRU size of 5.

Override the default OnCmdMsg message dispatcher of your application object (CWinApp derived) using the Class Wizard. In my example the application object is CTestFormApp.

BOOL CTestFormApp::OnCmdMsg(UINT nID, int nCode, 
    void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) 
 BOOL temp = CWinApp::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);

 if (nID >= ID_FILE_MRU_FILE1 && nID <= ID_FILE_MRU_FILE1 + 4) 
 if (nCode == CN_COMMAND) UpdateComboMRU();

 return temp;


The implementation of the UpdateComboMRU looks like this:

#include "afxpriv.h"    // needed because there is a forward class 
    //declaration of CRecentFileList

  CComboBox & combo=((CTestFormView*)(
  CString x;
  for (int i = 0; i < m_pRecentFileList->m_nSize; i++)
  { if (!m_pRecentFileList->GetDisplayName(x, i, NULL, NULL))
  combo.AddString(x); // update the combo from MRU object
  combo.SetCurSel(0);  // select first MRU file

CTestFormView is my document view class and m_ComboMRU is a CComboBox object displayed in the view.

In order to work things out the following calls are needed:



  • the form view OnInitialUpdate
  • the document OnOpenDocument
  • the document DoSave

just like this:

void CTestFormView::OnInitialUpdate()
BOOL CTestFormDoc::OnOpenDocument(LPCTSTR lpszPathName) 
 if (!CDocument::OnOpenDocument(lpszPathName))
  return FALSE;
 return TRUE;
BOOL CTestFormDoc::DoSave(LPCTSTR lpszPathName, BOOL bReplace)
 BOOL temp = CDocument::DoSave(lpszPathName, bReplace);
 return temp;

You need to override DoSave. There's an interesting article about this on this site:


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
Germany Germany

You may also be interested in...


Comments and Discussions

GeneralGood work Pin
Portatofe2-Oct-08 6:57
memberPortatofe2-Oct-08 6:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180111.1 | Last Updated 2 May 2003
Article Copyright 2003 by kla_boot
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid