Solved

Menu?

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Show shut-down message as Windows 8 shuts down. 9 91
Perl Awk Need Help 3 118
Whole sheet autoscrub still needed 19 51
sumHeights2  challenge 7 105
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

809 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