Link to home
Start Free TrialLog in
Avatar of Slask
Slask

asked on

Override the MRU open command

I have customized my OnFileOpen and when I open the database, in this case, I add the file to the MRU list using AfxGetApp()->AddToRecentFileList(lpszPath);

How can I override the MRU open command? I have tried to add a handler for ID_FILE_MRU_FILE1 but that only works on the first MRU file. I must override the MRU open command because I can't use the supplied function, my app crashes.

Any ideas?
Avatar of Zoppo
Zoppo
Flag of Germany image

Hi Slask,

There are predefined id's ID_FILE_MRU_FIRST to ID_FILE_MRU_LAST.

You could create one single message handler for them using ON_COMMAND_RANGE (unfortunately cannot be created via ClassWizard, see help).

hope that helps,

ZOPPO
Avatar of Slask
Slask

ASKER

Hi Zoppo!

Got it to work thank you. Perhaps you can help me out, how can I get the filename selected in the MRU list now that I catch the message. What's the easiest way? Do you know?
Hi,

I think U can copy the same code for other files also. Let us say 4 MRU files are allowed. Then add command handler for
ID_FILE_MRU_FILE1

Then copy the same code Now in *.h file declaration
      afx_msg void OnFileMruFile1();
      afx_msg void OnFileMruFile2();
      afx_msg void OnFileMruFile3();
      afx_msg void OnFileMruFile4();

and in *.cpp message map
      ON_COMMAND(ID_FILE_MRU_FILE1, OnFileMruFile1)
      ON_COMMAND(ID_FILE_MRU_FILE2, OnFileMruFile2)
      ON_COMMAND(ID_FILE_MRU_FILE3, OnFileMruFile3)
      ON_COMMAND(ID_FILE_MRU_FILE3, OnFileMruFile4)

Then add other three functions as(including for first)
void CSDIWithProgressView::OnFileMruFile1()
{
      AfxMessageBox("file1");
      
}

void CSDIWithProgressView::OnFileMruFile2()
{
      AfxMessageBox("file2");
      
}

void CSDIWithProgressView::OnFileMruFile3()
{
      AfxMessageBox("file3");
      
}

void CSDIWithProgressView::OnFileMruFile4()
{
      AfxMessageBox("file4");
      
}

Something like that u have to do.

try it out.

VinExpert
Hi slask,

seems that CWinApp has an (undocumented) member CRecentFileList* m_pRecentFileList. Just use it's operatot[] to get an indexed string from it.

ZOPPO
Avatar of Slask

ASKER

I got that working using Zoppos comment, all I need to know now is how to get the file selected in the MRU so that I can open it....
Avatar of Slask

ASKER

Hi Zoppo!

I get the names in the CRecentFileList, but how can I tell wfich string have been selected in the MRU List?
ASKER CERTIFIED SOLUTION
Avatar of Zoppo
Zoppo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Slask

ASKER

Thank you very much Zoppo. Made it work using the following:

void CMainFrame::OnFileMru (UINT nID)
{
CString      strFile;
CRecentFileList* pList = ((CMediaApp*)

AfxGetApp ())->GetRecentFileList ();
VERIFY (pList);

UINT nStringId = nID - ID_FILE_MRU_FIRST;
strFile = pList->m_arrNames[nStringId];
}
seems ok, but BTW you do not need to cast the return from AfxGetApp() to CMediaApp...

have a nice day ...

ZOPPO
Avatar of Slask

ASKER

I must cast the AfxGetApp, since the function GetRecentFileList is a function that I wrote. I couldn't get a pointer to m_pRecentFileList any other way since it is protected. If I don't cast I get an error saying that GetRecentFileList() is not a member of CWinApp.....
oh, uuups, sorry, just did not read the whole line, excuse my thoughtless comment...
Avatar of Slask

ASKER

No prob...