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

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


Replaceable Menus

Brian Jones -- BrianJ@apptechsys.com
Tuesday, February 18, 1997

Environment: MSVC 4.2b, NT 4.0

I have a 3 pane splitter application with 3 different views (static).  I 
would like to be able to provide a different set of menu options for each 
view, dynamically replacing each menu in the OnActivateView member. 
 Currently, I am doing this by obtaining a handle to the frame and calling 
MDISetMenu:
	pMenu = new CMenu;
	pMenu->LoadMenu(IDR_VIEW_MENU);
	CMDIFrameWnd* pFrame = (CMDIFrameWnd*)AfxGetMainWnd();
	pmenuOld = pFrame->MDISetMenu(pMenu,NULL);
	if(pmenuOld)
		pmenuOld->DestroyMenu();
	pMenu->Detach();
	delete pMenu;
	pFrame->DrawMenuBar();

I don't believe this is the best way to do this, especially since the 
documentation for MDISetMenu says not to use it if the framework handles 
menus.  The biggest problem I am having is with the DestroyMenu call.  If I 
don't call it, I eventually use up all of the menu resources for NT and the 
app will not change menus.  If I do call it, the first time the app tries 
it I get an exception directly after making the call (the Assertion varies 
depending on what  follows the call, so I won't include the error code 
here).

Am I going about this thing incorrectly, am I leaving something out, or is 
there a "right" way to do this?

Thanks,

Brian



*	Brian Jones
*	Applied Technical Systems
*	Bremerton, WA  USA




Jeremiah Talkar -- jtalkar@optika.com
Wednesday, February 19, 1997

[Mini-digest: 2 responses]


Why are you creating a new menu object every single time OnActiveView()   
  is called? Just create all of them once when your frame window class is   
  initialized ( OnCreate() ) and destroy them in the destructor. Then all   
  you have to do is access the respective menu handle and use it in the   
  call to MDISetMenu().
Jeremiah


 -----Original Message-----
From: Brian Jones
Sent: Tuesday, February 18, 1997 5:15 PM
To: 'MFC List'
Subject: Replaceable Menus


Environment: MSVC 4.2b, NT 4.0

I have a 3 pane splitter application with 3 different views (static).  I
would like to be able to provide a different set of menu options for each   

view, dynamically replacing each menu in the OnActivateView member.
 Currently, I am doing this by obtaining a handle to the frame and   
calling
MDISetMenu:
 pMenu = new CMenu;
 pMenu->LoadMenu(IDR_VIEW_MENU);
 CMDIFrameWnd* pFrame = (CMDIFrameWnd*)AfxGetMainWnd();
 pmenuOld = pFrame->MDISetMenu(pMenu,NULL);
 if(pmenuOld)
  pmenuOld->DestroyMenu();
 pMenu->Detach();
 delete pMenu;
 pFrame->DrawMenuBar();

I don't believe this is the best way to do this, especially since the
documentation for MDISetMenu says not to use it if the framework handles
menus.  The biggest problem I am having is with the DestroyMenu call.  If   
I
don't call it, I eventually use up all of the menu resources for NT and   
the
app will not change menus.  If I do call it, the first time the app tries   

it I get an exception directly after making the call (the Assertion   
varies
depending on what  follows the call, so I won't include the error code
here).

Am I going about this thing incorrectly, am I leaving something out, or   
is
there a "right" way to do this?

Thanks,

Brian



* Brian Jones
* Applied Technical Systems
* Bremerton, WA  USA


-----From: KIbrahim_Ideal@nets.com.jo (Kefah Ibrahim)

Hi,
You can associate your views with there menu resources using
CMultiDocTemplate, and passing the appropriate value for the first parameter,
this parameter specifies the ID of the resources used.
I think the following code  may serve your need. 
  
// call these functions from from InitInstance 

    AddDocTemplate( new CMultiDocTemplate( IDR_MYTYPE1,
                        RUNTIME_CLASS( CMyDoc ),
                        RUNTIME_CLASS( CChildFrame ),
                        RUNTIME_CLASS( CMyView2 ) ) );

    AddDocTemplate( new CMultiDocTemplate( IDR_MYTYPE2,
                        RUNTIME_CLASS( CMyDoc ),
                        RUNTIME_CLASS( CChildFrame ),
                        RUNTIME_CLASS( CMyView2 ) ) );

Good luck,

Kefah I.
IdealSoft
E-mail:KIbrahim_ideal@nets.com.jo


mfc-l@netcom.com,Internet writes:
Environment: MSVC 4.2b, NT 4.0

I have a 3 pane splitter application with 3 different views (static).  I 
would like to be able to provide a different set of menu options for each 
view, dynamically replacing each menu in the OnActivateView member. 
 Currently, I am doing this by obtaining a handle to the frame and calling 
MDISetMenu:
	pMenu = new CMenu;
	pMenu->LoadMenu(IDR_VIEW_MENU);
	CMDIFrameWnd* pFrame = (CMDIFrameWnd*)AfxGetMainWnd();
	pmenuOld = pFrame->MDISetMenu(pMenu,NULL);
	if(pmenuOld)
		pmenuOld->DestroyMenu();
	pMenu->Detach();
	delete pMenu;
	pFrame->DrawMenuBar();

I don't believe this is the best way to do this, especially since the 
documentation for MDISetMenu says not to use it if the framework handles 
menus.  The biggest problem I am having is with the DestroyMenu call.  If I 
don't call it, I eventually use up all of the menu resources for NT and the 
app will not change menus.  If I do call it, the first time the app tries 
it I get an exception directly after making the call (the Assertion varies 
depending on what  follows the call, so I won't include the error code 
here).

Am I going about this thing incorrectly, am I leaving something out, or is 
there a "right" way to do this?

Thanks,

Brian



*	Brian Jones
*	Applied Technical Systems
*	Bremerton, WA  USA







Become an MFC-L member | Вернуться в корень Архива |