Solved

Menu?

Posted on 1999-01-18
2
243 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
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now