Solved

Menu?

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ODBC Connection Logging, ADO.NET 6 71
Detect CR LF to each line 12 176
zeroFront challenge 7 124
JQuery serialize and unserialize 8 201
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

696 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