HOWTO: Add a Button Control to a Command Band

ID: Q190982


The information in this article applies to:
  • Microsoft Windows CE version 2.0 for the Handheld PC
  • Microsoft Windows CE version 2.0 for the Palm-size PC


SUMMARY

When you create a command band, you might want to add a button to the command band (for example, similar to the New button in the Calendar or Contacts applications on the Palm-size PC).


MORE INFORMATION

The following function sends a TB_INSERTBUTTON to the command bar to insert a button control:


   HWND WINAPI CommandBar_AddRealButton (HWND hWndCB, HINSTANCE hInstance,
                                         LPWSTR lpButtonText, int iWidth,
                                         UINT dwStyle, WORD idButton,
                                         WORD iButton)
   {
      RECT rect   = {0};
      TBBUTTON tbbutton   = {0};

      HWND hWndButton = CreateWindowEx (0, L"BUTTON", lpButtonText,
                                        WS_VISIBLE|WS_CHILD|dwStyle,
                                        0, 0, 0, 0,
                                        GetParent (hWndCB),
                                        (HMENU) idButton,
                                        hInstance, NULL);
      if (!hWndButton)
         return NULL;

      SetParent (hWndButton, hWndCB);

      tbbutton.iBitmap = iWidth;
      tbbutton.idCommand = 0;
      tbbutton.fsState = TBSTATE_ENABLED;
      tbbutton.fsStyle = TBSTYLE_SEP;
      tbbutton.dwData = (DWORD) hWndButton;
      tbbutton.iString = 0;

      SendMessage (hWndCB, TB_INSERTBUTTON, iButton, (LPARAM) &tbbutton);
      SendMessage (hWndCB, TB_GETITEMRECT, iButton, (LPARAM) &rect);
      MoveWindow (hWndButton, rect.left, rect.top,
                  rect.right - rect.left, rect.bottom - rect.top,
                  FALSE);

      return hWndButton;
   } 

Additional query words:

Keywords : kbGrpUser kbWinCE200 kbComCtrls
Version : WINDOWS:2.0
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: January 10, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.