|
 |
 |
 |
 |
Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms
of Use |
Trademarks
Article ID: 125683 - Last Review: July 8, 2005 - Revision: 3.4 SAMPLE: Barsdi.exe Customizes the Toolbar ControlThis article was previously published under Q125683
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.
The following file is available for download from the Microsoft Download Center: Barsdi.exe
(http://download.microsoft.com/download/platformsdk/sample/3/n351/en-us/barsdi.exe)
Release Date: Apr-21-1999
For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:
119591Â
(http://kbalertz.com/Feedback.aspx?kbNumber=119591/EN-US/
)
How to Obtain Microsoft Support Files from Online Services
Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to 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;
}
}
APPLIES TO- Microsoft Platform Software Development Kit-January 2000 Edition, when used with:
- Microsoft Windows 95
- Microsoft Windows 2000 Standard Edition
| kbdownload kbctrl kbfile kbinfo kbsample kbtoolbar KB125683 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate
|
 |
 |
 |
 |
 |
 |
 |
| |