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?
SlaskAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZoppoCommented:
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
0
SlaskAuthor Commented:
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?
0
Vinayak KumbarSr Program ManagerCommented:
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
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

ZoppoCommented:
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
0
SlaskAuthor Commented:
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....
0
SlaskAuthor Commented:
Hi Zoppo!

I get the names in the CRecentFileList, but how can I tell wfich string have been selected in the MRU List?
0
ZoppoCommented:
Hi Slask,

With the ON_COMMAND_RANGE the given handler function gets an id passed, so you should be able to just calculate the id of selected filename, i.e.:

....
ON_COMMAND_RANGE( ID_FILE_MRU_FIRST, ID_FILE_MRU_LAST,  OnFileMRU )
....

void OnFileMRU(UINT id)
{
 UINT stringId = id-ID_FILE_MRU_FIRST;
 ...
}

ZOPPO
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SlaskAuthor Commented:
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];
}
0
ZoppoCommented:
seems ok, but BTW you do not need to cast the return from AfxGetApp() to CMediaApp...

have a nice day ...

ZOPPO
0
SlaskAuthor Commented:
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.....
0
ZoppoCommented:
oh, uuups, sorry, just did not read the whole line, excuse my thoughtless comment...
0
SlaskAuthor Commented:
No prob...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.