Files
Work/toolbar/SCRAPS.TXT
2024-08-07 09:16:27 -04:00

973 lines
31 KiB
Plaintext
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//====== TOOLBAR CONTROL ======================================================
 
#ifndef NOTOOLBAR
 
#ifdef _WIN32
#define TOOLBARCLASSNAMEW L"ToolbarWindow32"
#define TOOLBARCLASSNAMEA "ToolbarWindow32"
 
#ifdef UNICODE
#define TOOLBARCLASSNAME TOOLBARCLASSNAMEW
#else
#define TOOLBARCLASSNAME TOOLBARCLASSNAMEA
#endif
 
#else
#define TOOLBARCLASSNAME "ToolbarWindow"
#endif
 
typedef struct _TBBUTTON {
    int iBitmap;
    int idCommand;
    BYTE fsState;
    BYTE fsStyle;
#ifdef _WIN32
    BYTE bReserved[2];
#endif
    DWORD dwData;
    int iString;
} TBBUTTON, NEAR* PTBBUTTON, FAR* LPTBBUTTON;
typedef const TBBUTTON FAR* LPCTBBUTTON;
 
 
typedef struct _COLORMAP {
    COLORREF from;
    COLORREF to;
} COLORMAP, FAR* LPCOLORMAP;
 
WINCOMMCTRLAPI HWND WINAPI CreateToolbarEx(HWND hwnd, DWORD ws, UINT wID, int nBitmaps,
                        HINSTANCE hBMInst, UINT wBMID, LPCTBBUTTON lpButtons,
                        int iNumButtons, int dxButton, int dyButton,
                        int dxBitmap, int dyBitmap, UINT uStructSize);
 
WINCOMMCTRLAPI HBITMAP WINAPI CreateMappedBitmap(HINSTANCE hInstance, int idBitmap,
                                  UINT wFlags, LPCOLORMAP lpColorMap,
                                  int iNumMaps);
 
#define CMB_MASKED 0x02
 
#define TBSTATE_CHECKED 0x01
#define TBSTATE_PRESSED 0x02
#define TBSTATE_ENABLED 0x04
#define TBSTATE_HIDDEN 0x08
#define TBSTATE_INDETERMINATE 0x10
#define TBSTATE_WRAP 0x20
#define TBSTATE_ELLIPSES 0x40
 
 
 
#define TB_ENABLEBUTTON (WM_USER + 1)
#define TB_CHECKBUTTON (WM_USER + 2)
#define TB_PRESSBUTTON (WM_USER + 3)
#define TB_HIDEBUTTON (WM_USER + 4)
#define TB_INDETERMINATE (WM_USER + 5)
#define TB_ISBUTTONENABLED (WM_USER + 9)
#define TB_ISBUTTONCHECKED (WM_USER + 10)
#define TB_ISBUTTONPRESSED (WM_USER + 11)
#define TB_ISBUTTONHIDDEN (WM_USER + 12)
#define TB_ISBUTTONINDETERMINATE (WM_USER + 13)
#define TB_SETSTATE (WM_USER + 17)
#define TB_GETSTATE (WM_USER + 18)
#define TB_ADDBITMAP (WM_USER + 19)
 
#ifdef _WIN32
typedef struct tagTBADDBITMAP {
        HINSTANCE hInst;
        UINT nID;
} TBADDBITMAP, *LPTBADDBITMAP;
 
#define HINST_COMMCTRL ((HINSTANCE)-1)
#define IDB_STD_SMALL_COLOR 0
#define IDB_STD_LARGE_COLOR 1
#define IDB_VIEW_SMALL_COLOR 4
#define IDB_VIEW_LARGE_COLOR 5
#define IDB_HIST_SMALL_COLOR 8
#define IDB_HIST_LARGE_COLOR 9
 
// icon indexes for standard bitmap
 
#define STD_CUT 0
#define STD_COPY 1
#define STD_PASTE 2
#define STD_UNDO 3
#define STD_REDOW 4
#define STD_DELETE 5
#define STD_FILENEW 6
#define STD_FILEOPEN 7
#define STD_FILESAVE 8
#define STD_PRINTPRE 9
#define STD_PROPERTIES 10
#define STD_HELP 11
#define STD_FIND 12
#define STD_REPLACE 13
#define STD_PRINT 14
 
