|
|
|
|
Forum
Please
Log In
to post a new message or reply to an existing one. If you are not registered, please
register.
NOTE: Some forums may be read-only if you are not currently subscribed to
our technical support services.
Subject |
Author |
Date |
|
Olaf Baeyens
|
Jan 22, 2003 - 6:50 AM
|
I am using the CExtMenuControlBar m_wndMenuBar; And I have defined these functions to react on the commands.
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_FILE4, OnFileMruFile4) ON_COMMAND(ID_FILE_MRU_FILE5, OnFileMruFile5)
The problems is that always OnFileMruFile1() is called, even if I press the other commands.
Any idea’s?
Ik have the commersial version of Prof-UIS v2.20
|
|
Sergiy Lavrynenko
|
Jan 23, 2003 - 2:43 AM
|
Dear Olaf,
I can not confirm this bug. I have sent you a letter with two demo projects demonstrating how to handle MRU file commands.
Best regards, Sergiy Lavrynenko.
|
|
Olaf Baeyens
|
Jan 24, 2003 - 7:18 AM
|
The example works, just the big question now is how to extract the filename???
We have sometimes big filenames and file paths, but when I use this command:
CExtCmdManager::cmd_t * p_cmd = g_CmdManager->CmdGetPtr(g_CmdManager->ProfileNameFromWnd(this->m_hWnd),nID); if( p_cmd == NULL ) { p_cmd->m_sMenuText }
Then I only get something that has ’...’ in it like this: "d:\Source\...\scenes\Scene.ctv"
I need the complete filename in order to open it. I do love the GUI! :-)
Olaf
|
|
Sergiy Lavrynenko
|
Jan 24, 2003 - 8:49 AM
|
Dear Olaf,
To get full file path you can use:
1) GetFullPathName() function from the Win32 API (see information in MSDN help for details);
2) AfxFullPath() function - this is an MFC internal function, to use it you should include:
#if _MFC_VER < 0x700 #include <../src/AfxImpl.h> #else #ifndef __AFXSTATE_H__ #include <../src/mfc/afxstat_.h> #endif #include <../src/mfc/AfxImpl.h> #endif
That’s all about fullpath extraction.
Best regards, Sergiy Lavrynenko.
|
|
Olaf Baeyens
|
Jan 27, 2003 - 1:50 AM
|
Thank you for your response but I think we have a small misunderstanding. What I try to do is in this function below. When I click on the recent used file list menu.
I still get the "\...\" in my path and I believe that the only way to solve this is to add an additional attribute to your CExtCmdManager like p_cmd->m_sFullRecentFileName that keeps the complete filename and path ready to be used for file managment.
Or exists there another possibility?
//--------------------------------------------------------------------------- void CMainFrame::OnFileMruFile1(UINT nID) { ASSERT(ID_FILE_MRU_FILE1 <= nID && nID <= ID_FILE_MRU_FILE5); int num = nID - ID_FILE_MRU_FILE1; ASSERT( 0 <= num && num <= 5 );
string sFileName="";
CExtCmdManager::cmd_t * p_cmd = g_CmdManager->CmdGetPtr(g_CmdManager->ProfileNameFromWnd(this->m_hWnd),nID); if( p_cmd != NULL ) { sFileName=p_cmd->m_sMenuText; // Get menu text : "&4 D:\Source\...\Debug\start.stl" sFileName=ExtractString(sFileName,’ ’,1); // Extract file name : "D:\Source\...\Debug\start.stl" TCHAR szTemp[_MAX_PATH]; AfxFullPath(szTemp, sFileName.c_str()); // "D:\Source\...\Debug\start.stl" Make full path??? "D:\Source\test\ctVol\Debug\start.stl" sFileName=szTemp; } CString sMsg; sMsg.Format(_T("CMainFrame::OnFileMRU(ID_FILE_MRU_FILE%d) = %s"),num + 1,sFileName.c_str()); ::AfxMessageBox( sMsg ); }
//---------------------------------------------------------------------------
|
|
Sergiy Lavrynenko
|
Jan 30, 2003 - 6:06 AM
|
Dear Olaf,
Sorry for my misunderstanding, I thought about relative paths when you told me about short names in menu with dots in the middle. Of course this is not the same. I am really sorry. The information about recently opened documents is storted in the CWinApp::m_pRecentFileList property. Here is described a simple way for accessing this data. Please define this class somewhere in your code:
class InternalFriendlyWinApp : CWinApp { public: inline static InternalFriendlyWinApp * _GetFriendlyApp() { CWinApp * pApp = ::AfxGetApp(); ASSERT( pApp != NULL ); return (InternalFriendlyWinApp *)pApp; } CRecentFileList * _GetRecentFileList() { //ASSERT( m_pRecentFileList != NULL ); return m_pRecentFileList; } }; // class InternalFriendlyWinApp
InternalFriendlyWinApp is required to access CWinApp::m_pRecentFileList property. This is a common trick for accessing protected members of base classes. Now you can use this trick to enumerate recently opened files.
CRecentFileList * pRecentFileList = InternalFriendlyWinApp::_GetFriendlyApp()-> _GetRecentFileList(); if( pRecentFileList != NULL ) { int nRecentCount = pRecentFileList->GetSize(); for( int nItemIndex = 0; nItemIndex < nRecentCount; nItemIndex++ ) { // now you can use pRecentFileList->GetDisplayName(...) // see MSDN on CRecentFileList::GetDisplayName for details
} // for( int nItemIndex = 0; nItemIndex < nRecentCount; nItemIndex++ ) } // if( pRecentFileList != NULL )
I dont see any reason to duplicate the CRecentFileList data inside the Prof-UIS CExtCmdManager. Please note: recent-list-item with index 0 is used for handling command with id=ID_FILE_MRU_FILE1, recent-list-item with index 1 is used for handling command with id=ID_FILE_MRU_FILE2, and so on...
Best regards, Sergiy Lavrynenko.
|
|
Olaf Baeyens
|
Jan 30, 2003 - 7:51 AM
|
This is exactly what I was searching for. :-) Something for the FAQ.
|
|