[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 518
  • Last Modified:

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?
0
Slask
Asked:
Slask
  • 6
  • 5
1 Solution
 
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
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
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
 
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now