Professional UI Solutions
Site Map   /  Register


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 Tech Support » How do we update CExtPopupMenuWnd after OnUpdateFileMenu( CCmdUI* pCmdUI ) calls InsertMenu(), etc. Collapse All
Subject Author Date
Dave Foster Sep 24, 2009 - 1:58 PM

We have an application, which must be maintained using MFC, as well as uses the Prof-UIS library (different build targets).  In several locations throughout the code, menu items are inserted dynamically to the CMenu instances, and this works fine for MFC.  I have discovered that we must ignore the m_pMenu referenced within the pCmdUI parameter when running under Prof-UIS - this is OK.

However, the observation is that when running with Prof-UIS, the menu item inserted with InsertMenu(), does not appear in the menu until the drop-down menu is dropped down a second time.  I have read about using OnExtMenuPrepare() to to dynamic menu creation, but this method is not compatible with our desire to maintain the MFC version in the mannor it is currently being used.  What I hope to do is use OnExtMenuPrepare() to force a new transfer of the CMenu items to the CExtPopupMenuWnd items (I guess through UpdateFromMenu(), but the following snippet closes the menu and causes an assertion):

LRESULT CMainFrame::OnExtMenuPrepare(WPARAM wParam, LPARAM lParam) {

 CExtPopupMenuWnd::MsgPrepareMenuData_t * pData = reinterpret_cast< CExtPopupMenuWnd::MsgPrepareMenuData_t * > (wParam);                                        

 ASSERT( pData != NULL );

 CExtPopupMenuWnd * pPopup = pData->m_pPopup;

 ASSERT( pPopup != NULL );

 CMenu *pMenu = m_wndMenuBar->GetMenu();

 pPopup->UpdateFromMenu( GetSafeHwnd(), pMenu, true, false );

return TRUE;


In addition, the menu pMenu is not the one which I think should be bound with this instance of pData->m_pPopup.   Any sugguestions as to how to make this scheme work?


Technical Support Sep 25, 2009 - 2:02 PM

Could you please create a small test project reproducing the assertions and crashing and send it to the support mail box at this web site?

Technical Support Sep 25, 2009 - 6:44 AM

You forgot to invoke the pData->m_bMenuChanged; line of code.

Dave Foster Sep 25, 2009 - 1:19 PM

I followed what happens when pData->bMenuChanged is set to TRUE, inside of OnExtMenuPrepare(), with and without the call to pPopup->UpdateFromMenu(), and the results are mixed.  I can see that without the call "UpdateFromMenu", the response within the routine CExtPopupMenuWnd::_TrackPopupMenu() to call _SyncItems() and _UpdateCmdUI() would seem desirable, but _SyncItems() is geared towards making the CMenu reflect what has been changed on the instance of CExtPopupMenuWnd, and not visa-versa.  Otherwise, if pData->bMenuChanged is set to TRUE, followed by a call to UpdateFromMenu(), the program still asserts, and then crashes.  

What I want to do is synchronize the chages made within our OnUpdateXXX( CCmdUI *pCmdUI) to the CMenu objects they are being called for to "instantly" update the instances of CExtPopupMenuWnd that are mirroring them.  I notice that the protected function _BuildItems really is what is the essence of UpdateFromMenu() that is needing to be called, but too much else is being done.  I  think I am going to have to write my own reconciliator function, to update the instance of CExtPopupMenuWnd. 

BTW - the problem with the update of the menu is only on the first time the pull-down window is dropped-down.  Subsequent calls seem fine.