// icon indexes for standard view bitmap
 
#define VIEW_LARGEICONS 0
#define VIEW_SMALLICONS 1
#define VIEW_LIST 2
#define VIEW_DETAILS 3
#define VIEW_SORTNAME 4
#define VIEW_SORTSIZE 5
#define VIEW_SORTDATE 6
#define VIEW_SORTTYPE 7
#define VIEW_PARENTFOLDER 8
#define VIEW_NETCONNECT 9
#define VIEW_NETDISCONNECT 10
#define VIEW_NEWFOLDER 11
 
#define HIST_BACK 0
#define HIST_FORWARD 1
#define HIST_FAVORITES 2
#define HIST_ADDTOFAVORITES 3
#define HIST_VIEWTREE 4
 
#endif
 
#define TB_ADDBUTTONS (WM_USER + 20)
#define TB_INSERTBUTTON (WM_USER + 21)
#define TB_DELETEBUTTON (WM_USER + 22)
#define TB_GETBUTTON (WM_USER + 23)
#define TB_BUTTONCOUNT (WM_USER + 24)
#define TB_COMMANDTOINDEX (WM_USER + 25)
 
#ifdef _WIN32
 
typedef struct tagTBSAVEPARAMSA {
    HKEY hkr;
    LPCSTR pszSubKey;
    LPCSTR pszValueName;
} TBSAVEPARAMSA, FAR* LPTBSAVEPARAMSA;
 
typedef struct tagTBSAVEPARAMSW {
    HKEY hkr;
    LPCWSTR pszSubKey;
    LPCWSTR pszValueName;
} TBSAVEPARAMSW, FAR *LPTBSAVEPARAMW;
 
#ifdef UNICODE
#define TBSAVEPARAMS TBSAVEPARAMSW
#define LPTBSAVEPARAMS LPTBSAVEPARAMSW
#else
#define TBSAVEPARAMS TBSAVEPARAMSA
#define LPTBSAVEPARAMS LPTBSAVEPARAMSA
#endif
 
#endif
 
#define TB_SAVERESTOREA (WM_USER + 26)
 
#define TB_SAVERESTOREW (WM_USER + 76)
#define TB_CUSTOMIZE (WM_USER + 27)
#define TB_ADDSTRINGA (WM_USER + 28)
#define TB_ADDSTRINGW (WM_USER + 77)
#define TB_GETITEMRECT (WM_USER + 29)
#define TB_BUTTONSTRUCTSIZE (WM_USER + 30)
#define TB_SETBUTTONSIZE (WM_USER + 31)
#define TB_SETBITMAPSIZE (WM_USER + 32)
#define TB_AUTOSIZE (WM_USER + 33)
#define TB_GETTOOLTIPS (WM_USER + 35)
#define TB_SETTOOLTIPS (WM_USER + 36)
#define TB_SETPARENT (WM_USER + 37)
#define TB_SETROWS (WM_USER + 39)
#define TB_GETROWS (WM_USER + 40)
#define TB_SETCMDID (WM_USER + 42)
#define TB_CHANGEBITMAP (WM_USER + 43)
#define TB_GETBITMAP (WM_USER + 44)
#define TB_GETBUTTONTEXTA (WM_USER + 45)
#define TB_GETBUTTONTEXTW (WM_USER + 75)
#define TB_REPLACEBITMAP (WM_USER + 46)
#define TB_SETINDENT (WM_USER + 47)
#define TB_SETIMAGELIST (WM_USER + 48)
#define TB_GETIMAGELIST (WM_USER + 49)
#define TB_LOADIMAGES (WM_USER + 50)
#define TB_GETRECT (WM_USER + 51) // wParam is the Cmd instead of index
#define TB_SETHOTIMAGELIST (WM_USER + 52)
#define TB_GETHOTIMAGELIST (WM_USER + 53)
#define TB_SETDISABLEDIMAGELIST (WM_USER + 54)
#define TB_GETDISABLEDIMAGELIST (WM_USER + 55)
#define TB_SETSTYLE (WM_USER + 56)
#define TB_GETSTYLE (WM_USER + 57)
#define TB_GETBUTTONSIZE (WM_USER + 58)
#define TB_SETBUTTONWIDTH (WM_USER + 59)
#define TB_SETMAXTEXTROWS (WM_USER + 60)
#define TB_GETTEXTROWS (WM_USER + 61)
#ifdef UNICODE
#define TB_GETBUTTONTEXT TB_GETBUTTONTEXTW
#define TB_SAVERESTORE TB_SAVERESTOREW
#define TB_ADDSTRING TB_ADDSTRINGW
#else
#define TB_GETBUTTONTEXT TB_GETBUTTONTEXTA
#define TB_SAVERESTORE TB_SAVERESTOREA
#define TB_ADDSTRING TB_ADDSTRINGA
#endif
 
