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()->AddToRecentFi leList(lps zPath);
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?
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?
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?
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_FIL E1, OnFileMruFile1)
ON_COMMAND(ID_FILE_MRU_FIL E2, OnFileMruFile2)
ON_COMMAND(ID_FILE_MRU_FIL E3, OnFileMruFile3)
ON_COMMAND(ID_FILE_MRU_FIL E3, OnFileMruFile4)
Then add other three functions as(including for first)
void CSDIWithProgressView::OnFi leMruFile1 ()
{
AfxMessageBox("file1");
}
void CSDIWithProgressView::OnFi leMruFile2 ()
{
AfxMessageBox("file2");
}
void CSDIWithProgressView::OnFi leMruFile3 ()
{
AfxMessageBox("file3");
}
void CSDIWithProgressView::OnFi leMruFile4 ()
{
AfxMessageBox("file4");
}
Something like that u have to do.
try it out.
VinExpert
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_FIL
ON_COMMAND(ID_FILE_MRU_FIL
ON_COMMAND(ID_FILE_MRU_FIL
ON_COMMAND(ID_FILE_MRU_FIL
Then add other three functions as(including for first)
void CSDIWithProgressView::OnFi
{
AfxMessageBox("file1");
}
void CSDIWithProgressView::OnFi
{
AfxMessageBox("file2");
}
void CSDIWithProgressView::OnFi
{
AfxMessageBox("file3");
}
void CSDIWithProgressView::OnFi
{
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
seems that CWinApp has an (undocumented) member CRecentFileList* m_pRecentFileList. Just use it's operatot[] to get an indexed string from it.
ZOPPO
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....
ASKER
Hi Zoppo!
I get the names in the CRecentFileList, but how can I tell wfich string have been selected in the MRU List?
I get the names in the CRecentFileList, but how can I tell wfich string have been selected in the MRU List?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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[nStringI d];
}
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[nStringI
}
seems ok, but BTW you do not need to cast the return from AfxGetApp() to CMediaApp...
have a nice day ...
ZOPPO
have a nice day ...
ZOPPO
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...
ASKER
No prob...
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