cplau
asked on
Menu?
Hi All,
I want to update the content of the menu after starting my application by reading a string from ini file.
I have used the following code to implement :
CMenu *CreateMenu, *SubMenu;
CreateMenu = new CMenu;
CreateMenu->LoadMenu(IDR_M AINFRAME);
SetMenu(CreateMenu);
SubMenu = CreateMenu->GetSubMenu(3);
CString dbfile = ((MyApp*)::AfxGetApp())->G etProfileS tring
("DefaultName","Name");
SubMenu->ModifyMenu(ID_FIR ST_DB,MF_E NABLED|MF_ STRING,ID_ FIRST_DB,d bfile);
CreateMenu->Detach();
delete CreateMenu;
////////////////////////// ////////// ////////// ////////// /
The menu had been updated after I have push a button in the
toolbar. But it cannot be updated if I put the above code inside the function CChildFrame::OnCreate(LPCR EATESTRUCT lpCreateStruct). What is the reason about this?
Also, after opening a new window using another view class and menu, if I use the mouse click back to the original window, the context of the menu had been resetted.
Thus, I want to know how can I change the context of the menu after reading a string from ini file..and it will not be resetted if I open another window.
Anyone can help me?
Thank you very much!
I want to update the content of the menu after starting my application by reading a string from ini file.
I have used the following code to implement :
CMenu *CreateMenu, *SubMenu;
CreateMenu = new CMenu;
CreateMenu->LoadMenu(IDR_M
SetMenu(CreateMenu);
SubMenu = CreateMenu->GetSubMenu(3);
CString dbfile = ((MyApp*)::AfxGetApp())->G
("DefaultName","Name");
SubMenu->ModifyMenu(ID_FIR
CreateMenu->Detach();
delete CreateMenu;
//////////////////////////
The menu had been updated after I have push a button in the
toolbar. But it cannot be updated if I put the above code inside the function CChildFrame::OnCreate(LPCR
Also, after opening a new window using another view class and menu, if I use the mouse click back to the original window, the context of the menu had been resetted.
Thus, I want to know how can I change the context of the menu after reading a string from ini file..and it will not be resetted if I open another window.
Anyone can help me?
Thank you very much!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I think that your application is MDI.
To modify mdi child window menu you must override OnMDIActivate method (due to framework in this method just set default child menu (getted by LoadMenu() function).
for example:
void CMyMDIChildWnd::OnMDIActiv
CWnd* pDeactivateWnd)
{
CMDIFrameWnd* pFrame = GetMDIFrame();
// hSetMenu - menu prepared before
::SendMessage(pFrame->m_hW
(WPARAM)hSetMenu,(LPARAM)p
}
hSetMenu is a modified menu hadler. You can call LoadMenu in the OnCreate method and modify getted menu.