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

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


Disabling MRU Most Recently Used File List

Eric Marc Loebenberg -- loebenbe@qc.bell.ca
Friday, January 17, 1997

Environment: MSVC 4.2b Windows 95

At times, say when a flag is set, I want to disable/gray the most recently
used file list in the FILE menu.  The reason is I do not want to change
documents at this time.  I have tried playing with  overriding
CWinApp::OnUpdateRecentFileMenu(CCmdUI* pCmdUI) but have not had much
success.  I did manage to gray/disable the last file on the menu.

Does anyone have an idea or an example of how to do this.  Much
appreciated.

***************************************************************
  Eric Marc Loebenberg                  loebenbe@qc.bell.ca
  Bell Sygma Inc.                    
  700 de la Gauchetiere West       Tel: 514-870-0465
  Room 14W1                        Fax: 514-870-7583
  Montreal, Quebec, Canada
  H3B 4L1



Umesh Chandwani -- Umesh.Chandwani@eng.efi.com
Sunday, January 19, 1997

[Mini-digest: 7 responses]

Here is the code for disabling then Recent File Menu.

void CWBApp::OnUpdateRecentFileMenu(CCmdUI* pCmdUI) 
{
	ASSERT_VALID(this);
	
	if (m_pRecentFileList == NULL) // no MRU files
		pCmdUI->Enable(FALSE);
	else 
	{
		m_pRecentFileList->UpdateMenu(pCmdUI);
		if(FlagIsSet())
		{
			CMenu * pMenu = ::AfxGetMainWnd()->GetMenu();
			pMenu->EnableMenuItem(ID_FILE_MRU_FILE1, MF_BYCOMMAND | MF_GRAYED);
			pMenu->EnableMenuItem(ID_FILE_MRU_FILE2, MF_BYCOMMAND | MF_GRAYED);
			pMenu->EnableMenuItem(ID_FILE_MRU_FILE3, MF_BYCOMMAND | MF_GRAYED);
			pMenu->EnableMenuItem(ID_FILE_MRU_FILE4, MF_BYCOMMAND | MF_GRAYED);
                        
                        // My app restricts no. items in Recent File Menu to
4 so I have upto ID_FILE_MRU_FILE4
                        // U may have to add more lines of code depending on
no. items.                               
                        
		}
	}
}










At 10:00 AM 1/17/97 -0500, you wrote:
>Environment: MSVC 4.2b Windows 95
>
>At times, say when a flag is set, I want to disable/gray the most recently
>used file list in the FILE menu.  The reason is I do not want to change
>documents at this time.  I have tried playing with  overriding
>CWinApp::OnUpdateRecentFileMenu(CCmdUI* pCmdUI) but have not had much
>success.  I did manage to gray/disable the last file on the menu.
>
>Does anyone have an idea or an example of how to do this.  Much
>appreciated.
>
>***************************************************************
>  Eric Marc Loebenberg                  loebenbe@qc.bell.ca
>  Bell Sygma Inc.                    
>  700 de la Gauchetiere West       Tel: 514-870-0465
>  Room 14W1                        Fax: 514-870-7583
>  Montreal, Quebec, Canada
>  H3B 4L1
>

-----From: hou@tfn.com (Bing Hou)

     Eric,
     
     You're in the right direction. I guess in your overridden 
     OnUpdateRecentFileMenu, you did something like:
     {
        CWinApp::OnUpdateRecentFileMenu(pCmdUI);
        // Your stuff goes here
        pCmdUI->Enable(MyFlag ? TRUE : FALSE);
     }
     Looking into MFC source, you'll find that 
     CWinApp::OnUpdateRecentFileMenu steps though each recent file and adds 
     them to the file menu, and leaves the pCmdUI->m_nIndex points to the 
     last item. That's why you had successfully grayed/disabled the last 
     file on the menu.
     
     Therefore, in your overridden, you should do something like this:
     {
        CWinApp::OnUpdateRecentFileMenu(pCmdUI);
        // step back to the first item
        pCmdUI->m_nIndex -= m_pRecentFileList.GetSize()-1;
        // enable/disable each item, and moves the index back to the right  
        // position
        for(int mru = 0; mru < m_pRecentFileList.GetSize(); i++)
        {
                pCmdUI->Enable(MyFlag ? TRUE : FALSE);
                pCmdUI->m_nIndex++;
        }
     }
     
             
      
     -Bing Hou
     hou@tfn.com
     ============================================
        Jambalaya Baby!!!
     ============================================

______________________________ Reply Separator _________________________________
Subject: Disabling MRU Most Recently Used File List
Author:  "Eric Marc Loebenberg"  at Internet
Date:    1/17/97 10:00 AM


Environment: MSVC 4.2b Windows 95
     
At times, say when a flag is set, I want to disable/gray the most recently 
used file list in the FILE menu.  The reason is I do not want to change 
documents at this time.  I have tried playing with  overriding 
CWinApp::OnUpdateRecentFileMenu(CCmdUI* pCmdUI) but have not had much 
success.  I did manage to gray/disable the last file on the menu.
     
