Click here to Skip to main content
13,005,192 members (63,644 online)
Click here to Skip to main content
Add your own
alternative version


19 bookmarked
Posted 19 Mar 2003

Disabling top-level popup menus in the PocketPC 2002

, 19 Mar 2003
Rate this:
Please Sign up or sign in to vote.
How to eneble and disable top-level popup menus in the Command Bar of PocketPC 2002 applications.

Sample Image - CeMultiBarMenu.jpg


This article shows a technique to disable top-level popup menus embedded in the Command Bar of PocketPC 2002 applications built with MFC. This is the result of my continuing discussions with John Simmons / outlaw programmer about the "ease of use" of the PocketPC 2002 User Interface API under MFC. On our last take at these issues, we found that disabling top-level popup menus is not a trivial task. Here is one solution.

Top-level popup menus

They are not popup menus. They are fakes. They are toolbar buttons! I reached this conclusion by looking at how CCeCommandBar::LoadToolBar is implemented. The menu resource you supply is broken into its popups, and a text toolbar button is created for each one of them. So it is useless to try and use CMenu methods to enable or disable these, you have to manipulate the underlying buttons.

Popup menu buttons are created with standard IDs starting with 0xF000 for the first one, and are incremented by 1 for the next ones. So, in order to know what button you want to access, you have to know its ordinal position. If you are using the "shared new" button, 0xF000 will be the first one to the right of it.

The solution

My first approach was to use the TB_ENABLEBUTTON message. It seemed to work until John Simmons noticed that some of the button's texts were being truncated when grayed. In fact, when the toolbar disables a text button, it paints it in gray with a white shadow, making the text one pixel wider. Needless to say that the rectangle that holds this text is not changed and the text is clipped...

The next approach was based on the GetButtonInfo and SetButtonInfo methods of the CToolBarCtrl that supports all toolbars. With these, I set a number of properties of the TBBUTTONINFO structure, namely fsState and cx. The first one is used to set the button state (enabled or disabled), where the second is used to increase the button size when it is disabled, and to decrease it back when it is enabled.

I encapsulated the solution in the CCeCommandBarEx class that has only one method (besides standard constructor and destructor): EnablePopupMenu. The implementation is as follows:

BOOL CCeCommandBarEx::EnablePopupMenu(int iIndex, BOOL bEnable)
    CToolBarCtrl&    rToolBar = GetToolBarCtrl();
    TBBUTTONINFO    tbi;
    int                nID = 0xf000 + iIndex;
    CSize            sizeImage(16,15),
                    sizeButton(23, 21);
    BOOL            bRval;

    tbi.cbSize        = sizeof(tbi);
    tbi.dwMask        = TBIF_STATE | TBIF_SIZE | TBIF_COMMAND;
    tbi.idCommand    = nID;
    bRval            = rToolBar.GetButtonInfo(nID, &tbi);
        if(tbi.fsState & TBSTATE_ENABLED)
   += bEnable ? 0 : 1;
   -= bEnable ? 1 : 0;

            tbi.fsState |= TBSTATE_ENABLED;
            tbi.fsState &= ~TBSTATE_ENABLED;

        rToolBar.SetButtonInfo(nID, &tbi);
        SetSizes(sizeButton, sizeImage);

    return bRval;

Note that I have to call SetSizes to avoid an incomprehensible bug I found: when increasing the popup menu button size, all other buttons would change their sizes as well.

The demo project

You will find that the demo project is an adaptation of the same project I used in my other article Multiple Toolbars in the PocketPC 2002 , but with some changes namely:

  • Tool tips on all toolbars
  • Toolbars are now exclusively shown


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

João Paulo Figueira
Software Developer (Senior) Frotcom International
Portugal Portugal
I work on R&D for Frotcom International, a company that develops web-based fleet management solutions.

You may also be interested in...

Comments and Discussions

Generaledit control in the toolbar Pin
Shabrawy91125-Aug-05 6:21
memberShabrawy91125-Aug-05 6:21 
GeneralRe: edit control in the toolbar Pin
João Paulo Figueira25-Aug-05 6:32
memberJoão Paulo Figueira25-Aug-05 6:32 
GeneralRe: edit control in the toolbar Pin
Shabrawy91126-Aug-05 2:17
memberShabrawy91126-Aug-05 2:17 
GeneralRe: edit control in the toolbar Pin
João Paulo Figueira26-Aug-05 3:00
memberJoão Paulo Figueira26-Aug-05 3:00 
GeneralRe: edit control in the toolbar Pin
Shabrawy91127-Aug-05 5:14
memberShabrawy91127-Aug-05 5:14 
GeneralRe: edit control in the toolbar Pin
Shabrawy91127-Aug-05 6:29
memberShabrawy91127-Aug-05 6:29 
GeneralExcellent! Pin
Jac Goudsmit13-Nov-03 16:54
sussJac Goudsmit13-Nov-03 16:54 
GeneralHi It's great. I want to increase the height of the command bar Pin
K.Senthil Kumar12-Nov-03 19:24
memberK.Senthil Kumar12-Nov-03 19:24 
GeneralRe: Hi It's great. I want to increase the height of the command bar Pin
João Paulo Figueira13-Nov-03 6:24
memberJoão Paulo Figueira13-Nov-03 6:24 
GeneralRe: Hi It's great. I want to increase the height of the command bar Pin
Carmen_Panturu18-Apr-04 20:07
memberCarmen_Panturu18-Apr-04 20:07 
GeneralDisable toolbar button in PocketPC 2002 Pin
annamammen1-Oct-03 22:00
memberannamammen1-Oct-03 22:00 
GeneralRe: Disable toolbar button in PocketPC 2002 Pin
João Paulo Figueira1-Oct-03 22:29
memberJoão Paulo Figueira1-Oct-03 22:29 
GeneralGreat work! Pin
Daniel S.20-Mar-03 6:15
memberDaniel S.20-Mar-03 6:15 
GeneralGood detective work... Pin
Codin' Carlos20-Mar-03 5:13
memberCodin' Carlos20-Mar-03 5:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170627.1 | Last Updated 20 Mar 2003
Article Copyright 2003 by João Paulo Figueira
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid