How To Add a Button Control to a Command Band (190982)



The information in this article applies to:

  • Microsoft Windows CE 2.0 for the Handheld PC
  • Microsoft Windows CE for the Palm-size PC, Versions 2.0

This article was previously published under Q190982

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;
   }
				

Modification Type:MinorLast Reviewed:6/29/2004
Keywords:kbComCtrls kbhowto KB190982