Does anyone have an idea or an example of how to do this.  Much 
appreciated.
     
***************************************************************
  Eric Marc Loebenberg                  loebenbe@qc.bell.ca 
  Bell Sygma Inc.                    
  700 de la Gauchetiere West       Tel: 514-870-0465 
  Room 14W1                        Fax: 514-870-7583 
  Montreal, Quebec, Canada
  H3B 4L1
-----From: Mark Conway 

CWinApp::OnUpdateRecentFileMenu() is called only for the first item in
the menu - and if you look at CRecentFileList::UpdateMenu() in
filelist.cpp you'll see why. This handler deletes the menu items, and
adds new ones as required to the menu, then sets some undocumented
members in CCmdUI to stop updates on the new items added. 

Probably the easiest solution to your problem is to code your
OnUpdateRecentFileMenu() something to call the CWinApp version, then go
thru and explicit disable the menu items yourself after the MFC handler
has played with the menu.

Eg something like this.

CYourApp::OnUpdateRecentFileMenu(CCmdUI * pCmdUI)
{
	CWinApp::OnUpdateRecentFileMenu();
	CMenu* pMenu = pCmdUI->m_pMenu;
	if (pMenu != NULL)
	{
		for (int i = 0; i < m_pRecentFileList.GetSize(); i++)
		{
			if (file i in your MRU file is disabled)
				pMenu->EnableItem(ID_RECENT_FILE0 + i, FALSE);
		}
	}
}

Hope this helps
Mark.


>----------
>From: 	Eric Marc Loebenberg[SMTP:loebenbe@qc.bell.ca]
>Sent: 	17 January 1997 15:00
>To: 	MFC
>Subject: 	Disabling MRU Most Recently Used File List
>
>Environment: MSVC 4.2b Windows 95
>
>At times, say when a flag is set, I want to disable/gray the most recently
>used file list in the FILE menu.  The reason is I do not want to change
>documents at this time.  I have tried playing with  overriding
>CWinApp::OnUpdateRecentFileMenu(CCmdUI* pCmdUI) but have not had much
>success.  I did manage to gray/disable the last file on the menu.
>
>Does anyone have an idea or an example of how to do this.  Much
>appreciated.
>
>***************************************************************
>  Eric Marc Loebenberg                  loebenbe@qc.bell.ca
>  Bell Sygma Inc.                    
>  700 de la Gauchetiere West       Tel: 514-870-0465
>  Room 14W1                        Fax: 514-870-7583
>  Montreal, Quebec, Canada
>  H3B 4L1
>
-----From: Christophe Nasarre  

>Eric wrote:
>
>------------------------------------------------------------------------------
>Environment: MSVC 4.2b Windows 95
>
>At times, say when a flag is set, I want to disable/gray the most recently
>used file list in the FILE menu. The reason is I do not want to change
>documents at this time. I have tried playing with overriding
>CWinApp::OnUpdateRecentFileMenu(CCmdUI* pCmdUI) but have not had much
>success. I did manage to gray/disable the last file on the menu.
>
>Does anyone have an idea or an example of how to do this. Much
>appreciated.
>------------------------------------------------------------------------------

Since OnUpdateRecentFileMenu() is not a virtual method, your own
implementation is never called :-)

You just have to add this line in the message map of your application class
 ON_UPDATE_COMMAND_UI_RANGE(ID_FILE_MRU_FILE1, ID_FILE_MRU_FILE1+16, OnUpdateRecentFileMenu)

and:

void CMruApp::OnUpdateRecentFileMenu(CCmdUI* pCmdUI)
{
 pCmdUI->Enable(bMRUEnabled);
}


Good luck

 Christophe -- a poor lonely frenchie --



-----From: SCS.007@mch.scn.de

Forwarded to:      smtp@oev ep 66@servers[mfc-l@netcom.com]
          cc:      
Comments by:       M Chandrashekhar@SCSE1@SCS_Bangalore

   -------------------------- [Original Message] -------------------------      

The soln I'm giving is for MSVC++ 4.0. Not sure whether it'll work for 4.2b.

The implementation of CWinApp::OnUpdateRecentFileMenu calls 
CRecentFileList::UpdateMenu. What this does is, deletes all the existing 
menuitems, reads the new entries from the ini file, adds mnemonics to them 
and then adds menuitems.

So what you can do is : 
Add a handler for ID_FILE_MRU_FILE1. In that

void CSdiappApp::OnUpdateFileMruFile1(CCmdUI* pCmdUI) 
{
	CWinApp::OnUpdateRecentFileMenu(pCmdUI);

  if( yourFlag == I_WANT_TO_DISABLE_MRU_LIST)
  {
        CMenu* temp = pCmdUI->m_pMenu;
	for(int i=0; im_nSize; i++)
	{
		temp->EnableMenuItem(ID_FILE_MRU_FILE1 + i, MF_BYCOMMAND | 
MF_DISABLED | MF_GRAYED);
	}

  }

}

