dcsimg
December 6, 2016
Hot Topics:

Adapting Application Menus to the CE User Interface

  • October 30, 2002
  • By Nancy Nicolaisen
  • Send Email »
  • More Articles »

Using Standard Button Images

You can also get bitmap images by "borrowing" them from the Windows CE small color bit map lists. This strategy has a couple of big advantages. First the bitmaps are already there, so you don't have to use any memory to get them. Also, you are assured of their color safety and proper size. Here's how you make the standard bitmap list available.

    // Add standard bitmaps for buttons.    CommandBar_AddBitmap (hwndCB, HINST_COMMCTRL,                          IDB_STD_SMALL_COLOR,                          0, 0, 0);

The parameters, in the order shown, are the handle to the command bar, a constant representing the instance handle to the common control dll, the resource ID of a system bit map list, with the remaining three parameters are always set to zero. The resource identifier IDB_STD_SMALL_COLOR references a bitmap list that contains the "standard" bitmaps. If you use the resource identifier IDB_VIEW_SMALL_COLOR, you get access to the "view" bitmap list.

Table 4 - Individual Bitmap Resource Identifiers for Standard Bitmaps

STD_COPY
STD_CUT
STD_DELETE
STD_FIND
STD_FILENEW
STD_FILEOPEN
STD_FILESAVE
STD_HELP
STD_PROPERTIES
STD_REDOW
STD_REPLACE
STD_PASTE
STD_PRINT
STD_PRINTPRE
STD_UNDO

Table 5 - Individual Bitmap Resource Identifiers for View Bitmaps

VIEW_DETAILS
VIEW_LARGEICONS
VIEW_LIST
VIEW_SMALLICONS
VIEW_SORTDATE
VIEW_SORTNAME
VIEW_SORTSIZE
VIEW_SORTTYPE

Like your own bitmaps, adding the system's bitmaps to the command bar list is cumulative. When you want to reference a specific bitmap you add its individual constant to the zero based offset of the last bitmap loaded before it.

Putting It All Together

Here are the three steps for adding buttons to a command bar:

Initialize an array of TBBUTTON structures. There must be on for each buttonAdd button bitmap images to the command bar.

Add the buttons

This code adds buttons with custom bitmap images

// Command band button initialization structure, custom bitmapsTBBUTTON tbCmdButtons[] = {//  BitmapIndex   Command  State     Style    UserData  String    {0,           IDM_ONE,  TBSTATE_ENABLED,                                                 TBSTYLE_BUTTON, 0,    0},    {1,           IDM_TWO,  TBSTATE_ENABLED,                                      TBSTYLE_BUTTON, 0,    0},};HWND    AddCustomButtons( HWND hWnd ){     //we have to destroy the old one before expanding     CommandBar_Destroy( hwndCB );      hwndCB = CommandBar_Create(hInst, hWnd, 800);         // Insert the menu band     CommandBar_InsertMenubar(hwndCB, hInst, IDM_MENU, 0);     //add bitmaps for buttons     CommandBar_AddBitmap(hwndCB, hInst, IDB_ONE_TWO, 2, 0, 0);     //Add the buttons     CommandBar_AddButtons(hwndCB, 2, tbCustomButtons);     // Add exit button to command band control.     CommandBar_AddAdornments (hwndCB, 0, 0);     CommandBar_Show(hwndCB, TRUE);     return hwndCB;}

This code adds buttons using system bitmaps

// Command band button initialization structure, std bitmapsTBBUTTON tbCustomButtons[] = {    {STD_UNDO,  IDM_UNDO, TBSTATE_ENABLED,      TBSTYLE_BUTTON, 0,    0},    {STD_REDOW, IDM_REDO, TBSTATE_ENABLED,      TBSTYLE_BUTTON, 0,    0},};HWND    AddStdCmdButtons( HWND hWnd ){    //we have to destroy the old one before expanding    CommandBar_Destroy( hwndCB );     hwndCB = CommandBar_Create(hInst, hWnd, 1);    // Insert the menu band    CommandBar_InsertMenubar(hwndCB, hInst, IDM_MENU, 0);    // Insert buttons.    CommandBar_AddBitmap (hwndCB, HINST_COMMCTRL,                             IDB_STD_SMALL_COLOR, 0, 0, 0);    //Add the buttons    CommandBar_AddButtons(hwndCB, 2, tbStdCmdButtons);    // Add exit button to command band control.    CommandBar_AddAdornments (hwndCB, 0, 0);    CommandBar_Show(hwndCB, TRUE);    return hwndCB;}