typedef struct {
        HINSTANCE hInstOld;
        UINT nIDOld;
        HINSTANCE hInstNew;
        UINT nIDNew;
        int nButtons;
} TBREPLACEBITMAP, *LPTBREPLACEBITMAP;
 
#ifdef _WIN32
 
#define TBBF_LARGE 0x0001
 
#define TB_GETBITMAPFLAGS (WM_USER + 41)
 
#define TBN_GETBUTTONINFOA (TBN_FIRST-0)
#define TBN_GETBUTTONINFOW (TBN_FIRST-20)
#define TBN_BEGINDRAG (TBN_FIRST-1)
#define TBN_ENDDRAG (TBN_FIRST-2)
#define TBN_BEGINADJUST (TBN_FIRST-3)
#define TBN_ENDADJUST (TBN_FIRST-4)
#define TBN_RESET (TBN_FIRST-5)
#define TBN_QUERYINSERT (TBN_FIRST-6)
#define TBN_QUERYDELETE (TBN_FIRST-7)
#define TBN_TOOLBARCHANGE (TBN_FIRST-8)
#define TBN_CUSTHELP (TBN_FIRST-9)
#define TBN_DROPDOWN (TBN_FIRST - 10)
#define TBN_CLOSEUP (TBN_FIRST - 11)
 
#ifdef UNICODE
#define TBN_GETBUTTONINFO TBN_GETBUTTONINFOW
#else
#define TBN_GETBUTTONINFO TBN_GETBUTTONINFOA
#endif
 
typedef struct tagNMTOOLBARA {
    NMHDR hdr;
    int iItem;
    TBBUTTON tbButton;
    int cchText;
    LPSTR pszText;
} NMTOOLBARA, FAR* LPNMTOOLBARA;
 
 
typedef struct tagNMTOOLBARW {
    NMHDR hdr;
    int iItem;
    TBBUTTON tbButton;
    int cchText;
    LPWSTR pszText;
} NMTOOLBARW, FAR* LPNMTOOLBARW;
 
#ifdef UNICODE
#define NMTOOLBAR NMTOOLBARW
#define LPNMTOOLBAR LPNMTOOLBARW
#else
#define NMTOOLBAR NMTOOLBARA
#define LPNMTOOLBAR LPNMTOOLBARA
#endif
 
#define TBNOTIFYA NMTOOLBARA
#define TBNOTIFYW NMTOOLBARW
#define TBNOTIFY NMTOOLBAR
#define LPTBNOTIFY LPNMTOOLBAR
#define LPTBNOTIFYA LPNMTOOLBARA
#define LPTBNOTIFYW LPNMTOOLBARW
 
#endif
 
