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 » OnCommand from a menu or a toolbar? Collapse All
Subject Author Date
Michael Bailey Sep 4, 2006 - 9:59 AM

Hi,

I’m looking for a way to tell whether a command was picked from a menu or a toolbar. Its easy to identify if a command was from an accelerator, but I haven’t figured out a good way to distinguish menu commands from toolbar ones (they both have the same ID). Here’s a code snippet:

//What kind of command
#define RW_FROMMENU 0
#define RW_FROMACCEL 1
#define RW_FROMTOOLBAR 2

BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM lParam) {

    int iFromWhat=RW_FROMMENU;
    if(HIWORD(wParam)) iFromWhat=RW_FROMACCEL;

// How to I know and set RW_FROMTOOLBAR ????

    DoMyCommandMessage(LOWORD(wParam),iFromWhat);

    return CFrameWnd::OnCommand(wParam, lParam);
}

Thanks,
Mike

Technical Support Sep 5, 2006 - 11:31 AM

The only way to determine the command source (toolbar or menu) is to use different identifiers for menu items and toolbar buttons.

Eugene Wineblat Sep 5, 2006 - 5:08 AM

MSDN: search WM_COMMAND
wParam
The high-order word specifies the notification code if the message is from a control.

-->> If the message is from an accelerator, this value is 1.
-->> If the message is from a menu, this value is zero.

The low-order word specifies the identifier of the menu item, control, or accelerator

I think...

#define WPARAM_HI_WORD_FROM_ACCELERATOR 1
#define WPARAM_HI_WORD_FROM_MENU 0

BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM lParam) {

int iFromWhat = RW_FROMTOOLBAR;

WORD wHI = HIWORD ( wParam );
switch ( wHI )
{
case WPARAM_HI_WORD_FROM_ACCELERATOR:
{
iFromWhat = RW_FROMACCEL;
break;
}
case WPARAM_HI_WORD_FROM_MENU:
{
iFromWhat = RW_FROMMENU;
break;
}
};

DoMyCommandMessage(LOWORD(wParam),iFromWhat);

return CFrameWnd::OnCommand(wParam, lParam);
}

Michael Bailey Sep 5, 2006 - 8:47 AM

The problem with the code is the high-order of wParam is zero for menus AND toolbar commands. I’m trying to figure out if the user selected my command from the menu or the toolbar.

I seem to recall there is a virtural function that the framwork calls when a menu opens and closes, but I can’t seem to find it. I may have to use a global to tell if the menu has been opened or not, then use that in OnCommand.

Any other ideas?

Thanks,
Mike