This code adds buttons with automatic "radio button" behavior

// Command band button initialization structureTBBUTTON tbRadioButtons[] = {//  BitmapIndex Command  State     Style    UserData  String    {0,         IDM_ONE, TBSTATE_ENABLED,                          TBSTYLE_GROUP | TBSTYLE_CHECKGROUP,                                                  0,    0},    {1,         IDM_TWO, TBSTATE_ENABLED,                                    TBSTYLE_CHECKGROUP,                                                    0,    0},};HWND    AddRadioButtons(HWND hWnd){    //we have to destroy the old one before expanding    CommandBar_Destroy( hwndCB );     hwndCB = CommandBar_Create(hInst, hWnd, 1);         // Insert the menu band    CommandBar_InsertMenubar(hwndCB, hInst, IDM_MENU, 0);    //add bitmaps for buttons    CommandBar_AddBitmap(hwndCB, hInst, IDB_ONE_TWO, 2, 0, 0);    //Add the buttons  the button structs define the button    //radio behaviors    CommandBar_AddButtons(hwndCB, 2, tbRadioButtons);    // Add exit button to command band control.    CommandBar_AddAdornments (hwndCB, 0, 0);    CommandBar_Show(hwndCB, TRUE);    return hwndCB;}

This code adds buttons with "check box" behavior

// Command band button initialization structureTBBUTTON tbCheckButton[] = {//  BitmapIndex Command    State     Style    UserData  String    {0,         IDM_ONE,    TBSTATE_ENABLED,                                      TBSTYLE_CHECK, 0,    0},};//Command band button initialization structure- check box behaviorTBBUTTON tbDropButton[] = {//  BitmapIndex Command  State     Style    UserData  String    {0,         IDM_ONE, TBSTATE_ENABLED,                                     TBSTYLE_DROPDOWN,                                              0,    0},};HWND    AddCheckButton(HWND hWnd){    //we have to destroy the old one before expanding    CommandBar_Destroy( hwndCB );     hwndCB = CommandBar_Create(hInst, hWnd, 1);         // Insert the menu band    CommandBar_InsertMenubar(hwndCB, hInst, IDM_MENU, 0);    //add bitmaps for buttons    CommandBar_AddBitmap(hwndCB, hInst, IDB_ONE_TWO, 2, 0, 0);    // Insert buttons.    CommandBar_AddBitmap (hwndCB, HINST_COMMCTRL,                           IDB_STD_SMALL_COLOR,                          0, 0, 0);    //Add the buttons the flags in the button structs     //specify the check box behaviors    CommandBar_AddButtons(hwndCB, 1, tbCheckButton);    // Add exit button to command band control.    CommandBar_AddAdornments (hwndCB, 0, 0);    CommandBar_Show(hwndCB, TRUE);    return hwndCB;}

Using a little creativity and the basic toolbar buttons demonstrated above, you'll be able to duplicate most of your Win32 application's menu functionality. In the next installment, we'll complete the picture by showing you how to add Combo Buttons and DropDown buttons to the CE command bar.

Evaluating Menu Strategies

With a little foresight, porting menu functionality can be smooth sailing. When examining your Win32 code with an eye to porting to CE, use these tips to spot potential problem areas:

Possible Porting ObstacleWorkarounds
Nested menus and floating menus
  1. Drop some of the menu functionality
  2. Use a dynamically constructed menu bar in place of the nested or floating menu
Long menu captions
  1. Replace caption with a bitmap
  2. Abbreviate
Too many menu choices for screen
  1. Eliminate redundant or unnecessary items
  2. Redesign menu items as dialog
  3. Use resizable command bands

SOURCE CODE: CE02.txt

About the Author

Nancy Nicolaisen is a software engineer who has designed and implemented highly modular Windows CE products that include features such as full remote diagnostics, CE-side data compression, dynamically constructed user interface, automatic screen size detection, entry time data validation.

In addition to writing for Developer.com, she has written several books including Making Win 32 Applications Mobile. She has also written numerous articles on programming technology for national publications including Dr. Dobbs, BYTE Magazine, Microsoft Systems Journal, PC Magazine; Computer Shopper, Windows Sources and Databased Advisor.

# # #





Page 3 of 3



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel