Link to home
Start Free TrialLog in
Avatar of cplau
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_MAINFRAME);
SetMenu(CreateMenu);
SubMenu = CreateMenu->GetSubMenu(3);
CString dbfile = ((MyApp*)::AfxGetApp())->GetProfileString
("DefaultName","Name");
SubMenu->ModifyMenu(ID_FIRST_DB,MF_ENABLED|MF_STRING,ID_FIRST_DB,dbfile);

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(LPCREATESTRUCT 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!
Avatar of migel
migel

Hi!
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::OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd,
      CWnd* pDeactivateWnd)
{
    CMDIFrameWnd* pFrame = GetMDIFrame();

// hSetMenu - menu prepared before
    ::SendMessage(pFrame->m_hWndMDIClient, WM_MDISETMENU,
        (WPARAM)hSetMenu,(LPARAM)pFrame->GetWindowMenuPopup(hSetMenu));
}

hSetMenu is a modified menu hadler. You can call LoadMenu in the OnCreate method and modify getted menu.
ASKER CERTIFIED SOLUTION
Avatar of nsrvijay
nsrvijay

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial