Joao Paulo Figueira (joao.fig@mail.telepac.pt), June 04, 2003.
I want to get the handle of command bar menu so that I can change it. Where is it?
Command bar menu handles are not readily available, especially if you use MFC. The framework uses the InsertMenuBar method to insert menus in the command bar, and it does so by splitting the menu in its popups, and creating a button for each. These buttons have the same text as the popup (with the & removed) and are created with a special (and undocumented) style: TBSTYLE_NO_DROPDOWN_ARROW. This is how a popup menu is simulated.
Ok. But where is the menu?
The popup's HMENU is stored in the TBBUTTON structure in the dwData variable. This is a DWORD where the popup handle is stored. And this is the handle that you want.
So, how do I get it?
You can get the handle using the TB_GETBUTTON message, using the button index as the wParam and a TBBUTTON structure pointer in lParam. The index is an ordinal starting at zero for the first menu (or button).
If you want to use MFC to get the TBBUTTON structure, first cast the pointer of the CCeCommandBar to a CToolBarCtrl and then use the GetButton method. This cast is safe as long as you use it just for this purpose.