Disadvantages of this solution : 
CRecentrFileList is undocumented.
Accessing protected variables of CWinApp directly.

So what you can do is : In the for loop - you can specify an arbitly large 
number OR
The default is 4 which you can change in LoadStdProfileSettings(). If you are 
changing it - store it and use it else loop thru 4 times.

So many solutions - didya go thru the code before posting the Q??

Chandru.

PS : Read the Source, Luke.
-----From: Christine Hagberg 





//You will need to add these to your message Map
ON_UPDATE_COMMAND_UI(ID_FILE_MRU_FILE1, OnUpdateFileMruFile1)
ON_UPDATE_COMMAND_UI(ID_FILE_MRU_FILE2, OnUpdateFileMruFile2)
ON_UPDATE_COMMAND_UI(ID_FILE_MRU_FILE3, OnUpdateFileMruFile3)
ON_UPDATE_COMMAND_UI(ID_FILE_MRU_FILE4, OnUpdateFileMruFile4)

//Microsoft warns
//   Customization of this command handler is not recommended.
// this is set up so that for the 1st mru calls the   
CWinApp::OnUpdateRecentFileMenu
//This needs to be called once for all 4 of the mru's.  The other 3 will   
not make
//this call.  They will simply gray the choice if we are in CAPTURE mode.

void CVidApp::OnUpdateFileMruFile1(CCmdUI* pCmdUI)
{
 CMainFrame *pFrame = (CMainFrame *)m_pMainWnd;
 if (pFrame != NULL)
 {
  int nMode = pFrame->GetFileMode();
  if ((nMode == CAPTURE) || (nMode == COMPRESS_MODE))
  {
    pCmdUI->Enable(FALSE);
    return;
  }
 }
 //only call this for the 1st in the list of the mru files
 OnUpdateRecentFileMenu(pCmdUI);
}

// I have 4 MRU's You will need to call this for each of your MRU's
void CVidApp::OnUpdateFileMruFile2(CCmdUI* pCmdUI)
{
 CMainFrame *pFrame = (CMainFrame *)m_pMainWnd;
 if (pFrame != NULL)
 {
  int nMode = pFrame->GetFileMode();
  if ((nMode == CAPTURE)  || (nMode == COMPRESS_MODE))
  {
    pCmdUI->Enable(FALSE);
    return;
  }
 }
}


Chris Hagberg
chagberg@datx.com  
-----From: Stuart Downing 

Use...
ON_UPDATE_COMMAND_UI_RANGE(ID_FILE_MRU_FILE1, ID_FILE_MRU_FILE16, OnUpdateRecentFileMenu)
in your App class's message map.

----------
From:  Eric Marc Loebenberg[SMTP:loebenbe@qc.bell.ca]
Sent:  Friday, January 17, 1997 10:01 AM
To:  MFC
Subject:  Disabling MRU Most Recently Used File List

Environment: MSVC 4.2b Windows 95

At times, say when a flag is set, I want to disable/gray the most recently
used file list in the FILE menu.  The reason is I do not want to change
documents at this time.  I have tried playing with  overriding
CWinApp::OnUpdateRecentFileMenu(CCmdUI* pCmdUI) but have not had much
success.  I did manage to gray/disable the last file on the menu.

Does anyone have an idea or an example of how to do this.  Much
appreciated.

***************************************************************
  Eric Marc Loebenberg                  loebenbe@qc.bell.ca
  Bell Sygma Inc.                    
  700 de la Gauchetiere West       Tel: 514-870-0465
  Room 14W1                        Fax: 514-870-7583
  Montreal, Quebec, Canada
  H3B 4L1




SCS.007@mch.scn.de
Monday, January 20, 1997


The soln I'm giving is for MSVC++ 4.0. Not sure whether it'll work for 4.2b.

The implementation of CWinApp::OnUpdateRecentFileMenu calls 
CRecentFileList::UpdateMenu. What this does is, deletes all the existing 
menuitems, reads the new entries from the ini file, adds mnemonics to them 
and then adds menuitems.

So what you can do is : 
Add a handler for ID_FILE_MRU_FILE1. In that

void CSdiappApp::OnUpdateFileMruFile1(CCmdUI* pCmdUI) 
{
	CWinApp::OnUpdateRecentFileMenu(pCmdUI);

  if( yourFlag == I_WANT_TO_DISABLE_MRU_LIST)
  {
        CMenu* temp = pCmdUI->m_pMenu;
	for(int i=0; im_nSize; i++)
	{
		temp->EnableMenuItem(ID_FILE_MRU_FILE1 + i, MF_BYCOMMAND | 
MF_DISABLED | MF_GRAYED);
	}

  }

}

Disadvantages of this solution : 
CRecentrFileList is undocumented.
Accessing protected variables of CWinApp directly.

So what you can do is : In the for loop - you can specify an arbitly large 
number OR
The default is 4 which you can change in LoadStdProfileSettings(). If you are 
changing it - store it and use it else loop thru 4 times.

So many solutions - didya go thru the code before posting the Q??

Chandru.

PS : Read the Source, Luke.




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