Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS General Discussion » Calling GetMenu() returns NULL after changing to CExtMenuControlBar. Collapse All
Subject Author Date
Scott Velasquez Feb 14, 2007 - 11:36 AM

I followed the docs on how to update my app to use ProfUI menubar’s:

if ( !m_wndMenuBar.Create(NULL, this, IDR_MAINFRAME) ||
!m_wndMenuBar.LoadMenuBar( IDR_MAINFRAME) )
{
TRACE0("Failed to create menubar\n");
return -1;
}

but now when my menu handler is called which resides in my view class, GetMenu() return false. Here is the code I used previously before switching to ProfUI:

void CLevel3DView::OnViewGrid()
{
CWnd* pParent = GetParent();

CMenu* pMenu = pParent->GetMenu();
ASSERT(pMenu != NULL);

UINT iState = pMenu->GetMenuState(ID_VIEW_GRID, MF_BYCOMMAND);

pMenu->CheckMenuItem(ID_VIEW_GRID, MF_BYCOMMAND | (iState == MF_CHECKED) ? MF_UNCHECKED : MF_CHECKED);
mDrawGrid = (iState == MF_CHECKED) ? false : true;

// Redraw the viewport
OnDraw( NULL );
}

Thanks!

Technical Support Feb 14, 2007 - 12:22 PM

The CExtMenuControlBar::GetMenu() method is for internal use only. You should never call this method. If you need to rebuild the top level list of toolbar buttons in menu bar, then you should invoke the CExtMenuControlBar::UpdateMenuBar() method which invokes the CExtMenuControlBar::_UpdateMenuBar() internal virtual method for re-creating list of the CExtBarButton toolbar buttons implementing the top menu level displayed in the menu bar. The CExtMenuControlBar::_UpdateMenuBar() virtual method can be overridden in your project and you can insert your additional buttons into the menu bar or even build all buttons from scratch. If you need to modify the popup menus displayed from the menu bar, toolbars or invoked as context menus, then you should handle the CExtPopupMenuWnd::g_nMsgPrepareMenu or CExtPopupMenuWnd::g_nMsgPrepareOneMenuLevel registered windows message which is invoked for popup menu or its one level before it appears on the screen and allows to create the menu items and sub menus on-the-fly. The CPagePopupMenus::OnExtMenuPrepare() method in the ProfUIS_Controls sample application is used for changing the context menu displayed over the Popup Menus page on-the-fly can be used as a sample. The similar handler method can be added into the main frame class for initializing the menu bar’s menus.

Scott Velasquez Feb 14, 2007 - 1:56 PM

BTW, GetMenu() is being called on a CFrameWnd object, not on CExtMenuControlBar.

Scott Velasquez Feb 14, 2007 - 1:50 PM

So what is the proper way of updating the menu to show a check mark next to the menu item? Previously I would check the state and toggle it.

Technical Support Feb 15, 2007 - 4:18 AM

Each menu/toolbar item controls its status (enabled/disabled, checked/unchecked) via MFC command updating mechanism. So you can make the menu item checked by providing an update handler for the command ID (simply add the ON_UPDATE_COMMAND_UI handler for this command):

<code><code>afx_msg void OnUpdateYourCommand(CCmdUI* pCmdUI);

...

ON_UPDATE_COMMAND_UI(ID_YOUR_COMMAND, OnUpdateYourCommand)

...

void CMainFrame::OnUpdateYourCommand( CCmdUI * pCmdUI ) 
{
 pCmdUI->SetCheck( m_bChecked ? 1 : 0 );
}

Suhai Gyorgy Feb 15, 2007 - 2:50 AM

I guess in your messagemap you have a line that connects command ID_VIEW_GRID to OnViewGrid message handler method, and also your mDrawGrid boolean class variable gives you always whether the view should be drawn (it is visible) or not. So this is really easy:

BEGIN_MESSAGE_MAP(CLevel3DView, CYourBaseView)
	...
	ON_COMMAND(ID_VIEW_GRID, OnViewGrid)
	ON_UPDATE_COMMAND_UI(ID_VIEW_GRID, OnUpdateViewGrid)
	...
END_MESSAGE_MAP()
...
void CLevel3DView::OnViewGrid() 
{
	mDrawGrid = !mDrawGrid;
	OnDraw( NULL ); // maybe Invalidate(); UpdateWindow(); would be better here
}

void CLevel3DView::OnUpdateViewGrid(CCmdUI* pCmdUI) 
{
	pCmdUI->Enable( TRUE );
	pCmdUI->SetCheck( mDrawGrid ? TRUE : FALSE );
}
That should solve your problem.

Scott Velasquez Feb 15, 2007 - 9:17 AM

Thanks guys, this works perfectly!