Microsoft KB Archive/125683

From BetaArchive Wiki

SAMPLE: Barsdi.exe Customizes the Toolbar Control

Q125683



The information in this article applies to:


  • Microsoft Win32 Software Development Kit (SDK), on platform(s):
    • Microsoft Windows 95
    • the operating system: Microsoft Windows 2000





SUMMARY

The sample Barsdi.exe demonstrates how to provide customization features for the Toolbar Common Control. The Toolbar Common Control under Windows 95 provides customization features that are useful when the user needs to change the toolbar control's buttons dynamically; for example, the add, delete, and interchange buttons.



MORE INFORMATION

The following file is available for download from the Microsoft Download Center:


Barsdi.exe

Release Date: Apr-21-1999

For additional information about how to download Microsoft Support files, click the article number below to view the article in the Microsoft Knowledge Base:

Q119591 How to Obtain Microsoft Support Files from Online Services

Microsoft used the most current virus detection software available on the date of posting to scan this file for viruses. Once posted, the file is housed on secure servers that prevent any unauthorized changes to the file.

There are two ways the user can customize the toolbar:

  • First, the user can use the Drag Drop Customization process to delete or change the position of buttons on the toolbar. This method does not allow the user to add buttons to the toolbar dynamically.
  • The second method involves displaying the Customize dialog box through which the user can add, remove, and interchange buttons on the toolbar.

To provide customization, the toolbar control must be created with the CCS_ADJUSTABLE style, and the parent of the toolbar control must process a series of TBN_XXXX notifications. The Barsdi.exe sample implements both methods of customization.

Method 1: Drag Drop Customization

This method of toolbar customization allows the user to reposition or delete buttons on the toolbar. The user initiates this operation by holding down the SHIFT key and dragging a button. The toolbar control handles all of the drag operations automatically, including the cursor changes.

To delete a button, the user must release the drag operation outside the toolbar control. The toolbar control sends the TBN_QUERYDELETE message to its parent window. The parent window can return TRUE to allow the button to be deleted and FALSE to prevent the button from being deleted.

If the application wants to do custom dragging, it must process the TBN_BEGINDRAG and TBN_ENDDRAG notifications itself and perform the drag/drop process, which involves more coding.

Method 2: Customization Dialog Box

This method of customization allows users to add buttons to the toolbar dynamically in addition to deleting and rearranging buttons on the toolbar. For example, if the toolbar has N total buttons, and displays only 10 of those buttons initially, the bitmap that was used to create the toolbar should contain all N buttons (where N > 10).

There are two ways in which the toolbar control displays the Customize dialog box. The user can bring up the Customize dialog box by double-clicking the left mouse button on the toolbar control or the application can send the TB_CUSTOMIZE message to the toolbar control.

The Customize dialog box displayed by the toolbar control has two list boxes:

  • The list box on the left contains the list of N-10 buttons that were not displayed on the initial toolbar.
  • The list box on the right has the currently displayed buttons on the toolbar.

The toolbar control provides the add, remove, and other features in the Customize dialog box.

Here is a code sample that shows how the Customization feature is implemented:

Sample Code

   // The initial set of toolbar buttons.

   TBBUTTON tbButton[] =
   {

       {0,   IDM_FILENEW,     TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
       {1,   IDM_FILEOPEN,    TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
       {2,   IDM_FILESAVE,    TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
       {3,   IDM_EDITCUT,     TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
       {0,   0,               TBSTATE_ENABLED, TBSTYLE_SEP,    0, 0},
       {4,   IDM_EDITCOPY,    TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
       {5,   IDM_EDITPASTE,   TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
       {6,   IDM_FILEPRINT,   TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
       {0,   0,               TBSTATE_ENABLED, TBSTYLE_SEP,    0, 0},
       {7,   IDM_ABOUT,       TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},

   };

   // Buttons that can be added at a later stage.

   TBBUTTON tbButtonNew[] =
   {

       { 8,  IDM_ERASE,       TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
       { 9,  IDM_PEN,         TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
       {10,  IDM_SELECT,      TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
       {11,  IDM_BRUSH,       TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
       {12,  IDM_AIRBRUSH,    TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
       {13,  IDM_FILL,        TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
       {14,  IDM_LINE,        TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
       {15,  IDM_EYEDROP,     TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
       {16,  IDM_ZOOM,        TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
       {17,  IDM_RECT,        TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
       {18,  IDM_FRAME,       TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
       {19,  IDM_OVAL,        TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},

   };

   // The bitmap that is used to create the toolbar should have all
   // tbButtonNew + tbButton buttons = 20 in this case.
   // Use tbButtons array to create the initial toolbar control.
   // Once the user starts to customize the toolbar, process the WM_NOTIFY
   // message and the following notifications.
   // The toolbar control sends a WM_NOTIFY message to the parent window
   // during each process of the customization.

   LRESULT OnMsgNotify(HWND hwnd, UINT uMessage, WPARAM wparam,

                       LPARAM lparam)

   {

       LPNMHDR         lpnmhdr;
       lpnmhdr =       (LPNMHDR)lparam;

   // Process the QUERYINSERT And QUERYDELETE notifications
   // to allow the drag/drop operation to succeed.
       if (lpnmhdr->code == TBN_QUERYINSERT)
           return TRUE;
       else if (lpnmhdr->code == TBN_QUERYDELETE)
           return TRUE;
       else if (lpnmhdr->code == TBN_GETBUTTONINFO)
   // The user has brought up the Customize dialog box,
   // so provide the control button information to
   // fill the list box on the left side.
       {
           LPTBNOTIFY lpTbNotify = (LPTBNOTIFY)lparam;
           char  szBuffer [20];
           if (lpTbNotify->iItem < 12) // 20 == the total number of buttons
           {                           // tbButton and tbButtonNew
                                       // Since initially we displayed
                                       // 8 buttons.
                      // Send back information about the rest of
                      // 12 buttons that can be added the toolbar.

               lpTbNotify->tbButton = tbButtonNew[lpTbNotify->iItem];

               LoadString(hInst,
                          NEWBUTTONIDS + lpTbNotify->iItem, // string
                                                           //ID =command ID
                          szBuffer,
                          sizeof(szBuffer));

               lstrcpy (lpTbNotify->pszText, szBuffer);
               lpTbNotify->cchText = sizeof (szBuffer);
               return TRUE;
           }
           else
           return 0;
       }

   } 

Additional query words:

Keywords : kbfile kbsample kbCtrl kbOSWin2000 kbSDKWin32 kbToolbar kbGrpDSUser kbOSWin95
Issue type : kbinfo
Technology : kbWin32SDKSearch kbAudDeveloper kbSDKSearch kbWin32sSearch


Last Reviewed: October 22, 2000
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.