Solved

Menu?

Posted on 1999-01-18
2
251 Views
Last Modified: 2013-11-20
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!
0
Comment
Question by:cplau
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 12

Expert Comment

by:migel
ID: 1327908
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.
0
 
LVL 1

Accepted Solution

by:
nsrvijay earned 80 total points
ID: 1327909
Hi
  U have placed ur code in the oncreate part of the mdichldwindow.But this code need to be placed in the OnMdiActivate part(ON_WM_MDIACTIVATE).
please try this as i have tried this sort of this before..
Note:
OnMDIActivate is called for the MDI child window being
deactivated and the child window being activated.

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question