You will often want to change the menus of the MDI parent window to reflect the state of the currently active MDI child window. This is especially true when there is more than one type of child window. However, it is true even when there is only one type of child window because menus often must change to correspond to the state of a particular window.
·To change an MDI window menu:
1.Use the GetParentFrame function, as explained previously in “Accessing the MDI Parent Window.”
2.Once you have the frame window, you can call the MDISetMenu member function to change the menu state for the frame window.
The following code shows how to respond to the WM_MDIACTIVATE message with the OnMDIActivate message-map message-handler function to change the frame window's menus. The flag argument to the handler is TRUE if the window is being activated, FALSE if it is being deactivated.
void
CMyChildWnd::OnMDIActivate( BOOL flag, CWnd* pActive, CWnd* pDeActive )
{
CMDIFrameWnd* pFrame = (CMDIFrameWnd*)GetParentFrame();
m_pMenuChartWindow = m_pMenuChart->GetSubMenu( CHART_MENU_POS );
m_pMenuInitWindow = m_pMenuInit->GetSubMenu( INIT_MENU_POS );
if( flag == TRUE )
{
pFrame->MDISetMenu( m_pMenuChart, m_pMenuChartWindow );
}
else
if( flag == FALSE )
{
pFrame->MDISetMenu( m_pMenuInit, m_pMenuInitWindow );
}
pFrame->DrawMenuBar();
}