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 » MenuBar/Detecting when user enter/exit menu Collapse All
Subject Author Date
Alexey Zbritsky Jan 15, 2004 - 2:45 AM

Hello.


In my application, i need to detect when user enter/exit main menu. in standard mfc menu i work with messages WM_ENTERMENULOOP/WM_EXITMENULOOP.


How i can detect entering/exiting main menu by using CExtMenuControlBar instead standard mfc menu (WM_ENTERMENULOOP/WM_EXITMENULOOP do not send to MainFrame.)


Thanks. Sorry for my english.

Technical Support Jan 15, 2004 - 4:16 AM

Dear Alexey,


It’s not difficult to do. Just override two registered messages in the frame window: CExtPopupMenuWnd::g_nMsgPrepareMenu and CExtPopupMenuWnd::g_nMsgNotifyMenuClosed. This will allow you to determine when the menu opens and closes. The messages are generated each time when any popup menu appears/disappears on the screen.


Please add the lines below to the frame’s message map:

ON_REGISTERED_MESSAGE ( CExtPopupMenuWnd::g_nMsgPrepareMenu, OnExtMenuPrepare ) 
ON_REGISTERED_MESSAGE ( CExtPopupMenuWnd::g_nMsgNotifyMenuClosed, OnExtMenuClosed )

You should also add the corresponding methods to your frame window:

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

The above described technique is implemented in the DrawCli sample.

Alexey Zbritsky Jan 15, 2004 - 8:33 AM

I look sources of CExtPopupMenuWnd searching a place where sending g_nMsgNotifyMenuClosed. Condition


if (::IsWindow(m_hWndCmdReciever))
::SendMessage(...)


in method PostNCDestroy() is true and SendMessage is called but not handled by MainFrame. If in this statement use WM_EXITMENULOOP instead g_nMsgNotifyMenuClosed message normally handled by MainFrame. but messages g_nMsgPrepareMenu and g_nMsgNotifyMenuClosed not handled (i test it).


 

Alexey Zbritsky Jan 15, 2004 - 4:42 AM

Thanks. but i have some troubles.


OnExtMenuPrepare works normally, but OnExtMenuClosed was never called.


I add both ON_REGISTERED_MESSAGE(...) to the frame’s message map, and wrote methods OnExtMenuPrepare, OnExtMenuClosed.


 

Technical Support Jan 15, 2004 - 6:45 AM

Sorry, we forgot to mention one important point.

If your application uses a menu bar, the g_nMsgNotifyMenuClosed message is intercepted by CExtMenuControlBar. So, if you want to process this message (as well as g_nMsgPrepareMenu), you need to do this before.

Please override the OnHookWndMsg() method of the CExtMenuControlBar class:

class CMyMenuBar : public CExtMenuControlBar 
{ 
public: 
    bool CMyMenuBar::OnHookWndMsg( 
        LRESULT &lResult, 
        HWND hWndHooked, 
        UINT nMessage, 
        WPARAM &wParam, 
        LPARAM &lParam ) 
    { 
        bool bRetVal = 
            CExtMenuControlBar::OnHookWndMsg( 
                lResult, 
                hWndHooked, 
                nMessage, 
                wParam, 
                lParam 
            ); 

        if( nMessage == CExtPopupMenuWnd::g_nMsgPrepareMenu )  
        { 
            CExtPopupMenuWnd *pPopupWnd = 
                reinterpret_cast< CExtPopupMenuWnd * >( lParam ); 
            ASSERT_VALID(pPopupWnd); 
            ASSERT_KINDOF(CExtPopupMenuWnd, pPopupWnd); 
            TRACE("Before menu displayed\n"); 
            .... 
        } 

        if( nMessage == CExtPopupMenuWnd::g_nMsgNotifyMenuClosed )
        { 
            CExtPopupMenuWnd *pPopupWnd = 
                reinterpret_cast< CExtPopupMenuWnd * >( lParam ); 
            ASSERT_VALID(pPopupWnd); 
            ASSERT_KINDOF(CExtPopupMenuWnd, pPopupWnd); 
            TRACE("After menu closed\n"); 
            .... 
        } 
        return bRetVal; 
    } 
}; // class CMyMenuBar

Alexey Zbritsky Jan 15, 2004 - 8:36 AM

Thanks.


It works.