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 » Prof-Uis and MFC CMenu Collapse All
Subject Author Date
Robert Hofstetter Oct 11, 2010 - 10:40 PM


In a standard MFC application, the current displayed popup menu will be killed automatically when a modal dialog is displayed. But, in a Prof-Uis application, the standard popup menu (CMenu, not Prof-Ui menu) stays on and the application is locked. Neither the menu nor the modal dialog is responsive. Unless you click outside of the application, the menu is gone and then you can click the dialog. Is this prof-Uis bug?

You can easily reproduce the problem with the Prof-Uis sample "SDI" with the following code changes

Add a context menu and a Start Timer menu item. When the timer is fired, a modal message box is displayed. 

void CChildView::OnContextMenu(CWnd* pWnd, CPoint point)


    CMenu menu;



    menu.AppendMenu(MF_STRING, 1, "Menu 1");

    menu.AppendMenu(MF_STRING, 2, "Menu 2");

    menu.AppendMenu(MF_STRING, 3, "Menu 3");

    menu.TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, pWnd);


void CChildView::OnTimer(UINT nIDEvent)




    CWnd ::OnTimer(nIDEvent);


void CChildView::OnEditStarttimer()


    SetTimer(0, 5000, NULL);



Now, Run the application and click the Start Timer menu firstly then right-click the View area to display the propup menu and wait.

Please let me know if you can fix this problem or other suggestions? Thanks

Technical Support Oct 12, 2010 - 12:44 PM

Here is the solution 1 (a bad solution, may not work with future Windows versions, 5 lines of code):

void CChildView::OnContextMenu( CWnd * pWnd, CPoint point ) 
      pWnd; // important line 1
CWnd* pWndPopupOwner = this; // important line 2
      while( ( pWndPopupOwner->GetStyle() & WS_CHILD ) != 0 ) // important line 3
            pWndPopupOwner = pWndPopupOwner->GetParent(); // important line 4
CMenu menu;
      menu.AppendMenu( MF_STRING, 1, "Menu 1" );
      menu.AppendMenu( MF_STRING, 2, "Menu 2" );
      menu.AppendMenu( MF_STRING, 3, "Menu 3" );
      menu.TrackPopupMenu( TPM_LEFTALIGN, point.x, point.y, /*pWnd*/ pWndPopupOwner ); // important line 5

Here is the solution 2 (a good solution, 1 line of code):
void CChildView::OnTimer( UINT nIDEvent ) 
      SendMessage( WM_CANCELMODE ); // important line
      CWnd::OnTimer( nIDEvent );

You need to display a modal dialog on timer. It’s good idea to send WM_CANCELMODE message to window which is created in the main UI thread. This cancels both Prof-UIS and Win32 menus, context menus and any other types of menus and even any other types of popup windows acting like menus. This cancels any correctly coded in-place activated editor controls inside any other controls in created in the main UI thread.