#endif
Toolbar Styles and Default Behavior
The window procedure for the toolbar automatically positions and sets the size of the toolbar window.
By default, the toolbar appears at the top of its parent window's client area; however, you can place
the toolbar at the bottom of the client area by specifying CCS_BOTTOM.
The only new window style associated with the new toolbar control is TBSTYLE_TOOLTIPS. This new style allows the toolbar to display ToolTips (that neat little box that pops up when you rest the mouse cursor on a toolbar button). The system will send a WM_NOTIFY message to the toolbar whenever it needs to display text in a pop-up. The code example below shows the implementation of the ToolTips feature.
Creating a Toolbar Window
As mentioned above, creating a toolbar is simple: You fill out a button structure, create a large
bitmap containing the buttons, then call the CreateWindowEx function,
specifying the TOOLBARCLASSNAME style. Once the toolbar is created, you need to send messages to
add the buttons and bitmaps to the toolbar. Then, unless there is something special you want to do,
you can just let the system take care of handling the toolbar processing. The following code creates
a toolbar, loads the bitmaps for the toolbar, and adds the buttons to the toolbar.
// Fill out a structure describing the buttons in the toolbar.
TBBUTTON tbButtons[] = {
{ 0, IDM_OPT1, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{ 1, IDM_OPT2, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{ 2, IDM_OPT3, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{ 0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0L, -1},
{ 3, IDM_EXIT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0}
};
// Declare a bitmap structure if working under Win32.
TBADDBITMAP tbBitamps;
// Initialize the members.
.
.
.
tbBitamps.hInst = hInstance; // current instance
tbBitmaps.nID = IDB_TOOLBAR; // ID of the bitmap resource
.
.
.
// Function that creates a Win32 toolbar.
// Parameters:
// HWND hWndParent - Handle to the parent window.
// LONG lNumBitmaps - Number of bitmaps for the toolbar.
// TBADDBITMAP tbBItmaps - Bitmap structure for Win32.
// LONG lNumButtons - Number of buttons on the toolbar.
// TBBUTON tbButtons - Pointer to button structure.
// DWORD dwStyle - Special toolbar window styles. Can be a combination
// of generic common control styles or specific toolbar styles.
// int iToolBarID - ID for the toolbar window.
// Returns:
// Handle to the toolbar window if successful; otherwise NULL.
//
if (hWndToolBar)
{
// Load the bitmaps for the toolbar.
if (SendMessage(hWndToolBar, TB_ADDBITMAP, lNumBitmaps,
(LONG) &tbBitmaps) == -1)
return (NULL);
// Add the buttons to the toolbar.
SendMessage(hWndToolBar, TB_ADDBUTTONS, lNumButtons, (LONG) &tbButtons);
// The toolbar was created with the buttons successfully.
// Return the handle to the toolbar.
return (hWndToolBar);
}
// There was an error creating the toolbar; return NULL.
return NULL;
}
Another method of creating a toolbar is to call the CreateToolBarEx function. This function performs the same actions that I outlined above in MyCreateToolBar. The CreateToolBarEx function takes the following parameters:
•HWND hwnd: Handle to the parent window for the toolbar.•DWORD ws: The window styles for the toolbar.•WORD wID: The identifier for the toolbar.•int nBitmaps: The number of images contained in the bitmap specified by hBMInst and wBMID.•HINSTANCE hBMInst: The module instance with the executable file that contains the bitmap resource.•WORD wBMID: The resource identifier for the bitmap resource. If hBMInst is NULL, this must be a valid bitmap handle.•LPCTTBBUTTON lpButtons: The address of the TBBUTTON structure.•int iNumButtons: The number of buttons to add to the toolbar.•int dxButton, dyButton: The width and height, in pixels, of the buttons.•int dxBitmap, dyBitmap: The width and height, in pixels, of the bitmaps.•UINT uStructSize: The size of the TBBUTTON structure.
You can add ToolTips support to your toolbar by specifying the TBSTYLE_TOOLTIPS style and creating a STRINGTABLE that contains the text to display in your .RC file. Once you have done this, you process the WM_NOTIFY message that is sent to the parent window procedure of the toolbar, as shown in the code below.
// This code goes in your .RC file.
STRINGTABLE
BEGIN
IDM_OPT1, "Option 1"
IDM_OPT2, "Option 2"
IDM_OPT3, "Option 3"
IDM_EXIT, "Exit Tool bar Sample"
END
// This code goes in your .C file.
TOOLINFO tbToolInfo;
// Trap the WM_NOTIFY message.
case WM_NOTIFY:
lpToolTipText = (LPTOOLTIPTEXT)lParam;
if (lpToolTipText->hdr.code == TTN_NEEDTEXT)
{
// If the system needs text, load it from the resource.
LoadString (hInst,
lpToolTipText->hdr.idFrom, // string ID == cmd ID
szBuf,
sizeof(szBuf));
// Point the structure to the string.
lpToolTipText->lpszText = szBuf;
}
break;
To see how the code above behaves, click to open the Toolbar project files and run TOOLBAR.EXE.
Warning: The Toolbar executable file was built and tested using the Windows 95 Preliminary Development Kit. The executable will run only on Windows 95; it will not run under Windows 3.1 or Windows NT 3.5. If you have Windows 95 installed on your computer but you have problems running this sample, copy the project files to your system, rebuild the project, and run the executable.
Toolbar Structures
This section describes the new structures that you can use in Win32 to create and manipulate toolbars and their buttons. Each button that you add to a toolbar can have one of the styles listed in the table below. These button styles can be used in combination and are included in the TBBUTTON structure described below.
Table 2. Toolbar Button Styles
Style
Use
TBSTYLE_BUTTON
Creates a standard button.
TBSTYLE_CHECK
Creates a button that stays pressed until released.
TBSTYLE_CHECKGROUP
Creates a checked button that stays pressed until released or until another button in the group is pressed.
TBSTYLE_GROUP
Creates a checked button that stays pressed until another button in the group is pressed.
TBSTYLE_SEP
Creates a separator, which provides a small gap between button groups.
Once you specify your toolbar and its buttons, you may need to query the toolbar for
information about the current state of a button. The current state is kept in a TBBUTTON
structure, as described below. If you need to determine the state of a button dynamically,
you can send the TB_GETSTATE message to the toolbar.
Table 3. Toolbar Button States
State
Meaning
TBSTATE_CHECKED
The button is checked.
TBSTATE_ENABLED
The button is enabled.
TBSTATE_HIDDEN
The button is hidden.
TBSTATE_INDETERMINATE
The button is indeterminate.
TBSTATE_PRESSED
The button is pressed.
TBBUTTON
typedef struct tagTBBUTTON {
int iBitmap; \\ index of the bitmap image of the button
int idCommand; \\ command identifier of the button
BYTE fsState; \\ button state flags, as listed in Table 3
BYTE fsStyle; \\ button style, as listed in Table 2
DWORD dwData; \\ application-defined data
int iString; \\ index of the help text string for the button
} TBBUTTON;
The TBBUTTON structure contains information about a button in a toolbar. TBBUTTON includes the following members:
•int iBitmap: Zero-based index that identifies the location of the button image in the bitmap.•int idCommand: Command identifier associated with the button. This identifier is used in a WM_COMMAND message when the button is pressed. This member must be zero if the fsStyle member is TBSTYLE_SEP.•BYTE fsState: Button state flags. This can be a combination of the values listed in Table 3.•BYTE fsStyle: Button style flags. This can be a combination of the values listed in Table 2.•DWORD dwData: Application-defined value.•int iString: Index of the help text string in the string list for the button.
ADJUSTINFO
typedef struct tagADJUSTINFO {
TBBUTTON tbButton; \\ structure containing button information
char szDescription[1]; \\ TBD
};
The ADJUSTINFO structure contains information about a button in a toolbar that is being
customized by the user. The structure includes the following members:
•TBBUTTON tbButton: A structure that contains information about a button.•char szDescription:
The use of this member has not been determined yet.
TBADDBITMAP
typedef struct tagTBADDBITMAP {
HINSTANCE hInst; \\ handle to the instance containing the bitmaps
UINT nID; \\ resource identifier for the bitmap
} TBADDBITMAP;
The TBADDBITMAP structure contains information about the bitmaps to add to a toolbar. It is used when writing a Win32 application. TBADDBITMAP includes the following members:
•HINSTANCE hInst: Handle to the instance that contains the bitmaps.•UINT nID: Resource identifier for the bitmap.
Toolbar Messages
The system and applications send messages to toolbars, just as they send messages to any other window. This section lists the messages that can be sent to toolbar controls and the values for the wParam and lParam for each message.
TB_ADDBITMAP
wParam = nButtons; \\ number of buttons in the bitmap
lParam = (LPTBADDBITMAP)lptbab; \\ handle of the bitmap
Description: The TB_ADDBITMAP message adds a new bitmap to the list of bitmaps available for a toolbar. This message is for non-Win32 applications only.
Parameters: wParam represents the number of buttons in the bitmap. lParam is a pointer to the TBADDBITMAP structure.
Return value: The low-order word contains the index of the first button bitmap. The high-order word is not used if the call is successful; otherwise, the low-order word is 1.
TB_ADDBUTTONS
wParam = nButtons; \\ number of buttons
lParam = (LPTBBUTTON)lpButtons; \\ address of array of button structures
Description: The TB_ADDBUTTONS message adds one or more buttons to a toolbar.
Parameters: wParam represents the number of buttons to add to the toolbar. lParam is the address of an array of TBBUTTON structures containing information about the buttons to add. The array must contain the same number of elements as buttons specified by wParam.
Return value: TRUE if successful; FALSE otherwise.
TB_ADDSTRING
wParam = (HINSTANCE)hInst; \\ module instance containing the string
lParam = (MAKELONG)(idString, 0); \\ string identifier or string buffer
Description: The TB_ADDSTRING message adds a new string to the list of strings available for a toolbar.
Parameters: wParam is the handle of the module instance with an executable file that contains the string resource. This parameter is zero if lParam points to one or more strings. lParam is the resource identifier for the string resource or the address of a buffer that contains one or more null-terminated strings to add to the list, depending on the value of wParam. The last string must be terminated with two NULL characters.
Return value: The index of the first new string if successful; otherwise 1.
TB_AUTOSIZE
wParam = 0; \\ not used
lParam = 0; \\ not used
Description: The TB_AUTOSIZE message causes a toolbar to be resized. An application sends this message whenever it does something (sets the button or bitmap size or adds strings) to change the size of a toolbar.
Parameters: wParam and lParam are not used.
Return value: None.
TB_BUTTONCOUNT
wParam = 0; \\ not used
lParam = 0; \\ not used
Description: The TB_BUTTONCOUNT message gets a count of the buttons currently in the toolbar.
Parameters: wParam and lParam are not used.
Return value: The number of buttons in the toolbar.
TB_BUTTONSTRUCTSIZE
wParam = cb; \\ size of the TBBUTTON structure in bytes
lParam = 0; \\ not used
Description: The TB_BUTTONSTRUCTSIZE specifies the size of the TBBUTTON structure. The system uses this size to determine the version of COMMCTRL.DLL that is being used. If an application uses CreateWindow to create the toolbar, it must send this message before adding any buttons to the toolbar. The CreateToolBarEx function automatically sends this message, and the size of the TBBUTTON structure is a parameter to the CreateToolbarEx function.
Parameters: wParam is the size, in bytes, of the TBBUTTON structure. lParam is not used.
Return value: None.
TB_CHECKBUTTON
wParam = idButton; \\ command identifier of the button to check
lParam = MAKELONG(fCheck, 0); \\ Check flag - TRUE to add, FALSE to remove
Description: The TB_CHECKBUTTON message checks or unchecks a given button. When a button has been checked, it appears pressed.
Parameters: wParam is the command identifier of the button to check. If lParam is TRUE, the check is added; if lParam is FALSE, the check is removed.
Return value: TRUE if successful; FALSE otherwise.
TB_COMMANDTOINDEX
wParam = idButton; \\ command identifier of the button
lParam = 0; \\ not used
Description: The TB_COMMANDTOINDEX message gets the zero-based index for the button associated with the specified command identifier.
Parameters: wParam is the command identifier associated with the button. lParam is not used.
Return value: The zero-based index for the button.
TB_CUSTOMIZE
wParam = 0; \\ not used
lParam = 0; \\ not used
Description: The TB_CUSTOMIZE message displays the Customize Toolbar dialog box.
Parameters: wParam and lParam are not used.
Return value: None.
TB_DELETEBUTTON
wParam = iButton; \\ zero-based index of the button to delete
lParam = 0; \\ not used
Description: The TB_DELETEBUTTON message deletes a button from the toolbar.
Parameters: wParam is the zero-based index of the button to delete. lParam is not used.
Return value: TRUE if successful; FALSE otherwise.
TB_ENABLEBUTTON
wParam = idButton; \\ command identifier of the button
lParam = MAKELONG(fEnable, 0); \\ flag - TRUE to enable, FALSE to disable
Description: The TB_ENABLEBUTTON message enables or disables the specified button. When a button has been enabled, it can be pressed and checked.
Parameters: wParam is the command identifier of the button to enable or disable. If lParam is TRUE, the button is enabled; if lParam is FALSE, the button is disabled.
Return value: TRUE if successful; FALSE otherwise.
TB_GETBUTTON
wParam = iButton; \\ zero-based index of the button to get
lParam = (LPTBBUTTON)lpButton; \\ buffer that receives the button information
Description: The TB_GETBUTTON message retrieves information about the given button.
Parameters: wParam is the zero-based index of the button for which to get information. lParam is the address of the TBBUTTON structure that receives the button information.
Return value: TRUE if successful; FALSE otherwise.
TB_GETITEMRECT
wParam = iButton; \\ zero-based index of the button
lParam = (LPRECT)lprc; \\ array that receives the rectangle values
Description: The TB_GETITEMRECT message gets the bounding rectangle of a button in a toolbar. This message does not get the bounding rectangle for buttons whose state is set to TBSTATE_HIDDEN.
Parameters: wParam is the zero-based index of the button for which to get information. lParam is the address of a RECT structure that receives the coordinates of the bounding rectangle.
Return value: TRUE if successful; FALSE otherwise.
TB_GETSTATE
wParam = idButton; \\ command identifier of the button
lParam = 0; \\ not used
Description: The TB_GETSTATE message gets information about the state of the button, such as whether it is enabled, pressed, or checked.
Parameters: wParam is the command identifier of the button for which to get information. lParam is not used.
Return value: If the call is successful, the message returns the button state information as listed in Table 3. If the call is not successful, the message returns 1.
TB_HIDEBUTTON
wParam = idButton; \\ command identifier of the button
lParam = MAKELONG(fShow, 0); \\ TRUE to show and FALSE to hide
Description: The TB_HIDEBUTTON message hides or shows the specified button.
Parameters: wParam is the command identifier of the button to hide or show. If lParam is TRUE, the button is hidden; if lParam is FALSE, the button is shown.
Return value: TRUE if successful; FALSE otherwise.
TB_INDETERMINATE
wParam = idButton; \\ command identifier of the button
lParam = MAKELONG(fIndeterminate, 0); \\ TRUE to set and FALSE to clear
Description: The TB_INDETERMINATE message sets or clears the indeterminate state of the specified button.
Parameters: wParam is the command identifier of the button whose indeterminate state is to be set or cleared. If lParam is TRUE, the indeterminate state is set; if lParam is FALSE, the indeterminate state is cleared.
Return value: TRUE if successful; FALSE otherwise.
TB_INSERTBUTTON
wParam = iButton; \\ zero-based index of the button
lParam = (LPTBBUTTON)lpButton; \\ button information structure
Description: The TB_INSERTBUTTON message inserts a button in the toolbar.
Parameters: wParam is the zero-based index of a button. The TB_INSERTBUTTON message inserts the new button in front of the button identified by wParam. lParam is the address of a TBBUTTON structure containing information about the button to insert.
Return value: TRUE if successful; FALSE otherwise.
TB_ISBUTTONCHECKED, TB_ISBUTTONENABLED, TB_ISBUTTONHIDDEN, TB_ISBUTTONINDETERMINATE, TB_ISBUTTONPRESSED
wParam = idButton; \\ command identifier of the button
lParam = 0; \\ not used
Description: These messages determine whether the given button is checked, enabled, hidden, indeterminate, or pressed.
Parameters: wParam is the command identifier of the button. lParam is not used.
Return value: Nonzero if the button if TRUE; otherwise, returns zero.
TB_PRESSBUTTON
wParam = idButton; \\ command identifier of the button
lParam = MAKELONG(fPress, 0); \\ TRUE to press and FALSE to release
Description: The TB_PRESSBUTTON message presses or releases the given button.
Parameters: wParam is the command identifier of the button to press or release. If lParam is TRUE, the button is pressed; if lParam is FALSE, the button is released.
Return value: TRUE if successful; FALSE otherwise.
TB_SAVERESTORE
wParam = (BOOL)fSave; \\ TRUE to save and FALSE to restore
lParam = (LPSTR)lpszSectionFile; \\ strings used to save the information
Description: The TB_SAVERESTORE message saves or restores the state of the toolbar.
Parameters: If wParam is TRUE, the information is saved; otherwise, it is restored. lParam is the address of two consecutive null-terminated strings. The first string specifies the name of a section in an initialization file. The second string specifies the name of the initialization file. If the second string is empty, the message uses the WIN.INI file by default.
Return value: None.
TB_SETBITMAPSIZE
wParam = 0; \\ not used
lParam = MAKELONG(dxBitmap, dyBitmap); \\ width and height to set
Description: The TB_SETBITMAPSIZE message sets the size of the bitmapped images to be added to a toolbar. The size can be set only before adding any bitmaps to the toolbar. If an application does not explicitly set the bitmap size, the size defaults to 16-by-15 pixels.
Parameters: wParam is not used. lParam is the width and height, in pixels, of the bitmapped images.
Return value: TRUE if successful; FALSE otherwise.
TB_SETBUTTONSIZE
wParam = 0; \\ not used
lParam = MAKELONG(dxButton, dyButton); \\ width and height to set
Description: The TB_SETBUTTONSIZE message sets the size of the buttons to be added to a toolbar. You can set the button size only before you add any buttons to the toolbar. If an application does not explicitly set the button size, the size defaults to 24-by-22 pixels.
Parameters: wParam is not used. lParam is the width and height, in pixels, of the buttons.
Return value: TRUE if successful; FALSE otherwise.
TB_SETSTATE
wParam = idButton; \\ command identifier of the button
lParam = MAKELONG(fState,0); \\ state to set as listed in Table 3
Description: The TB_SETSTATE message sets the state for the given button.
Parameters: wParam is the command identifier of the button. lParam consists of the state flags, as listed in Table 3.
Return value: TRUE if successful; FALSE otherwise.
Toolbar Notification Messages
This section lists the notification messages that Windows sends to toolbar windows. The parent window of the toolbar receives these messages via a WM_COMMAND message. Unless otherwise noted, Windows ignores the return value from these messages. In all cases, the wParam contains the identifier for the toolbar.
Table 4. Toolbar Notification Messages
Message
Description
lParam
TBN_ADJUSTINFO
Sent when the user is customizing a toolbar. Returns a handle to a global memory object containing an ADJUSTINFO structure.
Button index
TBN_BEGINADJUST
Sent when the user begins customizing a toolbar.
0—not used
TBN_BEGINDRAG
Sent when the user begins dragging a button in a toolbar.
Button command ID
TBN_CUSTHELP
Sent when the user chooses the Help button in the Customize Toolbar dialog box.
Customize Toolbar dialog box handle
TBN_ENDADJUST
Sent when the user finishes customizing a toolbar.
0—not used
TBN_ENDDRAG
Sent when the user stops dragging a button in a toolbar.
Button command ID
TBN_QUERYDELETE
Sent when the user attempts to delete a button while customizing a toolbar. Returns TRUE to delete the button, or FALSE to prevent the button from being deleted.
Button index
TBN_QUERYINSERT
Sent when the user attempts to insert a button while customizing a toolbar. Returns TRUE to insert the new button in front of the given button, or FALSE to prevent the button from being inserted.
Button index
TBN_RESET
Sent when the user resets a customized toolbar.
0—not used
TBN_TOOLBARCHANGE
Sent when the user has customized a toolbar.
Toolbar handle
Summary
Status bars and toolbars are very handy controls that are familiar to users and easy to implement. These controls are built into Windows 95, so you will no longer have to worry about whether your toolbar or status bar conforms to the way the operating system or other companies implement these controls. If you are planning to add status bars or toolbars to your existing application, I suggest that you give these new common controls a try. Adding value to your application can hardly get any easier th