15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


MRU list in MFC

Lynn Herrera -- lherrera@kofax.com
Tuesday, May 28, 1996

     
        Environment: VC++ 4.0 / Win 95 and NT
     
       
        I am using the MRU list in an SDI sample application.  The application 
        reads images and during the display applies image cleanup algorithms to 
        it.
     
        After picking the 1st item from the MRU list, I want to be able 
        to pick it again and  have it read the same image file again.
     
        Unfortunately, the first item is not reread.  I'm not sure how to 
        use CRecentFileList to make this happen.  (MFC traps the name and 
        knows it has already been read.
     
        Any ideas or examples?  I'm using MSDEV C++ 4.0  
    
        Thanks,
     
        Lynn
        lherrera@kofax.com
     



Greg D. Tighe -- gdt@eng.aisinc.com
Friday, May 31, 1996

[Mini-digest: 2 responses]

>         After picking the 1st item from the MRU list, I want to be able 
>         to pick it again and  have it read the same image file again.
>      
>         Unfortunately, the first item is not reread.  I'm not sure how to 
>         use CRecentFileList to make this happen.  (MFC traps the name and 
>         knows it has already been read.
>      
Once you do something like this:

CMyDocument *pDoc = 
	AfxGetApp()->OpenDocumentFile(<1st MRU file name>);

You need to determine whether the document was actually read in from 
disk or was already loaded and its view simply brought to the front.

You can do this by adding a member variable to your doc class which 
only gets set when you read from disk.  If this variable is not set 
and you want to force a reread from disk you can do the following:

pDoc->OnOpenDocument (pDoc->GetPathName ());

Hope this helps.

	-Greg Tighe
	Applied Intelligent Systems, Inc.
	Ann Arbor, MI
	gdt@aisinc.com
-----From: "Peter A. Vanvliet" 

MFC's logic for reselecting an already opened document from the MRU list
(which has not been modified), is to simply set the "focus" back to the
document that is already loaded. You can prevent that by overriding the
default response functions:


    ON_COMMAND_EX(ID_FILE_MRU_FILE1, OnOpenRecentFile)


BOOL CMyApp::OnOpenRecentFile(UINT nID)
{
    // If there is a document open, close it.
    if (m_pTheDoc != NULL)
         if (!m_pTheDoc->CloseThisDocument())
            return FALSE;    
    
    return CWinApp::OnOpenRecentFile(nID)
}

In this particular application I only allowed one CDocument to be open at a
time, so I had to override the OnOpenRecentFile() function to close the
currently opened document and load the new one the user selected. This has
the side effect of reloading the same document if the user reselected the
currently open document.

Peter,




| Вернуться в корень Архива |