• Welcome to Jose's Read Only Forum 2023.
 

Toolbar Controls

Started by José Roca, December 26, 2006, 05:08:11 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca

 
What is a Toolbar?

"A toolbar is a control window that contains one or more buttons. Each button, when clicked by a user, sends a command message to the parent window. Typically, the buttons in a toolbar correspond to items in the application's menu, providing an additional and more direct way for the user to access an application's commands."
Microsoft MSDN




The window class name for a toolbar control is $TOOLBARCLASSNAME, which is defined as "ToolbarWindow32" in Commctrl.inc.




The toolbar is part of the common control DLL (COMCTL32.DLL) which contains resources such as bitmaps and strings. Six of those bitmap resources are used by the toolbar. Also, a programmer can access these bitmaps directly using EnumResourceNames and  LoadBitmap/LoadImage, or just LoadBitmap/LoadImage with the appropriate resource ID.
         
The bitmaps are organized as follows:

 
       Bitmaps               |     ID in CommCtrl.inc    |  Resource ID in COMCTL32.DLL
------------------------------|---------------------------|-----------------------------
"standard" small color images | IDB_STD_SMALL_COLOR  (0)  |             0
"standard" large color images | IDB_STD_LARGE_COLOR  (1)  |             1
"view" small color images     | IDB_VIEW_SMALL_COLOR (4)  |             2
"view" large color images     | IDB_VIEW_LARGE_COLOR (5)  |             3
"history" small color images  | IDB_HIST_SMALL_COLOR (8)  |             4
"history" large color images  | IDB_HIST_LARGE_COLOR (9)  |             5
 
The resource IDs are useful to apps such as visual designers.  IDB_XXX are the identifiers used when working with the toolbar via the toolbar messages(TB_XXX).
 
Use TB_SETIMAGELIST when working with the toolbar.  TB_ADDBITMAP is too limited. Its color depth is limited to 8 bpp and it cannot use icons.


Dominic Mitchell: Toolbars 101

José Roca

#1
 
A simple toolbar using the standard small color images.


'#########################################################################################
' Toolbar Control example
'#########################################################################################

#DIM ALL
#COMPILE EXE
#INCLUDE ONCE "ToolbarCtrl.inc"

GLOBAL   ghInstance              AS DWORD    ' handle of the application instance

'--------------------------- [ Command Identifiers ] ---------------------------

%IDM_CUT                                     = 28000
%IDM_COPY                                    = 28001
%IDM_PASTE                                   = 28002
%IDM_UNDO                                    = 28003
%IDM_REDOW                                   = 28004
%IDM_DELETE                                  = 28005
%IDM_FILENEW                                 = 28006
%IDM_FILEOPEN                                = 28007
%IDM_FILESAVE                                = 28008
%IDM_PRINTPRE                                = 28009
%IDM_PROPERTIES                              = 28010
%IDM_HELP                                    = 28011
%IDM_FIND                                    = 28012
%IDM_REPLACE                                 = 28013
%IDM_PRINT                                   = 28014

'--------------------------- [ Control Identifiers ] ---------------------------

%IDC_TOOLBAR                                 = 101


'-------------------------------------------------------------------------------
'
' PROCEDURE: WinMain
' PURPOSE:   Program entry point, calls initialization function, processes
'            message loop.
'
'-------------------------------------------------------------------------------

FUNCTION WinMain _
   ( _
   BYVAL hInstance      AS DWORD, _       ' handle of current instance
   BYVAL hPrevInstance  AS DWORD, _       ' handle of previous instance(not used in Win32)
   BYVAL pszCmdLine     AS ASCIIZ PTR, _  ' address of command line
   BYVAL nCmdShow       AS LONG _         ' show state of window
   ) AS LONG

   LOCAL szClassName       AS ASCIIZ * %MAX_PATH         ' class name
   LOCAL twcx              AS WNDCLASSEX                 ' class information
   LOCAL tmsg              AS tagMsg                     ' message information
   LOCAL ticc              AS INIT_COMMON_CONTROLSEX     ' specifies common control classes to register
   LOCAL hWnd              AS DWORD                      ' handle of main window

   ' Save the handle of the application instance
   ghInstance = hInstance

   ' Register the Form1 window
   szClassName        = "EX_TOOLBAR_01"
   twcx.cbSize        = SIZEOF(twcx)                              ' size of WNDCLASSEX structure
   twcx.style         = %CS_DBLCLKS                               ' class styles
   twcx.lpfnWndProc   = CODEPTR(Form1_WndProc)                    ' address of window procedure used by class
   twcx.cbClsExtra    = 0                                         ' extra class bytes
   twcx.cbWndExtra    = 0                                         ' extra window bytes
   twcx.hInstance     = ghInstance                                ' instance of the process that is registering the window
   twcx.hIcon         = LoadIcon(%NULL, BYVAL %IDI_APPLICATION)   ' handle of class icon
   twcx.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)       ' handle of class cursor
   twcx.hbrBackground = %COLOR_BTNFACE + 1                        ' brush used to fill background of window's client area
   twcx.lpszMenuName  = %NULL                                     ' resource identifier of the class menu
   twcx.lpszClassName = VARPTR(szClassName)                       ' class name
   twcx.hIconSm       = %NULL                                     ' handle of small icon shown in caption/system Taskbar
   IF ISFALSE RegisterClassEx(twcx) THEN
      FUNCTION = %TRUE
      EXIT FUNCTION
   END IF

   ' Load the common controls library and
   ' specify the classes to register.
   ticc.dwSize = SIZEOF(ticc)
   ticc.dwICC  = %ICC_BAR_CLASSES
   InitCommonControlsEx ticc

   ' Create the Form1 window
   hWnd = CreateWindowEx(%WS_EX_WINDOWEDGE, _                                          ' extended styles
                         szClassName, _                                                ' class name
                         "Toolbar Demo", _                                             ' caption
                         %WS_OVERLAPPEDWINDOW OR %WS_VISIBLE, _                        ' window styles
                         %CW_USEDEFAULT, 0, _                                          ' left, top
                         %CW_USEDEFAULT, 0, _                                          ' width, height
                         %NULL, %NULL, _                                               ' handle of owner, menu handle
                         ghInstance, BYVAL %NULL)                                      ' handle of instance, creation parameters

   ' If window could not be created, return "failure"
   IF ISFALSE hWnd THEN
      FUNCTION = %FALSE
      EXIT FUNCTION
   END IF

   ' Make the window visible; update its client area
   ShowWindow hWnd, nCmdShow
   UpdateWindow hWnd

   ' Main message loop of program.
   ' Acquire and dispatch messages until a WM_QUIT message is received.
   WHILE ISTRUE GetMessage(tmsg, BYVAL %NULL, 0, 0)
      IF ISFALSE IsDialogMessage(hWnd, tmsg) THEN
         TranslateMessage tmsg
         DispatchMessage tmsg
      END IF
   WEND

   FUNCTION = tmsg.wParam

END FUNCTION

'-------------------------------------------------------------------------------
'
' PROCEDURE: Form1_WndProc
' PURPOSE:   Processes messages for the Form1 window.
'
'-------------------------------------------------------------------------------

FUNCTION Form1_WndProc _
   ( _
   BYVAL hWnd     AS DWORD, _ ' window handle
   BYVAL uMsg     AS DWORD, _ ' type of message
   BYVAL wParam   AS DWORD, _ ' first message parameter
   BYVAL lParam   AS LONG _   ' second message parameter
   ) EXPORT AS LONG

   LOCAL sBtnText       AS STRING               ' toolbar button caption
   LOCAL ttbb           AS TBBUTTON             ' specifies or receives the attributes of a toolbar button
   LOCAL ttbab          AS TBADDBITMAP          ' specifies the images to add to a toolbar
   LOCAL ptnmhdr        AS NMHDR PTR            ' information about a notification message
   LOCAL ptttdi         AS NMTTDISPINFO PTR     ' tooltip notification message information
   LOCAL pttbb          AS TBBUTTON PTR         ' address of array of toolbar button info
   LOCAL hWndChild      AS DWORD                ' handle of child window
   LOCAL hFont          AS DWORD                ' handle of font used by form
   LOCAL lMsgResult     AS LONG                 ' value returned to message after message is processed

   SELECT CASE uMsg

      CASE %WM_COMMAND

         ' -------------------------------------------------------
         ' Messages from the Toolbar are handled here.
         ' ------------------------------------------------------

         SELECT CASE LOWRD(wParam)

            CASE %IDCANCEL
               IF HIWRD(wParam) = %BN_CLICKED THEN
                  SendMessage hWnd, %WM_CLOSE, wParam, lParam
                  FUNCTION = %FALSE
                  EXIT FUNCTION
               END IF

            CASE %IDM_CUT
               MSGBOX "Cut button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_COPY
               MSGBOX "Copy button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_PASTE
               MSGBOX "Paste button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_UNDO
               MSGBOX "Undo button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_REDOW
               MSGBOX "Redo button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_DELETE
               MSGBOX "Delete button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FILENEW
               MSGBOX "File New button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FILEOPEN
               MSGBOX "File Open button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FILESAVE
               MSGBOX "File Save button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_PRINTPRE
               MSGBOX "Print Preview button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_PROPERTIES
               MSGBOX "Properties button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_HELP
               MSGBOX "Help button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FIND
               MSGBOX "Find button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_REPLACE
               MSGBOX "Replace button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_PRINT
               MSGBOX "Print button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

         END SELECT

      CASE %WM_SYSCOLORCHANGE
         ' Forward this message to common controls so that they will
         ' be properly updated when the user changes the color settings.
         SendMessage GetDlgItem(hWnd, %IDC_TOOLBAR), %WM_SYSCOLORCHANGE, wParam, lParam

      CASE %WM_DESTROY
         PostQuitMessage 0
         FUNCTION = %FALSE
         EXIT FUNCTION

      CASE %WM_SIZE
         IF wParam <> %SIZE_MINIMIZED THEN
            ' Update the size and position of the Toolbar control
            SendMessage GetDlgItem(hWnd, %IDC_TOOLBAR), %TB_AUTOSIZE, 0, 0
         END IF
         FUNCTION = %FALSE
         EXIT FUNCTION

      CASE %WM_CREATE
         ' Create font used by container
         hFont = GetStockObject(%DEFAULT_GUI_FONT)

         ' Create the Toolbar1 toolbar control
         hWndChild = CreateWindowEx(%NULL, _                                              ' extended styles
                                    "ToolbarWindow32", _                                  ' class name
                                    "", _                                                 ' caption
                                    %WS_CHILD OR %WS_VISIBLE OR _                         ' window styles
                                    %CCS_TOP , _                                           ' class styles
                                    0, 0, _                                               ' left, top
                                    345, 116, _                                           ' width, height
                                    hWnd, %IDC_TOOLBAR, _                                 ' handle of parent, control ID
                                    ghInstance, BYVAL %NULL)                              ' handle of instance, creation parameters
         SendMessage hWndChild, %WM_SETFONT, hFont, %TRUE

         ' Allocate memory for the button info array
         pttbb = HeapAlloc(GetProcessHeap(), %HEAP_ZERO_MEMORY, 15 * SIZEOF(ttbb))
         IF ISTRUE pttbb THEN
            ' Send the TB_BUTTONSTRUCTSIZE message, for backward compatibility
            SendMessage hWndChild, %TB_BUTTONSTRUCTSIZE, SIZEOF(ttbb), 0
            ' Add bitmaps to the internal image list
            ttbab.hInst = %HINST_COMMCTRL
            ttbab.nId   = %IDB_STD_SMALL_COLOR
            SendMessage hWndChild, %TB_ADDBITMAP, 15, BYVAL VARPTR(ttbab)
            ' Add buttons to the toolbar
            @pttbb[0].iBitmap    = %STD_CUT
            @pttbb[0].idCommand  = %IDM_CUT
            @pttbb[0].fsState    = %TBSTATE_ENABLED
            @pttbb[0].fsStyle    = %BTNS_BUTTON
            @pttbb[0].dwData     = 0
            @pttbb[0].iString    = -1

            @pttbb[1].iBitmap    = %STD_COPY
            @pttbb[1].idCommand  = %IDM_COPY
            @pttbb[1].fsState    = %TBSTATE_ENABLED
            @pttbb[1].fsStyle    = %BTNS_BUTTON
            @pttbb[1].dwData     = 0
            @pttbb[1].iString    = -1

            @pttbb[2].iBitmap    = %STD_PASTE
            @pttbb[2].idCommand  = %IDM_PASTE
            @pttbb[2].fsState    = %TBSTATE_ENABLED
            @pttbb[2].fsStyle    = %BTNS_BUTTON
            @pttbb[2].dwData     = 0
            @pttbb[2].iString    = -1

            @pttbb[3].iBitmap    = %STD_UNDO
            @pttbb[3].idCommand  = %IDM_UNDO
            @pttbb[3].fsState    = %TBSTATE_ENABLED
            @pttbb[3].fsStyle    = %BTNS_BUTTON
            @pttbb[3].dwData     = 0
            @pttbb[3].iString    = -1

            @pttbb[4].iBitmap    = %STD_REDOW
            @pttbb[4].idCommand  = %IDM_REDOW
            @pttbb[4].fsState    = %TBSTATE_ENABLED
            @pttbb[4].fsStyle    = %BTNS_BUTTON
            @pttbb[4].dwData     = 0
            @pttbb[4].iString    = -1

            @pttbb[5].iBitmap    = %STD_DELETE
            @pttbb[5].idCommand  = %IDM_DELETE
            @pttbb[5].fsState    = %TBSTATE_ENABLED
            @pttbb[5].fsStyle    = %BTNS_BUTTON
            @pttbb[5].dwData     = 0
            @pttbb[5].iString    = -1

            @pttbb[6].iBitmap    = %STD_FILENEW
            @pttbb[6].idCommand  = %IDM_FILENEW
            @pttbb[6].fsState    = %TBSTATE_ENABLED
            @pttbb[6].fsStyle    = %BTNS_BUTTON
            @pttbb[6].dwData     = 0
            @pttbb[6].iString    = -1

            @pttbb[7].iBitmap    = %STD_FILEOPEN
            @pttbb[7].idCommand  = %IDM_FILEOPEN
            @pttbb[7].fsState    = %TBSTATE_ENABLED
            @pttbb[7].fsStyle    = %BTNS_BUTTON
            @pttbb[7].dwData     = 0
            @pttbb[7].iString    = -1

            @pttbb[8].iBitmap    = %STD_FILESAVE
            @pttbb[8].idCommand  = %IDM_FILESAVE
            @pttbb[8].fsState    = %TBSTATE_ENABLED
            @pttbb[8].fsStyle    = %BTNS_BUTTON
            @pttbb[8].dwData     = 0
            @pttbb[8].iString    = -1

            @pttbb[9].iBitmap    = %STD_PRINTPRE
            @pttbb[9].idCommand  = %IDM_PRINTPRE
            @pttbb[9].fsState    = %TBSTATE_ENABLED
            @pttbb[9].fsStyle    = %BTNS_BUTTON
            @pttbb[9].dwData     = 0
            @pttbb[9].iString    = -1

            @pttbb[10].iBitmap   = %STD_PROPERTIES
            @pttbb[10].idCommand = %IDM_PROPERTIES
            @pttbb[10].fsState   = %TBSTATE_ENABLED
            @pttbb[10].fsStyle   = %BTNS_BUTTON
            @pttbb[10].dwData    = 0
            @pttbb[10].iString   = -1

            @pttbb[11].iBitmap   = %STD_HELP
            @pttbb[11].idCommand = %IDM_HELP
            @pttbb[11].fsState   = %TBSTATE_ENABLED
            @pttbb[11].fsStyle   = %BTNS_BUTTON
            @pttbb[11].dwData    = 0
            @pttbb[11].iString   = -1

            @pttbb[12].iBitmap   = %STD_FIND
            @pttbb[12].idCommand = %IDM_FIND
            @pttbb[12].fsState   = %TBSTATE_ENABLED
            @pttbb[12].fsStyle   = %BTNS_BUTTON
            @pttbb[12].dwData    = 0
            @pttbb[12].iString   = -1

            @pttbb[13].iBitmap   = %STD_REPLACE
            @pttbb[13].idCommand = %IDM_REPLACE
            @pttbb[13].fsState   = %TBSTATE_ENABLED
            @pttbb[13].fsStyle   = %BTNS_BUTTON
            @pttbb[13].dwData    = 0
            @pttbb[13].iString   = -1

            @pttbb[14].iBitmap   = %STD_PRINT
            @pttbb[14].idCommand = %IDM_PRINT
            @pttbb[14].fsState   = %TBSTATE_ENABLED
            @pttbb[14].fsStyle   = %BTNS_BUTTON
            @pttbb[14].dwData    = 0
            @pttbb[14].iString   = -1
            SendMessage hWndChild, %TB_ADDBUTTONS, 15, BYVAL pttbb
            ' Free memory that was allocated for the button info
            HeapFree GetProcessHeap(), 0, BYVAL pttbb
            ' Update the size of the toolbar
            SendMessage hWndChild, %TB_AUTOSIZE, 0, 0
         END IF

         FUNCTION = %FALSE
         EXIT FUNCTION
   END SELECT

   FUNCTION = DefWindowProc(hWnd, uMsg, wParam, lParam)

END FUNCTION
'=========================================================================================


To position the toolbar at the bottom of the parent window's client area use the CCS_BOTTTOM style.


         ' Create the Toolbar1 toolbar control
         hWndChild = CreateWindowEx(%NULL, _                                              ' extended styles
                                    "ToolbarWindow32", _                                  ' class name
                                    "", _                                                 ' caption
                                    %WS_CHILD OR %WS_VISIBLE OR _                         ' window styles
                                    %CCS_BOTTTOM, _                                       ' class styles
                                    0, 0, _                                               ' left, top
                                    345, 116, _                                           ' width, height
                                    hWnd, %IDC_TOOLBAR, _                                 ' handle of parent, control ID
                                    ghInstance, BYVAL %NULL)                              ' handle of instance, creation parameters



To give it a flat appearance use TBSTYLE_FLAT:


         ' Create the Toolbar1 toolbar control
         hWndChild = CreateWindowEx(%NULL, _                                              ' extended styles
                                    "ToolbarWindow32", _                                  ' class name
                                    "", _                                                 ' caption
                                    %WS_CHILD OR %WS_VISIBLE OR _                         ' window styles
                                    %CCS_TOP OR %TBSTYLE_FLAT, _                          ' class styles
                                    0, 0, _                                               ' left, top
                                    345, 116, _                                           ' width, height
                                    hWnd, %IDC_TOOLBAR, _                                 ' handle of parent, control ID
                                    ghInstance, BYVAL %NULL)                              ' handle of instance, creation parameters
         SendMessage hWndChild, %WM_SETFONT, hFont, %TRUE


José Roca

#2
 
The same Toolbar with tooltips, button captions and multiple lines of buttons.

To get multiple lines of buttons simply add TBSTYLE_WRAPABLE to the styles.


         ' Create the Toolbar1 toolbar control
         hWndChild = CreateWindowEx(%NULL, _                                              ' extended styles
                                    "ToolbarWindow32", _                                  ' class name
                                    "", _                                                 ' caption
                                    %WS_CHILD OR %WS_VISIBLE OR _                         ' window styles
                                    %CCS_TOP OR %TBSTYLE_TOOLTIPS OR _                    ' class styles
                                    %TBSTYLE_WRAPABLE, _
                                    0, 0, _                                               ' left, top
                                    345, 116, _                                           ' width, height
                                    hWnd, %IDC_TOOLBAR, _                                 ' handle of parent, control ID
                                    ghInstance, BYVAL %NULL)                              ' handle of instance, creation parameters


To be able to use tooltips add TBSTYLE_TOOLTIPS to the styles and then process the WM_NOTIFY message, where you will return a pointer to an ASCIIZ variable holding the tooltip text:


      CASE %WM_NOTIFY

         ' -------------------------------------------------------
         ' Notification messages are handled here.
         ' The TTN_GETDISPINFO message is sent by a ToolTip control
         ' to retrieve information needed to display a ToolTip window.
         ' ------------------------------------------------------
         ptnmhdr = lParam

         SELECT CASE @ptnmhdr.code
            CASE %TTN_GETDISPINFO
               ptttdi        = lParam
               @ptttdi.hinst = %NULL
               szTooltip = ""
               SELECT CASE @ptttdi.hdr.hwndFrom
                  CASE SendMessage(GetDlgItem(hWnd, %IDC_TOOLBAR), %TB_GETTOOLTIPS, 0, 0)
                     SELECT CASE @ptttdi.hdr.idFrom
                        CASE %IDM_CUT        : szTooltip = "Cut"
                        CASE %IDM_COPY       : szTooltip = "Copy"
                        CASE %IDM_PASTE      : szTooltip = "Paste"
                        CASE %IDM_UNDO       : szTooltip = "Undo"
                        CASE %IDM_REDOW      : szTooltip = "Redo"
                        CASE %IDM_DELETE     : szTooltip = "Delete"
                        CASE %IDM_FILENEW    : szTooltip = "File New"
                        CASE %IDM_FILEOPEN   : szTooltip = "File Open"
                        CASE %IDM_FILESAVE   : szTooltip = "File Save"
                        CASE %IDM_PRINTPRE   : szTooltip = "Print Preview"
                        CASE %IDM_PROPERTIES : szTooltip = "Properties"
                        CASE %IDM_HELP       : szTooltip = "Help"
                        CASE %IDM_FIND       : szTooltip = "Find"
                        CASE %IDM_REPLACE    : szTooltip = "Replace"
                        CASE %IDM_PRINT      : szTooltip = "Print"
                     END SELECT
                     IF LEN(szTooltip) THEN @ptttdi.lpszText = VARPTR(szTooltip)
               END SELECT
         END SELECT


To add button captions, add them to the internal string list of the control using the TB_ADDSTRING message.


            ' Add strings to the internal list
            sBtnText = "Cut" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Copy" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Paste" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Undo" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Redo" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Delete" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "File New" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "File Open" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "File Save" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Print Preview" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Properties" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Help" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Find" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Replace" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Print" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)


Here is the full program listing:


'#########################################################################################
' Toolbar Control example
'#########################################################################################

#DIM ALL
#COMPILE EXE
#INCLUDE ONCE "ToolbarCtrl.inc"

GLOBAL   ghInstance              AS DWORD    ' handle of the application instance

'--------------------------- [ Command Identifiers ] ---------------------------

%IDM_CUT                                     = 28000
%IDM_COPY                                    = 28001
%IDM_PASTE                                   = 28002
%IDM_UNDO                                    = 28003
%IDM_REDOW                                   = 28004
%IDM_DELETE                                  = 28005
%IDM_FILENEW                                 = 28006
%IDM_FILEOPEN                                = 28007
%IDM_FILESAVE                                = 28008
%IDM_PRINTPRE                                = 28009
%IDM_PROPERTIES                              = 28010
%IDM_HELP                                    = 28011
%IDM_FIND                                    = 28012
%IDM_REPLACE                                 = 28013
%IDM_PRINT                                   = 28014

'--------------------------- [ Control Identifiers ] ---------------------------

%IDC_TOOLBAR                                 = 101


'-------------------------------------------------------------------------------
'
' PROCEDURE: WinMain
' PURPOSE:   Program entry point, calls initialization function, processes
'            message loop.
'
'-------------------------------------------------------------------------------

FUNCTION WinMain _
   ( _
   BYVAL hInstance      AS DWORD, _       ' handle of current instance
   BYVAL hPrevInstance  AS DWORD, _       ' handle of previous instance(not used in Win32)
   BYVAL pszCmdLine     AS ASCIIZ PTR, _  ' address of command line
   BYVAL nCmdShow       AS LONG _         ' show state of window
   ) AS LONG

   LOCAL szClassName       AS ASCIIZ * %MAX_PATH         ' class name
   LOCAL twcx              AS WNDCLASSEX                 ' class information
   LOCAL tmsg              AS tagMsg                     ' message information
   LOCAL ticc              AS INIT_COMMON_CONTROLSEX     ' specifies common control classes to register
   LOCAL hWnd              AS DWORD                      ' handle of main window

   ' Save the handle of the application instance
   ghInstance = hInstance

   ' Register the Form1 window
   szClassName        = "EX_TOOLBAR_02"
   twcx.cbSize        = SIZEOF(twcx)                              ' size of WNDCLASSEX structure
   twcx.style         = %CS_DBLCLKS                               ' class styles
   twcx.lpfnWndProc   = CODEPTR(Form1_WndProc)                    ' address of window procedure used by class
   twcx.cbClsExtra    = 0                                         ' extra class bytes
   twcx.cbWndExtra    = 0                                         ' extra window bytes
   twcx.hInstance     = ghInstance                                ' instance of the process that is registering the window
   twcx.hIcon         = LoadIcon(%NULL, BYVAL %IDI_APPLICATION)   ' handle of class icon
   twcx.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)       ' handle of class cursor
   twcx.hbrBackground = %COLOR_BTNFACE + 1                        ' brush used to fill background of window's client area
   twcx.lpszMenuName  = %NULL                                     ' resource identifier of the class menu
   twcx.lpszClassName = VARPTR(szClassName)                       ' class name
   twcx.hIconSm       = %NULL                                     ' handle of small icon shown in caption/system Taskbar
   IF ISFALSE RegisterClassEx(twcx) THEN
      FUNCTION = %TRUE
      EXIT FUNCTION
   END IF

   ' Load the common controls library and
   ' specify the classes to register.
   ticc.dwSize = SIZEOF(ticc)
   ticc.dwICC  = %ICC_BAR_CLASSES
   InitCommonControlsEx ticc

   ' Create the Form1 window
   hWnd = CreateWindowEx(%WS_EX_WINDOWEDGE, _                                          ' extended styles
                         szClassName, _                                                ' class name
                         "Toolbar Demo", _                                             ' caption
                         %WS_OVERLAPPEDWINDOW OR %WS_VISIBLE, _                        ' window styles
                         %CW_USEDEFAULT, 0, _                                          ' left, top
                         %CW_USEDEFAULT, 0, _                                          ' width, height
                         %NULL, %NULL, _                                               ' handle of owner, menu handle
                         ghInstance, BYVAL %NULL)                                      ' handle of instance, creation parameters

   ' If window could not be created, return "failure"
   IF ISFALSE hWnd THEN
      FUNCTION = %FALSE
      EXIT FUNCTION
   END IF

   ' Make the window visible; update its client area
   ShowWindow hWnd, nCmdShow
   UpdateWindow hWnd

   ' Main message loop of program.
   ' Acquire and dispatch messages until a WM_QUIT message is received.
   WHILE ISTRUE GetMessage(tmsg, BYVAL %NULL, 0, 0)
      IF ISFALSE IsDialogMessage(hWnd, tmsg) THEN
         TranslateMessage tmsg
         DispatchMessage tmsg
      END IF
   WEND

   FUNCTION = tmsg.wParam

END FUNCTION

'-------------------------------------------------------------------------------
'
' PROCEDURE: Form1_WndProc
' PURPOSE:   Processes messages for the Form1 window.
'
'-------------------------------------------------------------------------------

FUNCTION Form1_WndProc _
   ( _
   BYVAL hWnd     AS DWORD, _ ' window handle
   BYVAL uMsg     AS DWORD, _ ' type of message
   BYVAL wParam   AS DWORD, _ ' first message parameter
   BYVAL lParam   AS LONG _   ' second message parameter
   ) EXPORT AS LONG

   LOCAL sBtnText       AS STRING               ' toolbar button caption
   LOCAL ttbb           AS TBBUTTON             ' specifies or receives the attributes of a toolbar button
   LOCAL ttbab          AS TBADDBITMAP          ' specifies the images to add to a toolbar
   LOCAL ptnmhdr        AS NMHDR PTR            ' information about a notification message
   LOCAL ptttdi         AS NMTTDISPINFO PTR     ' tooltip notification message information
   LOCAL pttbb          AS TBBUTTON PTR         ' address of array of toolbar button info
   LOCAL hWndChild      AS DWORD                ' handle of child window
   LOCAL hFont          AS DWORD                ' handle of font used by form
   LOCAL lMsgResult     AS LONG                 ' value returned to message after message is processed
   LOCAL szTooltip      AS ASCIIZ * 256         ' Tooltip text

   SELECT CASE uMsg

      CASE %WM_COMMAND

         ' -------------------------------------------------------
         ' Messages from the Toolbar are handled here.
         ' ------------------------------------------------------

         SELECT CASE LOWRD(wParam)

            CASE %IDCANCEL
               IF HIWRD(wParam) = %BN_CLICKED THEN
                  SendMessage hWnd, %WM_CLOSE, wParam, lParam
                  FUNCTION = %FALSE
                  EXIT FUNCTION
               END IF

            CASE %IDM_CUT
               MSGBOX "Cut button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_COPY
               MSGBOX "Copy button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_PASTE
               MSGBOX "Paste button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_UNDO
               MSGBOX "Undo button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_REDOW
               MSGBOX "Redo button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_DELETE
               MSGBOX "Delete button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FILENEW
               MSGBOX "File New button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FILEOPEN
               MSGBOX "File Open button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FILESAVE
               MSGBOX "File Save button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_PRINTPRE
               MSGBOX "Print Preview button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_PROPERTIES
               MSGBOX "Properties button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_HELP
               MSGBOX "Help button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FIND
               MSGBOX "Find button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_REPLACE
               MSGBOX "Replace button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_PRINT
               MSGBOX "Print button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

         END SELECT

      CASE %WM_NOTIFY

         ' -------------------------------------------------------
         ' Notification messages are handled here.
         ' The TTN_GETDISPINFO message is sent by a ToolTip control
         ' to retrieve information needed to display a ToolTip window.
         ' ------------------------------------------------------
         ptnmhdr = lParam

         SELECT CASE @ptnmhdr.code
            CASE %TTN_GETDISPINFO
               ptttdi        = lParam
               @ptttdi.hinst = %NULL
               szTooltip = ""
               SELECT CASE @ptttdi.hdr.hwndFrom
                  CASE SendMessage(GetDlgItem(hWnd, %IDC_TOOLBAR), %TB_GETTOOLTIPS, 0, 0)
                     SELECT CASE @ptttdi.hdr.idFrom
                        CASE %IDM_CUT        : szTooltip = "Cut"
                        CASE %IDM_COPY       : szTooltip = "Copy"
                        CASE %IDM_PASTE      : szTooltip = "Paste"
                        CASE %IDM_UNDO       : szTooltip = "Undo"
                        CASE %IDM_REDOW      : szTooltip = "Redo"
                        CASE %IDM_DELETE     : szTooltip = "Delete"
                        CASE %IDM_FILENEW    : szTooltip = "File New"
                        CASE %IDM_FILEOPEN   : szTooltip = "File Open"
                        CASE %IDM_FILESAVE   : szTooltip = "File Save"
                        CASE %IDM_PRINTPRE   : szTooltip = "Print Preview"
                        CASE %IDM_PROPERTIES : szTooltip = "Properties"
                        CASE %IDM_HELP       : szTooltip = "Help"
                        CASE %IDM_FIND       : szTooltip = "Find"
                        CASE %IDM_REPLACE    : szTooltip = "Replace"
                        CASE %IDM_PRINT      : szTooltip = "Print"
                     END SELECT
                     IF LEN(szTooltip) THEN @ptttdi.lpszText = VARPTR(szTooltip)
               END SELECT
         END SELECT

      CASE %WM_SYSCOLORCHANGE
         ' Forward this message to common controls so that they will
         ' be properly updated when the user changes the color settings.
         SendMessage GetDlgItem(hWnd, %IDC_TOOLBAR), %WM_SYSCOLORCHANGE, wParam, lParam

      CASE %WM_DESTROY
         PostQuitMessage 0
         FUNCTION = %FALSE
         EXIT FUNCTION

      CASE %WM_SIZE
         IF wParam <> %SIZE_MINIMIZED THEN
            ' Update the size and position of the Toolbar control
            SendMessage GetDlgItem(hWnd, %IDC_TOOLBAR), %TB_AUTOSIZE, 0, 0
         END IF
         FUNCTION = %FALSE
         EXIT FUNCTION

      CASE %WM_CREATE
         ' Create font used by container
         hFont = GetStockObject(%DEFAULT_GUI_FONT)

         ' Create the Toolbar1 toolbar control
         hWndChild = CreateWindowEx(%NULL, _                                              ' extended styles
                                    "ToolbarWindow32", _                                  ' class name
                                    "", _                                                 ' caption
                                    %WS_CHILD OR %WS_VISIBLE OR _                         ' window styles
                                    %CCS_TOP OR %TBSTYLE_TOOLTIPS OR _                    ' class styles
                                    %TBSTYLE_WRAPABLE, _
                                    0, 0, _                                               ' left, top
                                    345, 116, _                                           ' width, height
                                    hWnd, %IDC_TOOLBAR, _                                 ' handle of parent, control ID
                                    ghInstance, BYVAL %NULL)                              ' handle of instance, creation parameters
         SendMessage hWndChild, %WM_SETFONT, hFont, %TRUE

         ' Allocate memory for the button info array
         pttbb = HeapAlloc(GetProcessHeap(), %HEAP_ZERO_MEMORY, 15 * SIZEOF(ttbb))
         IF ISTRUE pttbb THEN
            ' Send the TB_BUTTONSTRUCTSIZE message, for backward compatibility
            SendMessage hWndChild, %TB_BUTTONSTRUCTSIZE, SIZEOF(ttbb), 0
            ' Add bitmaps to the internal image list
            ttbab.hInst = %HINST_COMMCTRL
            ttbab.nId   = %IDB_STD_SMALL_COLOR
            SendMessage hWndChild, %TB_ADDBITMAP, 15, BYVAL VARPTR(ttbab)
            ' Add strings to the internal list
            sBtnText = "Cut" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Copy" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Paste" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Undo" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Redo" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Delete" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "File New" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "File Open" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "File Save" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Print Preview" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Properties" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Help" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Find" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Replace" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Print" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            ' Add buttons to the toolbar
            @pttbb[0].iBitmap    = %STD_CUT
            @pttbb[0].idCommand  = %IDM_CUT
            @pttbb[0].fsState    = %TBSTATE_ENABLED
            @pttbb[0].fsStyle    = %BTNS_BUTTON
            @pttbb[0].dwData     = 0
            @pttbb[0].iString    = 0

            @pttbb[1].iBitmap    = %STD_COPY
            @pttbb[1].idCommand  = %IDM_COPY
            @pttbb[1].fsState    = %TBSTATE_ENABLED
            @pttbb[1].fsStyle    = %BTNS_BUTTON
            @pttbb[1].dwData     = 0
            @pttbb[1].iString    = 1

            @pttbb[2].iBitmap    = %STD_PASTE
            @pttbb[2].idCommand  = %IDM_PASTE
            @pttbb[2].fsState    = %TBSTATE_ENABLED
            @pttbb[2].fsStyle    = %BTNS_BUTTON
            @pttbb[2].dwData     = 0
            @pttbb[2].iString    = 2

            @pttbb[3].iBitmap    = %STD_UNDO
            @pttbb[3].idCommand  = %IDM_UNDO
            @pttbb[3].fsState    = %TBSTATE_ENABLED
            @pttbb[3].fsStyle    = %BTNS_BUTTON
            @pttbb[3].dwData     = 0
            @pttbb[3].iString    = 3

            @pttbb[4].iBitmap    = %STD_REDOW
            @pttbb[4].idCommand  = %IDM_REDOW
            @pttbb[4].fsState    = %TBSTATE_ENABLED
            @pttbb[4].fsStyle    = %BTNS_BUTTON
            @pttbb[4].dwData     = 0
            @pttbb[4].iString    = 4

            @pttbb[5].iBitmap    = %STD_DELETE
            @pttbb[5].idCommand  = %IDM_DELETE
            @pttbb[5].fsState    = %TBSTATE_ENABLED
            @pttbb[5].fsStyle    = %BTNS_BUTTON
            @pttbb[5].dwData     = 0
            @pttbb[5].iString    = 5

            @pttbb[6].iBitmap    = %STD_FILENEW
            @pttbb[6].idCommand  = %IDM_FILENEW
            @pttbb[6].fsState    = %TBSTATE_ENABLED
            @pttbb[6].fsStyle    = %BTNS_BUTTON
            @pttbb[6].dwData     = 0
            @pttbb[6].iString    = 6

            @pttbb[7].iBitmap    = %STD_FILEOPEN
            @pttbb[7].idCommand  = %IDM_FILEOPEN
            @pttbb[7].fsState    = %TBSTATE_ENABLED
            @pttbb[7].fsStyle    = %BTNS_BUTTON
            @pttbb[7].dwData     = 0
            @pttbb[7].iString    = 7

            @pttbb[8].iBitmap    = %STD_FILESAVE
            @pttbb[8].idCommand  = %IDM_FILESAVE
            @pttbb[8].fsState    = %TBSTATE_ENABLED
            @pttbb[8].fsStyle    = %BTNS_BUTTON
            @pttbb[8].dwData     = 0
            @pttbb[8].iString    = 8

            @pttbb[9].iBitmap    = %STD_PRINTPRE
            @pttbb[9].idCommand  = %IDM_PRINTPRE
            @pttbb[9].fsState    = %TBSTATE_ENABLED
            @pttbb[9].fsStyle    = %BTNS_BUTTON
            @pttbb[9].dwData     = 0
            @pttbb[9].iString    = 9

            @pttbb[10].iBitmap   = %STD_PROPERTIES
            @pttbb[10].idCommand = %IDM_PROPERTIES
            @pttbb[10].fsState   = %TBSTATE_ENABLED
            @pttbb[10].fsStyle   = %BTNS_BUTTON
            @pttbb[10].dwData    = 0
            @pttbb[10].iString   = 10

            @pttbb[11].iBitmap   = %STD_HELP
            @pttbb[11].idCommand = %IDM_HELP
            @pttbb[11].fsState   = %TBSTATE_ENABLED
            @pttbb[11].fsStyle   = %BTNS_BUTTON
            @pttbb[11].dwData    = 0
            @pttbb[11].iString   = 11

            @pttbb[12].iBitmap   = %STD_FIND
            @pttbb[12].idCommand = %IDM_FIND
            @pttbb[12].fsState   = %TBSTATE_ENABLED
            @pttbb[12].fsStyle   = %BTNS_BUTTON
            @pttbb[12].dwData    = 0
            @pttbb[12].iString   = 12

            @pttbb[13].iBitmap   = %STD_REPLACE
            @pttbb[13].idCommand = %IDM_REPLACE
            @pttbb[13].fsState   = %TBSTATE_ENABLED
            @pttbb[13].fsStyle   = %BTNS_BUTTON
            @pttbb[13].dwData    = 0
            @pttbb[13].iString   = 13

            @pttbb[14].iBitmap   = %STD_PRINT
            @pttbb[14].idCommand = %IDM_PRINT
            @pttbb[14].fsState   = %TBSTATE_ENABLED
            @pttbb[14].fsStyle   = %BTNS_BUTTON
            @pttbb[14].dwData    = 0
            @pttbb[14].iString   = 14
            SendMessage hWndChild, %TB_ADDBUTTONS, 15, BYVAL pttbb
            ' Free memory that was allocated for the button info
            HeapFree GetProcessHeap(), 0, BYVAL pttbb
            ' Update the size of the toolbar
            SendMessage hWndChild, %TB_AUTOSIZE, 0, 0
         END IF

         FUNCTION = %FALSE
         EXIT FUNCTION
   END SELECT

   FUNCTION = DefWindowProc(hWnd, uMsg, wParam, lParam)

END FUNCTION
'=========================================================================================


José Roca

#3
 
Now, instead of passing a pointer to a variable holding the text of the tooltip, we are going to use a resource file with an string table:

Resource file: EX_TOOLBAR_02.RC


// Resource script

////////////////////////////////////////////////////////////////////////////////
//
//  Menu/Toolbar Identifiers
//

#define IDM_CUT                              28000
#define IDM_COPY                             28001
#define IDM_PASTE                            28002
#define IDM_UNDO                             28003
#define IDM_REDOW                            28004
#define IDM_DELETE                           28005
#define IDM_FILENEW                          28006
#define IDM_FILEOPEN                         28007
#define IDM_FILESAVE                         28008
#define IDM_PRINTPRE                         28009
#define IDM_PROPERTIES                       28010
#define IDM_HELP                             28011
#define IDM_FIND                             28012
#define IDM_REPLACE                          28013
#define IDM_PRINT                            28014

////////////////////////////////////////////////////////////////////////////////
//
//  Toolbar tooltip string table
//

STRINGTABLE DISCARDABLE
BEGIN
   IDM_CUT                    "Cut"
   IDM_COPY                   "Copy"
   IDM_PASTE                  "Paste"
   IDM_UNDO                   "Undo"
   IDM_REDOW                  "Redo"
   IDM_DELETE                 "Delete"
   IDM_FILENEW                "File New"
   IDM_FILEOPEN               "File Open"
   IDM_FILESAVE               "File Save"
   IDM_PRINTPRE               "Print Preview"
   IDM_PROPERTIES             "Properties"
   IDM_HELP                   "Help"
   IDM_FIND                   "Find"
   IDM_REPLACE                "Replace"
   IDM_PRINT                  "Print"
END


Note: For information of how to compile resource files see the Resource Files topic in the help file of the compiler.

Once compiled and converted to a .PBR file, we need to add the following line to our program:


#RESOURCE "EX_TOOLBAR_02.PBR"


And we will change the code that processes the WM_NOTIFY message to:


      CASE %WM_NOTIFY

         ' -------------------------------------------------------
         ' Notification messages are handled here.
         ' The TTN_GETDISPINFO message is sent by a ToolTip control
         ' to retrieve information needed to display a ToolTip window.
         ' ------------------------------------------------------
         ptnmhdr = lParam

         SELECT CASE @ptnmhdr.code
            CASE %TTN_GETDISPINFO
               ptttdi        = lParam
               @ptttdi.hinst = ghInstance

               SELECT CASE @ptttdi.hdr.hwndFrom
                  ' The TB_GETTOOLTIPS message retrieves the handle to the ToolTip control,
                  ' if any, associated with the toolbar.
                  CASE SendMessage(GetDlgItem(hWnd, %IDC_TOOLBAR), %TB_GETTOOLTIPS, 0, 0)
                     @ptttdi.lpszText = @ptttdi.hdr.idFrom
                     EXIT FUNCTION
               END SELECT
         END SELECT


Here is the full program listing:


'#########################################################################################
' Toolbar Control example
'#########################################################################################

#DIM ALL
#COMPILE EXE
#INCLUDE ONCE "ToolbarCtrl.inc"
#RESOURCE "EX_TOOLBAR_02.PBR"

GLOBAL   ghInstance              AS DWORD    ' handle of the application instance

'--------------------------- [ Command Identifiers ] ---------------------------

%IDM_CUT                                     = 28000
%IDM_COPY                                    = 28001
%IDM_PASTE                                   = 28002
%IDM_UNDO                                    = 28003
%IDM_REDOW                                   = 28004
%IDM_DELETE                                  = 28005
%IDM_FILENEW                                 = 28006
%IDM_FILEOPEN                                = 28007
%IDM_FILESAVE                                = 28008
%IDM_PRINTPRE                                = 28009
%IDM_PROPERTIES                              = 28010
%IDM_HELP                                    = 28011
%IDM_FIND                                    = 28012
%IDM_REPLACE                                 = 28013
%IDM_PRINT                                   = 28014

'--------------------------- [ Control Identifiers ] ---------------------------

%IDC_TOOLBAR                                 = 101


'-------------------------------------------------------------------------------
'
' PROCEDURE: WinMain
' PURPOSE:   Program entry point, calls initialization function, processes
'            message loop.
'
'-------------------------------------------------------------------------------

FUNCTION WinMain _
   ( _
   BYVAL hInstance      AS DWORD, _       ' handle of current instance
   BYVAL hPrevInstance  AS DWORD, _       ' handle of previous instance(not used in Win32)
   BYVAL pszCmdLine     AS ASCIIZ PTR, _  ' address of command line
   BYVAL nCmdShow       AS LONG _         ' show state of window
   ) AS LONG

   LOCAL szClassName       AS ASCIIZ * %MAX_PATH         ' class name
   LOCAL twcx              AS WNDCLASSEX                 ' class information
   LOCAL tmsg              AS tagMsg                     ' message information
   LOCAL ticc              AS INIT_COMMON_CONTROLSEX     ' specifies common control classes to register
   LOCAL hWnd              AS DWORD                      ' handle of main window

   ' Save the handle of the application instance
   ghInstance = hInstance

   ' Register the Form1 window
   szClassName        = "EX_TOOLBAR_02"
   twcx.cbSize        = SIZEOF(twcx)                              ' size of WNDCLASSEX structure
   twcx.style         = %CS_DBLCLKS                               ' class styles
   twcx.lpfnWndProc   = CODEPTR(Form1_WndProc)                    ' address of window procedure used by class
   twcx.cbClsExtra    = 0                                         ' extra class bytes
   twcx.cbWndExtra    = 0                                         ' extra window bytes
   twcx.hInstance     = ghInstance                                ' instance of the process that is registering the window
   twcx.hIcon         = LoadIcon(%NULL, BYVAL %IDI_APPLICATION)   ' handle of class icon
   twcx.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)       ' handle of class cursor
   twcx.hbrBackground = %COLOR_BTNFACE + 1                        ' brush used to fill background of window's client area
   twcx.lpszMenuName  = %NULL                                     ' resource identifier of the class menu
   twcx.lpszClassName = VARPTR(szClassName)                       ' class name
   twcx.hIconSm       = %NULL                                     ' handle of small icon shown in caption/system Taskbar
   IF ISFALSE RegisterClassEx(twcx) THEN
      FUNCTION = %TRUE
      EXIT FUNCTION
   END IF

   ' Load the common controls library and
   ' specify the classes to register.
   ticc.dwSize = SIZEOF(ticc)
   ticc.dwICC  = %ICC_BAR_CLASSES
   InitCommonControlsEx ticc

   ' Create the Form1 window
   hWnd = CreateWindowEx(%WS_EX_WINDOWEDGE, _                                          ' extended styles
                         szClassName, _                                                ' class name
                         "Toolbar Demo", _                                             ' caption
                         %WS_OVERLAPPEDWINDOW OR %WS_VISIBLE, _                        ' window styles
                         %CW_USEDEFAULT, 0, _                                          ' left, top
                         %CW_USEDEFAULT, 0, _                                          ' width, height
                         %NULL, %NULL, _                                               ' handle of owner, menu handle
                         ghInstance, BYVAL %NULL)                                      ' handle of instance, creation parameters

   ' If window could not be created, return "failure"
   IF ISFALSE hWnd THEN
      FUNCTION = %FALSE
      EXIT FUNCTION
   END IF

   ' Make the window visible; update its client area
   ShowWindow hWnd, nCmdShow
   UpdateWindow hWnd

   ' Main message loop of program.
   ' Acquire and dispatch messages until a WM_QUIT message is received.
   WHILE ISTRUE GetMessage(tmsg, BYVAL %NULL, 0, 0)
      IF ISFALSE IsDialogMessage(hWnd, tmsg) THEN
         TranslateMessage tmsg
         DispatchMessage tmsg
      END IF
   WEND

   FUNCTION = tmsg.wParam

END FUNCTION

'-------------------------------------------------------------------------------
'
' PROCEDURE: Form1_WndProc
' PURPOSE:   Processes messages for the Form1 window.
'
'-------------------------------------------------------------------------------

FUNCTION Form1_WndProc _
   ( _
   BYVAL hWnd     AS DWORD, _ ' window handle
   BYVAL uMsg     AS DWORD, _ ' type of message
   BYVAL wParam   AS DWORD, _ ' first message parameter
   BYVAL lParam   AS LONG _   ' second message parameter
   ) EXPORT AS LONG

   LOCAL sBtnText       AS STRING               ' toolbar button caption
   LOCAL ttbb           AS TBBUTTON             ' specifies or receives the attributes of a toolbar button
   LOCAL ttbab          AS TBADDBITMAP          ' specifies the images to add to a toolbar
   LOCAL ptnmhdr        AS NMHDR PTR            ' information about a notification message
   LOCAL ptttdi         AS NMTTDISPINFO PTR     ' tooltip notification message information
   LOCAL pttbb          AS TBBUTTON PTR         ' address of array of toolbar button info
   LOCAL hWndChild      AS DWORD                ' handle of child window
   LOCAL hFont          AS DWORD                ' handle of font used by form
   LOCAL lMsgResult     AS LONG                 ' value returned to message after message is processed

   SELECT CASE uMsg

      CASE %WM_COMMAND

         ' -------------------------------------------------------
         ' Messages from the Toolbar are handled here.
         ' ------------------------------------------------------

         SELECT CASE LOWRD(wParam)

            CASE %IDCANCEL
               IF HIWRD(wParam) = %BN_CLICKED THEN
                  SendMessage hWnd, %WM_CLOSE, wParam, lParam
                  FUNCTION = %FALSE
                  EXIT FUNCTION
               END IF

            CASE %IDM_CUT
               MSGBOX "Cut button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_COPY
               MSGBOX "Copy button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_PASTE
               MSGBOX "Paste button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_UNDO
               MSGBOX "Undo button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_REDOW
               MSGBOX "Redo button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_DELETE
               MSGBOX "Delete button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FILENEW
               MSGBOX "File New button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FILEOPEN
               MSGBOX "File Open button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FILESAVE
               MSGBOX "File Save button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_PRINTPRE
               MSGBOX "Print Preview button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_PROPERTIES
               MSGBOX "Properties button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_HELP
               MSGBOX "Help button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FIND
               MSGBOX "Find button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_REPLACE
               MSGBOX "Replace button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_PRINT
               MSGBOX "Print button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

         END SELECT

      CASE %WM_NOTIFY

         ' -------------------------------------------------------
         ' Notification messages are handled here.
         ' The TTN_GETDISPINFO message is sent by a ToolTip control
         ' to retrieve information needed to display a ToolTip window.
         ' ------------------------------------------------------
         ptnmhdr = lParam

         SELECT CASE @ptnmhdr.code
            CASE %TTN_GETDISPINFO
               ptttdi        = lParam
               @ptttdi.hinst = ghInstance

               SELECT CASE @ptttdi.hdr.hwndFrom
                  ' The TB_GETTOOLTIPS message retrieves the handle to the ToolTip control,
                  ' if any, associated with the toolbar.
                  CASE SendMessage(GetDlgItem(hWnd, %IDC_TOOLBAR), %TB_GETTOOLTIPS, 0, 0)
                     @ptttdi.lpszText = @ptttdi.hdr.idFrom
                     EXIT FUNCTION
               END SELECT
         END SELECT

      CASE %WM_SYSCOLORCHANGE
         ' Forward this message to common controls so that they will
         ' be properly updated when the user changes the color settings.
         SendMessage GetDlgItem(hWnd, %IDC_TOOLBAR), %WM_SYSCOLORCHANGE, wParam, lParam

      CASE %WM_DESTROY
         PostQuitMessage 0
         FUNCTION = %FALSE
         EXIT FUNCTION

      CASE %WM_SIZE
         IF wParam <> %SIZE_MINIMIZED THEN
            ' Update the size and position of the Toolbar control
            SendMessage GetDlgItem(hWnd, %IDC_TOOLBAR), %TB_AUTOSIZE, 0, 0
         END IF
         FUNCTION = %FALSE
         EXIT FUNCTION

      CASE %WM_CREATE
         ' Create font used by container
         hFont = GetStockObject(%DEFAULT_GUI_FONT)

         ' Create the Toolbar1 toolbar control
         hWndChild = CreateWindowEx(%NULL, _                                              ' extended styles
                                    "ToolbarWindow32", _                                  ' class name
                                    "", _                                                 ' caption
                                    %WS_CHILD OR %WS_VISIBLE OR _                         ' window styles
                                    %CCS_TOP OR %TBSTYLE_TOOLTIPS OR _                    ' class styles
                                    %TBSTYLE_WRAPABLE, _
                                    0, 0, _                                               ' left, top
                                    345, 116, _                                           ' width, height
                                    hWnd, %IDC_TOOLBAR, _                                 ' handle of parent, control ID
                                    ghInstance, BYVAL %NULL)                              ' handle of instance, creation parameters
         SendMessage hWndChild, %WM_SETFONT, hFont, %TRUE

         ' Allocate memory for the button info array
         pttbb = HeapAlloc(GetProcessHeap(), %HEAP_ZERO_MEMORY, 15 * SIZEOF(ttbb))
         IF ISTRUE pttbb THEN
            ' Send the TB_BUTTONSTRUCTSIZE message, for backward compatibility
            SendMessage hWndChild, %TB_BUTTONSTRUCTSIZE, SIZEOF(ttbb), 0
            ' Add bitmaps to the internal image list
            ttbab.hInst = %HINST_COMMCTRL
            ttbab.nId   = %IDB_STD_SMALL_COLOR
            SendMessage hWndChild, %TB_ADDBITMAP, 15, BYVAL VARPTR(ttbab)
            ' Add strings to the internal list
            sBtnText = "Cut" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Copy" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Paste" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Undo" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Redo" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Delete" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "File New" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "File Open" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "File Save" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Print Preview" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Properties" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Help" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Find" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Replace" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            sBtnText = "Print" + CHR$(0, 0)
            SendMessage hWndChild, %TB_ADDSTRING, %NULL, BYVAL STRPTR(sBtnText)
            ' Add buttons to the toolbar
            @pttbb[0].iBitmap    = %STD_CUT
            @pttbb[0].idCommand  = %IDM_CUT
            @pttbb[0].fsState    = %TBSTATE_ENABLED
            @pttbb[0].fsStyle    = %BTNS_BUTTON
            @pttbb[0].dwData     = 0
            @pttbb[0].iString    = 0

            @pttbb[1].iBitmap    = %STD_COPY
            @pttbb[1].idCommand  = %IDM_COPY
            @pttbb[1].fsState    = %TBSTATE_ENABLED
            @pttbb[1].fsStyle    = %BTNS_BUTTON
            @pttbb[1].dwData     = 0
            @pttbb[1].iString    = 1

            @pttbb[2].iBitmap    = %STD_PASTE
            @pttbb[2].idCommand  = %IDM_PASTE
            @pttbb[2].fsState    = %TBSTATE_ENABLED
            @pttbb[2].fsStyle    = %BTNS_BUTTON
            @pttbb[2].dwData     = 0
            @pttbb[2].iString    = 2

            @pttbb[3].iBitmap    = %STD_UNDO
            @pttbb[3].idCommand  = %IDM_UNDO
            @pttbb[3].fsState    = %TBSTATE_ENABLED
            @pttbb[3].fsStyle    = %BTNS_BUTTON
            @pttbb[3].dwData     = 0
            @pttbb[3].iString    = 3

            @pttbb[4].iBitmap    = %STD_REDOW
            @pttbb[4].idCommand  = %IDM_REDOW
            @pttbb[4].fsState    = %TBSTATE_ENABLED
            @pttbb[4].fsStyle    = %BTNS_BUTTON
            @pttbb[4].dwData     = 0
            @pttbb[4].iString    = 4

            @pttbb[5].iBitmap    = %STD_DELETE
            @pttbb[5].idCommand  = %IDM_DELETE
            @pttbb[5].fsState    = %TBSTATE_ENABLED
            @pttbb[5].fsStyle    = %BTNS_BUTTON
            @pttbb[5].dwData     = 0
            @pttbb[5].iString    = 5

            @pttbb[6].iBitmap    = %STD_FILENEW
            @pttbb[6].idCommand  = %IDM_FILENEW
            @pttbb[6].fsState    = %TBSTATE_ENABLED
            @pttbb[6].fsStyle    = %BTNS_BUTTON
            @pttbb[6].dwData     = 0
            @pttbb[6].iString    = 6

            @pttbb[7].iBitmap    = %STD_FILEOPEN
            @pttbb[7].idCommand  = %IDM_FILEOPEN
            @pttbb[7].fsState    = %TBSTATE_ENABLED
            @pttbb[7].fsStyle    = %BTNS_BUTTON
            @pttbb[7].dwData     = 0
            @pttbb[7].iString    = 7

            @pttbb[8].iBitmap    = %STD_FILESAVE
            @pttbb[8].idCommand  = %IDM_FILESAVE
            @pttbb[8].fsState    = %TBSTATE_ENABLED
            @pttbb[8].fsStyle    = %BTNS_BUTTON
            @pttbb[8].dwData     = 0
            @pttbb[8].iString    = 8

            @pttbb[9].iBitmap    = %STD_PRINTPRE
            @pttbb[9].idCommand  = %IDM_PRINTPRE
            @pttbb[9].fsState    = %TBSTATE_ENABLED
            @pttbb[9].fsStyle    = %BTNS_BUTTON
            @pttbb[9].dwData     = 0
            @pttbb[9].iString    = 9

            @pttbb[10].iBitmap   = %STD_PROPERTIES
            @pttbb[10].idCommand = %IDM_PROPERTIES
            @pttbb[10].fsState   = %TBSTATE_ENABLED
            @pttbb[10].fsStyle   = %BTNS_BUTTON
            @pttbb[10].dwData    = 0
            @pttbb[10].iString   = 10

            @pttbb[11].iBitmap   = %STD_HELP
            @pttbb[11].idCommand = %IDM_HELP
            @pttbb[11].fsState   = %TBSTATE_ENABLED
            @pttbb[11].fsStyle   = %BTNS_BUTTON
            @pttbb[11].dwData    = 0
            @pttbb[11].iString   = 11

            @pttbb[12].iBitmap   = %STD_FIND
            @pttbb[12].idCommand = %IDM_FIND
            @pttbb[12].fsState   = %TBSTATE_ENABLED
            @pttbb[12].fsStyle   = %BTNS_BUTTON
            @pttbb[12].dwData    = 0
            @pttbb[12].iString   = 12

            @pttbb[13].iBitmap   = %STD_REPLACE
            @pttbb[13].idCommand = %IDM_REPLACE
            @pttbb[13].fsState   = %TBSTATE_ENABLED
            @pttbb[13].fsStyle   = %BTNS_BUTTON
            @pttbb[13].dwData    = 0
            @pttbb[13].iString   = 13

            @pttbb[14].iBitmap   = %STD_PRINT
            @pttbb[14].idCommand = %IDM_PRINT
            @pttbb[14].fsState   = %TBSTATE_ENABLED
            @pttbb[14].fsStyle   = %BTNS_BUTTON
            @pttbb[14].dwData    = 0
            @pttbb[14].iString   = 14
            SendMessage hWndChild, %TB_ADDBUTTONS, 15, BYVAL pttbb
            ' Free memory that was allocated for the button info
            HeapFree GetProcessHeap(), 0, BYVAL pttbb
            ' Update the size of the toolbar
            SendMessage hWndChild, %TB_AUTOSIZE, 0, 0
         END IF

         FUNCTION = %FALSE
         EXIT FUNCTION
   END SELECT

   FUNCTION = DefWindowProc(hWnd, uMsg, wParam, lParam)

END FUNCTION
'=========================================================================================


Finally, if we want to have the button captions placed to the right of the bitmap instead of below it, we will use the TBSTYLE_LIST style:


         ' Create the Toolbar1 toolbar control
         hWndChild = CreateWindowEx(%NULL, _                                              ' extended styles
                                    "ToolbarWindow32", _                                  ' class name
                                    "", _                                                 ' caption
                                    %WS_CHILD OR %WS_VISIBLE OR _                         ' window styles
                                    %CCS_TOP OR %TBSTYLE_TOOLTIPS OR _                    ' class styles
                                    %TBSTYLE_WRAPABLE OR %TBSTYLE_LIST, _
                                    0, 0, _                                               ' left, top
                                    345, 116, _                                           ' width, height
                                    hWnd, %IDC_TOOLBAR, _                                 ' handle of parent, control ID
                                    ghInstance, BYVAL %NULL)                              ' handle of instance, creation parameters


José Roca

#4
 
So far, so good. But standard icons are limited in number and are ugly to today standards. Besides, if we are more ambitious we will want to have toolbar buttons that will change its appearance when the mouse hovers over them and/or when they are disabled. For that we need to use image lists, that are bitmaps with an strip of icons.

Glyfz provides a link to download the free Glyfz sampler which provides you with a number of images from each of his products for you to try out.

http://www.glyfz.com/index.htm

glyFX provides a free common toolbar set which contains the most often used images, such as file functions (create, open, save), printing, navigation and more. These images are suitable for all applications and form the basis of the glyFX stock icon collection.

http://www.glyfx.com/free.html

The glyFX Image Welder is a utility to create multi-state image strips out of individual BMP icons. Depending on what controls you are using in your interface, rather than separate state images (normal, hot, disabled), you may need to use a single image which contains all of the states in a single file.

http://www.glyfx.com/utilities/image_welder.html

José Roca

#5
 
We also need a tool to create image lists. A very good and inexpensive professional icon editor is Articons: http://www.aha-soft.com/articons/index.htm . It has the ability to easily build image lists and to import and export them.

A free one is Toolbar Paint, by Edgar Hansen (aka Donkey), "a small and powerful paint package that is specifically targeted at developers who wish to design their own toolbar button graphics. It can open BMP images up to 64x64 pixel and allows you to visually design a toolbar, using various editing tools that include shapes, text, drawing, brush, selections and more. It also includes tools to replace colors, apply gradients and more. The toolbar graphics can be saved as 16 color, 256 color and 24 bit graphics. A tiny and powerful editor, written entirely in assembler. Additional plug-ins are available from the website that lets you save as icon file, add additional effects and more." It has a limit of 64 icons per image list, that will suffice in most cases.

http://www.assembler.ca/

Another freebie is TBarCreator, that you can download in The Code Project site. Comes with a collection of 408 16x16 icons in .gif format.

http://www.codeproject.com/tools/TBar.asp

José Roca

#6
 
Here are three image lists built with Toolbar Paint using the glyFX common toolbar set (see attched images), that we are going to use in the examples. Pink, RGB(255, 0, 255), is used as the transparent background color.

And here is the resource script that creates a resource file with the three bitmaps and defines identifiers for the 13 first images and an string table for the tooltips.

Resource: EX_TOOLBAR_03.RC


// Resource script

////////////////////////////////////////////////////////////////////////////////
//
//  Menu/Toolbar Identifiers
//

#define IDM_ARROWLEFT                        28000
#define IDM_ARROWRIGHT                       28001
#define IDM_COPYCLIPBOARD                    28002
#define IDM_COPYTOFOLDER                     28003
#define IDM_CUTCLIPBOARD                     28004
#define IDM_DELETE                           28005
#define IDM_FAVORITES                        28006
#define IDM_FOLDERCLOSED                     28007
#define IDM_FOLDEROPEN                       28008
#define IDM_FOLDEROPTIONS                    28009
#define IDM_FOLDERS                          28010
#define IDM_HISTORY                          28011
#define IDM_HOME                             28012

////////////////////////////////////////////////////////////////////////////////
//
// Application Bitmap Strips.
//

TBNOR  BITMAP Toolbar24Normal.BMP
TBHOT  BITMAP Toolbar24Hot.BMP
TBDIS  BITMAP Toolbar24Disabled.BMP

////////////////////////////////////////////////////////////////////////////////
//
//  Toolbar tooltip string table
//

STRINGTABLE DISCARDABLE
BEGIN
   IDM_ARROWLEFT              "Arrow Left"
   IDM_ARROWRIGHT             "Arrow Right"
   IDM_COPYCLIPBOARD          "Copy to Clipboard"
   IDM_COPYTOFOLDER           "Copy to Folder"
   IDM_CUTCLIPBOARD           "Cut to Clipboard"
   IDM_DELETE                 "Delete"
   IDM_FAVORITES              "Favorites"
   IDM_FOLDERCLOSED           "Folder Closed"
   IDM_FOLDEROPEN             "Folder Open"
   IDM_FOLDEROPTIONS          "Folder Options"
   IDM_FOLDERS                "Folders"
   IDM_HISTORY                "History"
   IDM_HOME                   "Home"
END


José Roca

#7
 
Using Imagelists

The following example creates a toolbar that uses three images lists for normal, disabled and hot state.

This is the code used to create the image lists from the three bitmap strips stored in the resource file:


         ' Set the imagelist used with default images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBNOR", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hWndChild, %TB_SETIMAGELIST, 0, hImageList

         ' Set the imagelist used with disabled images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBDIS", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hWndChild, %TB_SETDISABLEDIMAGELIST, 0, hImageList

         ' Set the imagelist used with hot images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBHOT", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hWndChild, %TB_SETHOTIMAGELIST, 0, hImageList


The code used to add the toolbar buttons is the same as the one used in the previous examples, excepting that instead of the STD_XXX identifiers we will use the zero based index of the image in the bitmap strip:


            ' Add buttons to the toolbar
            @pttbb[0].iBitmap    = 0
            @pttbb[0].idCommand  = %IDM_ARROWLEFT
            @pttbb[0].fsState    = %TBSTATE_ENABLED
            @pttbb[0].fsStyle    = %BTNS_BUTTON
            @pttbb[0].dwData     = 0
            @pttbb[0].iString    = -1

            @pttbb[1].iBitmap    = 1
            @pttbb[1].idCommand  = %IDM_ARROWRIGHT
            @pttbb[1].fsState    = 0
            @pttbb[1].fsStyle    = %BTNS_BUTTON
            @pttbb[1].dwData     = 0
            @pttbb[1].iString    = -1


Two of the buttons are flagged as disabled (fsState = 0) to show how the toolbar uses the images from the image list for disabled images instead of the ugly grayed hole with the shape of the icon that is produced when no image lists are used.

Finally, the image lists must be destroyed to avoid memory leaks. A good place to do it is during the processing of the WM_DESTROY message:


      CASE %WM_DESTROY
         ' Destroy the image lists
         hWndChild = GetDlgItem(hWnd, %IDC_TOOLBAR)
         ImageList_Destroy SendMessage(hWndChild, %TB_SETIMAGELIST, 0, %NULL)
         ImageList_Destroy SendMessage(hWndChild, %TB_SETDISABLEDIMAGELIST, 0, %NULL)
         ImageList_Destroy SendMessage(hWndChild, %TB_SETHOTIMAGELIST, 0, %NULL)


Here is the full program listing:


'#########################################################################################
' Toolbar Control example
'#########################################################################################

#DIM ALL
#COMPILE EXE
#INCLUDE ONCE "ToolbarCtrl.inc"
#RESOURCE "EX_TOOLBAR_03.PBR"

GLOBAL   ghInstance              AS DWORD    ' handle of the application instance

'--------------------------- [ Command Identifiers ] ---------------------------

%IDM_ARROWLEFT                               = 28000
%IDM_ARROWRIGHT                              = 28001
%IDM_COPYCLIPBOARD                           = 28002
%IDM_COPYTOFOLDER                            = 28003
%IDM_CUTCLIPBOARD                            = 28004
%IDM_DELETE                                  = 28005
%IDM_FAVORITES                               = 28006
%IDM_FOLDERCLOSED                            = 28007
%IDM_FOLDEROPEN                              = 28008
%IDM_FOLDEROPTIONS                           = 28009
%IDM_FOLDERS                                 = 28010
%IDM_HISTORY                                 = 28011
%IDM_HOME                                    = 28012

'--------------------------- [ Control Identifiers ] ---------------------------

%IDC_TOOLBAR                                 = 101


'-------------------------------------------------------------------------------
'
' PROCEDURE: WinMain
' PURPOSE:   Program entry point, calls initialization function, processes
'            message loop.
'
'-------------------------------------------------------------------------------

FUNCTION WinMain _
   ( _
   BYVAL hInstance      AS DWORD, _       ' handle of current instance
   BYVAL hPrevInstance  AS DWORD, _       ' handle of previous instance(not used in Win32)
   BYVAL pszCmdLine     AS ASCIIZ PTR, _  ' address of command line
   BYVAL nCmdShow       AS LONG _         ' show state of window
   ) AS LONG

   LOCAL szClassName       AS ASCIIZ * %MAX_PATH         ' class name
   LOCAL twcx              AS WNDCLASSEX                 ' class information
   LOCAL tmsg              AS tagMsg                     ' message information
   LOCAL ticc              AS INIT_COMMON_CONTROLSEX     ' specifies common control classes to register
   LOCAL hWnd              AS DWORD                      ' handle of main window

   ' Save the handle of the application instance
   ghInstance = hInstance

   ' Register the Form1 window
   szClassName        = "EX_TOOLBAR_03"
   twcx.cbSize        = SIZEOF(twcx)                              ' size of WNDCLASSEX structure
   twcx.style         = %CS_DBLCLKS                               ' class styles
   twcx.lpfnWndProc   = CODEPTR(Form1_WndProc)                    ' address of window procedure used by class
   twcx.cbClsExtra    = 0                                         ' extra class bytes
   twcx.cbWndExtra    = 0                                         ' extra window bytes
   twcx.hInstance     = ghInstance                                ' instance of the process that is registering the window
   twcx.hIcon         = LoadIcon(%NULL, BYVAL %IDI_APPLICATION)   ' handle of class icon
   twcx.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)       ' handle of class cursor
   twcx.hbrBackground = %COLOR_BTNFACE + 1                        ' brush used to fill background of window's client area
   twcx.lpszMenuName  = %NULL                                     ' resource identifier of the class menu
   twcx.lpszClassName = VARPTR(szClassName)                       ' class name
   twcx.hIconSm       = %NULL                                     ' handle of small icon shown in caption/system Taskbar
   IF ISFALSE RegisterClassEx(twcx) THEN
      FUNCTION = %TRUE
      EXIT FUNCTION
   END IF

   ' Load the common controls library and
   ' specify the classes to register.
   ticc.dwSize = SIZEOF(ticc)
   ticc.dwICC  = %ICC_BAR_CLASSES
   InitCommonControlsEx ticc

   ' Create the Form1 window
   hWnd = CreateWindowEx(%WS_EX_WINDOWEDGE, _                                          ' extended styles
                         szClassName, _                                                ' class name
                         "Toolbar Demo", _                                             ' caption
                         %WS_OVERLAPPEDWINDOW OR %WS_VISIBLE, _                        ' window styles
                         %CW_USEDEFAULT, 0, _                                          ' left, top
                         %CW_USEDEFAULT, 0, _                                          ' width, height
                         %NULL, %NULL, _                                               ' handle of owner, menu handle
                         ghInstance, BYVAL %NULL)                                      ' handle of instance, creation parameters

   ' If window could not be created, return "failure"
   IF ISFALSE hWnd THEN
      FUNCTION = %FALSE
      EXIT FUNCTION
   END IF

   ' Make the window visible; update its client area
   ShowWindow hWnd, nCmdShow
   UpdateWindow hWnd

   ' Main message loop of program.
   ' Acquire and dispatch messages until a WM_QUIT message is received.
   WHILE ISTRUE GetMessage(tmsg, BYVAL %NULL, 0, 0)
      IF ISFALSE IsDialogMessage(hWnd, tmsg) THEN
         TranslateMessage tmsg
         DispatchMessage tmsg
      END IF
   WEND

   FUNCTION = tmsg.wParam

END FUNCTION

'-------------------------------------------------------------------------------
'
' PROCEDURE: Form1_WndProc
' PURPOSE:   Processes messages for the Form1 window.
'
'-------------------------------------------------------------------------------

FUNCTION Form1_WndProc _
   ( _
   BYVAL hWnd     AS DWORD, _ ' window handle
   BYVAL uMsg     AS DWORD, _ ' type of message
   BYVAL wParam   AS DWORD, _ ' first message parameter
   BYVAL lParam   AS LONG _   ' second message parameter
   ) EXPORT AS LONG

   LOCAL sBtnText       AS STRING               ' toolbar button caption
   LOCAL ttbb           AS TBBUTTON             ' specifies or receives the attributes of a toolbar button
   LOCAL ttbab          AS TBADDBITMAP          ' specifies the images to add to a toolbar
   LOCAL ptnmhdr        AS NMHDR PTR            ' information about a notification message
   LOCAL ptttdi         AS NMTTDISPINFO PTR     ' tooltip notification message information
   LOCAL pttbb          AS TBBUTTON PTR         ' address of array of toolbar button info
   LOCAL hWndChild      AS DWORD                ' handle of child window
   LOCAL hFont          AS DWORD                ' handle of font used by form
   LOCAL lMsgResult     AS LONG                 ' value returned to message after message is processed
   LOCAL hImageList     AS DWORD                ' handle of imagelist control
   LOCAL hImage         AS DWORD                ' handle of bitmap

   SELECT CASE uMsg

      CASE %WM_COMMAND

         ' -------------------------------------------------------
         ' Messages from the Toolbar are handled here.
         ' ------------------------------------------------------

         SELECT CASE LOWRD(wParam)

            CASE %IDCANCEL
               IF HIWRD(wParam) = %BN_CLICKED THEN
                  SendMessage hWnd, %WM_CLOSE, wParam, lParam
                  FUNCTION = %FALSE
                  EXIT FUNCTION
               END IF

            CASE %IDM_ARROWLEFT
               MSGBOX "Arrow left button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_ARROWRIGHT
               MSGBOX "Arrow right button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_COPYCLIPBOARD
               MSGBOX "Copy to clipboard button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_COPYTOFOLDER
               MSGBOX "Copy to folder button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_CUTCLIPBOARD
               MSGBOX "Cut to clipboard button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_DELETE
               MSGBOX "Delete button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FAVORITES
               MSGBOX "Favorites button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDERCLOSED
               MSGBOX "Folder closed button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDEROPEN
               MSGBOX "Folder open button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDEROPTIONS
               MSGBOX "Folder options button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDERS
               MSGBOX "Folders button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_HISTORY
               MSGBOX "History button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_HOME
               MSGBOX "Home button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

         END SELECT

      CASE %WM_NOTIFY

         ' -------------------------------------------------------
         ' Notification messages are handled here.
         ' The TTN_GETDISPINFO message is sent by a ToolTip control
         ' to retrieve information needed to display a ToolTip window.
         ' ------------------------------------------------------
         ptnmhdr = lParam

         SELECT CASE @ptnmhdr.code
            CASE %TTN_GETDISPINFO
               ptttdi        = lParam
               @ptttdi.hinst = ghInstance

               SELECT CASE @ptttdi.hdr.hwndFrom
                  ' The TB_GETTOOLTIPS message retrieves the handle to the ToolTip control,
                  ' if any, associated with the toolbar.
                  CASE SendMessage(GetDlgItem(hWnd, %IDC_TOOLBAR), %TB_GETTOOLTIPS, 0, 0)
                     @ptttdi.lpszText = @ptttdi.hdr.idFrom
                     EXIT FUNCTION
               END SELECT
         END SELECT

      CASE %WM_SYSCOLORCHANGE
         ' Forward this message to common controls so that they will
         ' be properly updated when the user changes the color settings.
         SendMessage GetDlgItem(hWnd, %IDC_TOOLBAR), %WM_SYSCOLORCHANGE, wParam, lParam

      CASE %WM_DESTROY
         ' Destroy the image lists
         hWndChild = GetDlgItem(hWnd, %IDC_TOOLBAR)
         ImageList_Destroy SendMessage(hWndChild, %TB_SETIMAGELIST, 0, %NULL)
         ImageList_Destroy SendMessage(hWndChild, %TB_SETDISABLEDIMAGELIST, 0, %NULL)
         ImageList_Destroy SendMessage(hWndChild, %TB_SETHOTIMAGELIST, 0, %NULL)
         ' End the application
         PostQuitMessage 0
         FUNCTION = %FALSE
         EXIT FUNCTION

      CASE %WM_SIZE
         IF wParam <> %SIZE_MINIMIZED THEN
            ' Update the size and position of the Toolbar control
            SendMessage GetDlgItem(hWnd, %IDC_TOOLBAR), %TB_AUTOSIZE, 0, 0
         END IF
         FUNCTION = %FALSE
         EXIT FUNCTION

      CASE %WM_CREATE
         ' Create font used by container
         hFont = GetStockObject(%DEFAULT_GUI_FONT)

         ' Create the Toolbar1 toolbar control
         hWndChild = CreateWindowEx(%NULL, _                                              ' extended styles
                                    "ToolbarWindow32", _                                  ' class name
                                    "", _                                                 ' caption
                                    %WS_CHILD OR %WS_VISIBLE OR _                         ' window styles
                                    %CCS_TOP OR %TBSTYLE_TOOLTIPS, _                      ' class styles
                                    0, 0, _                                               ' left, top
                                    345, 116, _                                           ' width, height
                                    hWnd, %IDC_TOOLBAR, _                                 ' handle of parent, control ID
                                    ghInstance, BYVAL %NULL)                              ' handle of instance, creation parameters
         SendMessage hWndChild, %WM_SETFONT, hFont, %TRUE

         ' Set the imagelist used with default images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBNOR", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hWndChild, %TB_SETIMAGELIST, 0, hImageList

         ' Set the imagelist used with disabled images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBDIS", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hWndChild, %TB_SETDISABLEDIMAGELIST, 0, hImageList

         ' Set the imagelist used with hot images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBHOT", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hWndChild, %TB_SETHOTIMAGELIST, 0, hImageList

         ' Allocate memory for the button info array
         pttbb = HeapAlloc(GetProcessHeap(), %HEAP_ZERO_MEMORY, 13 * SIZEOF(ttbb))
         IF ISTRUE pttbb THEN
            ' Send the TB_BUTTONSTRUCTSIZE message, for backward compatibility
            SendMessage hWndChild, %TB_BUTTONSTRUCTSIZE, SIZEOF(ttbb), 0
            ' Set the size of the bitmaps
            SendMessage hWndChild, %TB_SETBITMAPSIZE, 0, MAKLNG(24, 24)
            ' Add buttons to the toolbar
            @pttbb[0].iBitmap    = 0
            @pttbb[0].idCommand  = %IDM_ARROWLEFT
            @pttbb[0].fsState    = %TBSTATE_ENABLED
            @pttbb[0].fsStyle    = %BTNS_BUTTON
            @pttbb[0].dwData     = 0
            @pttbb[0].iString    = -1

            @pttbb[1].iBitmap    = 1
            @pttbb[1].idCommand  = %IDM_ARROWRIGHT
            @pttbb[1].fsState    = 0
            @pttbb[1].fsStyle    = %BTNS_BUTTON
            @pttbb[1].dwData     = 0
            @pttbb[1].iString    = -1

            @pttbb[2].iBitmap    = 2
            @pttbb[2].idCommand  = %IDM_COPYCLIPBOARD
            @pttbb[2].fsState    = %TBSTATE_ENABLED
            @pttbb[2].fsStyle    = %BTNS_BUTTON
            @pttbb[2].dwData     = 0
            @pttbb[2].iString    = -1

            @pttbb[3].iBitmap    = 3
            @pttbb[3].idCommand  = %IDM_COPYTOFOLDER
            @pttbb[3].fsState    = %TBSTATE_ENABLED
            @pttbb[3].fsStyle    = %BTNS_BUTTON
            @pttbb[3].dwData     = 0
            @pttbb[3].iString    = -1

            @pttbb[4].iBitmap    = 4
            @pttbb[4].idCommand  = %IDM_CUTCLIPBOARD
            @pttbb[4].fsState    = %TBSTATE_ENABLED
            @pttbb[4].fsStyle    = %BTNS_BUTTON
            @pttbb[4].dwData     = 0
            @pttbb[4].iString    = -1

            @pttbb[5].iBitmap    = 5
            @pttbb[5].idCommand  = %IDM_DELETE
            @pttbb[5].fsState    = %TBSTATE_ENABLED
            @pttbb[5].fsStyle    = %BTNS_BUTTON
            @pttbb[5].dwData     = 0
            @pttbb[5].iString    = -1

            @pttbb[6].iBitmap    = 6
            @pttbb[6].idCommand  = %IDM_FAVORITES
            @pttbb[6].fsState    = %TBSTATE_ENABLED
            @pttbb[6].fsStyle    = %BTNS_BUTTON
            @pttbb[6].dwData     = 0
            @pttbb[6].iString    = -1

            @pttbb[7].iBitmap    = 7
            @pttbb[7].idCommand  = %IDM_FOLDERCLOSED
            @pttbb[7].fsState    = %TBSTATE_ENABLED
            @pttbb[7].fsStyle    = %BTNS_BUTTON
            @pttbb[7].dwData     = 0
            @pttbb[7].iString    = -1

            @pttbb[8].iBitmap    = 8
            @pttbb[8].idCommand  = %IDM_FOLDEROPEN
            @pttbb[8].fsState    = 0
            @pttbb[8].fsStyle    = %BTNS_BUTTON
            @pttbb[8].dwData     = 0
            @pttbb[8].iString    = -1

            @pttbb[9].iBitmap    = 9
            @pttbb[9].idCommand  = %IDM_FOLDEROPTIONS
            @pttbb[9].fsState    = %TBSTATE_ENABLED
            @pttbb[9].fsStyle    = %BTNS_BUTTON
            @pttbb[9].dwData     = 0
            @pttbb[9].iString    = -1

            @pttbb[10].iBitmap   = 10
            @pttbb[10].idCommand = %IDM_FOLDERS
            @pttbb[10].fsState   = %TBSTATE_ENABLED
            @pttbb[10].fsStyle   = %BTNS_BUTTON
            @pttbb[10].dwData    = 0
            @pttbb[10].iString   = -1

            @pttbb[11].iBitmap   = 11
            @pttbb[11].idCommand = %IDM_HISTORY
            @pttbb[11].fsState   = %TBSTATE_ENABLED
            @pttbb[11].fsStyle   = %BTNS_BUTTON
            @pttbb[11].dwData    = 0
            @pttbb[11].iString   = -1

            @pttbb[12].iBitmap   = 12
            @pttbb[12].idCommand = %IDM_HOME
            @pttbb[12].fsState   = %TBSTATE_ENABLED
            @pttbb[12].fsStyle   = %BTNS_BUTTON
            @pttbb[12].dwData    = 0
            @pttbb[12].iString   = -1

            SendMessage hWndChild, %TB_ADDBUTTONS, 13, BYVAL pttbb
            ' Free memory that was allocated for the button info
            HeapFree GetProcessHeap(), 0, BYVAL pttbb
            ' Update the size of the toolbar
            SendMessage hWndChild, %TB_AUTOSIZE, 0, 0
         END IF

         FUNCTION = %FALSE
         EXIT FUNCTION
   END SELECT

   FUNCTION = DefWindowProc(hWnd, uMsg, wParam, lParam)

END FUNCTION
'=========================================================================================


José Roca

#8
 
Dropdown Button

Same as above, but uses the BTNS_CHECKGROUP style in the two first buttons, the BTNS_CHECK style in the fifth button and the BTNS_DROPDOWN  style in the tenth button. To allow this last button to have a separate dropdown arrow the TBSTYLE_EX_DRAWDDARROWS extended style is set after the creation of the toolbar window:


         ' Set the extended class styles for the control
         SendMessage hWndChild, %TB_SETEXTENDEDSTYLE, 0, %TBSTYLE_EX_DRAWDDARROWS


Dropdown buttons send a TBN_DROPDOWN notification message. In the example, a popmenu is displayed during the processing of this message:


            CASE %TBN_DROPDOWN
               SELECT CASE @tbn.iItem
                  CASE %IDM_FOLDEROPTIONS
                     SendMessage(@tbn.hdr.hwndFrom, %TB_GETRECT, @tbn.iItem, VARPTR(rc))
                     MapWindowPoints(@tbn.hdr.hwndFrom, %HWND_DESKTOP, BYVAL VARPTR(rc), 2)
                     hPopupMenu = CreatePopUpMenu
                     AppendMenu hPopupMenu, %MF_ENABLED, 1, "Option 1"
                     AppendMenu hPopupMenu, %MF_ENABLED, 2, "Option 2"
                     AppendMenu hPopupMenu, %MF_ENABLED, 3, "Option 3"
                     AppendMenu hPopupMenu, %MF_ENABLED, 4, "Option 4"
                     AppendMenu hPopupMenu, %MF_ENABLED, 5, "Option 5"
                     TrackPopupMenu(hPopupMenu, 0, rc.nLeft, rc.nBottom, 0, hWnd, BYVAL %NULL)
                     DestroyMenu hPopupMenu
               END SELECT


Here is the full program listing:


'#########################################################################################
' Toolbar Control example
'#########################################################################################

#DIM ALL
#COMPILE EXE
#INCLUDE "ToolbarCtrl.inc"
#RESOURCE "EX_TOOLBAR_03.PBR"

GLOBAL   ghInstance              AS DWORD    ' handle of the application instance

'--------------------------- [ Command Identifiers ] ---------------------------

%IDM_ARROWLEFT                               = 28000
%IDM_ARROWRIGHT                              = 28001
%IDM_COPYCLIPBOARD                           = 28002
%IDM_COPYTOFOLDER                            = 28003
%IDM_CUTCLIPBOARD                            = 28004
%IDM_DELETE                                  = 28005
%IDM_FAVORITES                               = 28006
%IDM_FOLDERCLOSED                            = 28007
%IDM_FOLDEROPEN                              = 28008
%IDM_FOLDEROPTIONS                           = 28009
%IDM_FOLDERS                                 = 28010
%IDM_HISTORY                                 = 28011
%IDM_HOME                                    = 28012

'--------------------------- [ Control Identifiers ] ---------------------------

%IDC_TOOLBAR                                 = 101


'-------------------------------------------------------------------------------
'
' PROCEDURE: WinMain
' PURPOSE:   Program entry point, calls initialization function, processes
'            message loop.
'
'-------------------------------------------------------------------------------

FUNCTION WinMain _
   ( _
   BYVAL hInstance      AS DWORD, _       ' handle of current instance
   BYVAL hPrevInstance  AS DWORD, _       ' handle of previous instance(not used in Win32)
   BYVAL pszCmdLine     AS ASCIIZ PTR, _  ' address of command line
   BYVAL nCmdShow       AS LONG _         ' show state of window
   ) AS LONG

   LOCAL szClassName       AS ASCIIZ * %MAX_PATH         ' class name
   LOCAL twcx              AS WNDCLASSEX                 ' class information
   LOCAL tmsg              AS tagMsg                     ' message information
   LOCAL ticc              AS INIT_COMMON_CONTROLSEX     ' specifies common control classes to register
   LOCAL hWnd              AS DWORD                      ' handle of main window

   ' Save the handle of the application instance
   ghInstance = hInstance

   ' Register the Form1 window
   szClassName        = "EX_TOOLBAR_03"
   twcx.cbSize        = SIZEOF(twcx)                              ' size of WNDCLASSEX structure
   twcx.style         = %CS_DBLCLKS                               ' class styles
   twcx.lpfnWndProc   = CODEPTR(Form1_WndProc)                    ' address of window procedure used by class
   twcx.cbClsExtra    = 0                                         ' extra class bytes
   twcx.cbWndExtra    = 0                                         ' extra window bytes
   twcx.hInstance     = ghInstance                                ' instance of the process that is registering the window
   twcx.hIcon         = LoadIcon(%NULL, BYVAL %IDI_APPLICATION)   ' handle of class icon
   twcx.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)       ' handle of class cursor
   twcx.hbrBackground = %COLOR_BTNFACE + 1                        ' brush used to fill background of window's client area
   twcx.lpszMenuName  = %NULL                                     ' resource identifier of the class menu
   twcx.lpszClassName = VARPTR(szClassName)                       ' class name
   twcx.hIconSm       = %NULL                                     ' handle of small icon shown in caption/system Taskbar
   IF ISFALSE RegisterClassEx(twcx) THEN
      FUNCTION = %TRUE
      EXIT FUNCTION
   END IF

   ' Load the common controls library and
   ' specify the classes to register.
   ticc.dwSize = SIZEOF(ticc)
   ticc.dwICC  = %ICC_BAR_CLASSES
   InitCommonControlsEx ticc

   ' Create the Form1 window
   hWnd = CreateWindowEx(%WS_EX_WINDOWEDGE, _                                          ' extended styles
                         szClassName, _                                                ' class name
                         "Toolbar Demo", _                                             ' caption
                         %WS_OVERLAPPEDWINDOW OR %WS_VISIBLE, _                        ' window styles
                         %CW_USEDEFAULT, 0, _                                          ' left, top
                         %CW_USEDEFAULT, 0, _                                          ' width, height
                         %NULL, %NULL, _                                               ' handle of owner, menu handle
                         ghInstance, BYVAL %NULL)                                      ' handle of instance, creation parameters

   ' If window could not be created, return "failure"
   IF ISFALSE hWnd THEN
      FUNCTION = %FALSE
      EXIT FUNCTION
   END IF

   ' Make the window visible; update its client area
   ShowWindow hWnd, nCmdShow
   UpdateWindow hWnd

   ' Main message loop of program.
   ' Acquire and dispatch messages until a WM_QUIT message is received.
   WHILE ISTRUE GetMessage(tmsg, BYVAL %NULL, 0, 0)
      IF ISFALSE IsDialogMessage(hWnd, tmsg) THEN
         TranslateMessage tmsg
         DispatchMessage tmsg
      END IF
   WEND

   FUNCTION = tmsg.wParam

END FUNCTION

'-------------------------------------------------------------------------------
'
' PROCEDURE: Form1_WndProc
' PURPOSE:   Processes messages for the Form1 window.
'
'-------------------------------------------------------------------------------

FUNCTION Form1_WndProc _
   ( _
   BYVAL hWnd     AS DWORD, _ ' window handle
   BYVAL uMsg     AS DWORD, _ ' type of message
   BYVAL wParam   AS DWORD, _ ' first message parameter
   BYVAL lParam   AS LONG _   ' second message parameter
   ) EXPORT AS LONG

   LOCAL sBtnText       AS STRING               ' toolbar button caption
   LOCAL ttbb           AS TBBUTTON             ' specifies or receives the attributes of a toolbar button
   LOCAL ttbab          AS TBADDBITMAP          ' specifies the images to add to a toolbar
   LOCAL ptnmhdr        AS NMHDR PTR            ' information about a notification message
   LOCAL ptttdi         AS NMTTDISPINFO PTR     ' tooltip notification message information
   LOCAL pttbb          AS TBBUTTON PTR         ' address of array of toolbar button info
   LOCAL hWndChild      AS DWORD                ' handle of child window
   LOCAL hFont          AS DWORD                ' handle of font used by form
   LOCAL lMsgResult     AS LONG                 ' value returned to message after message is processed
   LOCAL hImageList     AS DWORD                ' handle of imagelist control
   LOCAL hImage         AS DWORD                ' handle of bitmap
   LOCAL tbn            AS TBNOTIFY PTR         ' for toolbar notification messages
   LOCAL rc             AS RECT                 ' bounding rectangle for a specified toolbar button
   LOCAL hPopupMenu     AS DWORD                ' Popmenu handle

   SELECT CASE uMsg

      CASE %WM_COMMAND

         ' -------------------------------------------------------
         ' Messages from the Toolbar are handled here.
         ' ------------------------------------------------------

         SELECT CASE LOWRD(wParam)

            CASE %IDCANCEL
               IF HIWRD(wParam) = %BN_CLICKED THEN
                  SendMessage hWnd, %WM_CLOSE, wParam, lParam
                  FUNCTION = %FALSE
                  EXIT FUNCTION
               END IF

            CASE %IDM_ARROWLEFT
               MSGBOX "Arrow left button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_ARROWRIGHT
               MSGBOX "Arrow right button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_COPYCLIPBOARD
               MSGBOX "Copy to clipboard button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_COPYTOFOLDER
               MSGBOX "Copy to folder button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_CUTCLIPBOARD
               MSGBOX "Cut to clipboard button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_DELETE
               MSGBOX "Delete button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FAVORITES
               MSGBOX "Favorites button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDERCLOSED
               MSGBOX "Folder closed button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDEROPEN
               MSGBOX "Folder open button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDEROPTIONS
               MSGBOX "Folder options button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDERS
               MSGBOX "Folders button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_HISTORY
               MSGBOX "History button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_HOME
               MSGBOX "Home button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

         END SELECT

      CASE %WM_NOTIFY

         ' -------------------------------------------------------
         ' Notification messages are handled here.
         ' The TTN_GETDISPINFO message is sent by a ToolTip control
         ' to retrieve information needed to display a ToolTip window.
         ' ------------------------------------------------------
         ptnmhdr = lParam
         tbn = lParam

         SELECT CASE @ptnmhdr.code
            CASE %TTN_GETDISPINFO
               ptttdi        = lParam
               @ptttdi.hinst = ghInstance
               SELECT CASE @ptttdi.hdr.hwndFrom
                  ' The TB_GETTOOLTIPS message retrieves the handle to the ToolTip control,
                  ' if any, associated with the toolbar.
                  CASE SendMessage(GetDlgItem(hWnd, %IDC_TOOLBAR), %TB_GETTOOLTIPS, 0, 0)
                     @ptttdi.lpszText = @ptttdi.hdr.idFrom
                     EXIT FUNCTION
               END SELECT
            CASE %TBN_DROPDOWN
               SELECT CASE @tbn.iItem
                  CASE %IDM_FOLDEROPTIONS
                     SendMessage(@tbn.hdr.hwndFrom, %TB_GETRECT, @tbn.iItem, VARPTR(rc))
                     MapWindowPoints(@tbn.hdr.hwndFrom, %HWND_DESKTOP, BYVAL VARPTR(rc), 2)
                     hPopupMenu = CreatePopUpMenu
                     AppendMenu hPopupMenu, %MF_ENABLED, 1, "Option 1"
                     AppendMenu hPopupMenu, %MF_ENABLED, 2, "Option 2"
                     AppendMenu hPopupMenu, %MF_ENABLED, 3, "Option 3"
                     AppendMenu hPopupMenu, %MF_ENABLED, 4, "Option 4"
                     AppendMenu hPopupMenu, %MF_ENABLED, 5, "Option 5"
                     TrackPopupMenu(hPopupMenu, 0, rc.nLeft, rc.nBottom, 0, hWnd, BYVAL %NULL)
                     DestroyMenu hPopupMenu
               END SELECT
         END SELECT

      CASE %WM_SYSCOLORCHANGE
         ' Forward this message to common controls so that they will
         ' be properly updated when the user changes the color settings.
         SendMessage GetDlgItem(hWnd, %IDC_TOOLBAR), %WM_SYSCOLORCHANGE, wParam, lParam

      CASE %WM_DESTROY
         ' Destroy the image lists
         hWndChild = GetDlgItem(hWnd, %IDC_TOOLBAR)
         ImageList_Destroy SendMessage(hWndChild, %TB_SETIMAGELIST, 0, %NULL)
         ImageList_Destroy SendMessage(hWndChild, %TB_SETDISABLEDIMAGELIST, 0, %NULL)
         ImageList_Destroy SendMessage(hWndChild, %TB_SETHOTIMAGELIST, 0, %NULL)
         ' End the application
         PostQuitMessage 0
         FUNCTION = %FALSE
         EXIT FUNCTION

      CASE %WM_SIZE
         IF wParam <> %SIZE_MINIMIZED THEN
            ' Update the size and position of the Toolbar control
            SendMessage GetDlgItem(hWnd, %IDC_TOOLBAR), %TB_AUTOSIZE, 0, 0
         END IF
         FUNCTION = %FALSE
         EXIT FUNCTION

      CASE %WM_CREATE
         ' Create font used by container
         hFont = GetStockObject(%DEFAULT_GUI_FONT)

         ' Create the Toolbar1 toolbar control
         hWndChild = CreateWindowEx(%NULL, _                                              ' extended styles
                                    "ToolbarWindow32", _                                  ' class name
                                    "", _                                                 ' caption
                                    %WS_CHILD OR %WS_VISIBLE OR _                         ' window styles
                                    %CCS_TOP OR %TBSTYLE_TOOLTIPS OR _
                                    %TBSTYLE_FLAT, _                                      ' class styles
                                    0, 0, _                                               ' left, top
                                    345, 116, _                                           ' width, height
                                    hWnd, %IDC_TOOLBAR, _                                 ' handle of parent, control ID
                                    ghInstance, BYVAL %NULL)                              ' handle of instance, creation parameters
         SendMessage hWndChild, %WM_SETFONT, hFont, %TRUE

         ' Set the extended class styles for the control
         SendMessage hWndChild, %TB_SETEXTENDEDSTYLE, 0, %TBSTYLE_EX_DRAWDDARROWS

         ' Set the imagelist used with default images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBNOR", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hWndChild, %TB_SETIMAGELIST, 0, hImageList

         ' Set the imagelist used with disabled images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBDIS", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hWndChild, %TB_SETDISABLEDIMAGELIST, 0, hImageList

         ' Set the imagelist used with hot images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBHOT", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hWndChild, %TB_SETHOTIMAGELIST, 0, hImageList

         ' Allocate memory for the button info array
         pttbb = HeapAlloc(GetProcessHeap(), %HEAP_ZERO_MEMORY, 16 * SIZEOF(ttbb))
         IF ISTRUE pttbb THEN
            ' Send the TB_BUTTONSTRUCTSIZE message, for backward compatibility
            SendMessage hWndChild, %TB_BUTTONSTRUCTSIZE, SIZEOF(ttbb), 0
            ' Set the size of the bitmaps
            SendMessage hWndChild, %TB_SETBITMAPSIZE, 0, MAKLNG(24, 24)
            ' Add buttons to the toolbar
            @pttbb[0].iBitmap    = 0
            @pttbb[0].idCommand  = %IDM_ARROWLEFT
            @pttbb[0].fsState    = %TBSTATE_ENABLED
            @pttbb[0].fsStyle    = %BTNS_CHECKGROUP
            @pttbb[0].dwData     = 0
            @pttbb[0].iString    = -1

            @pttbb[1].iBitmap    = 1
            @pttbb[1].idCommand  = %IDM_ARROWRIGHT
            @pttbb[1].fsState    = %TBSTATE_ENABLED
            @pttbb[1].fsStyle    = %BTNS_CHECKGROUP
            @pttbb[1].dwData     = 0
            @pttbb[1].iString    = -1

            @pttbb[2].iBitmap    = 2
            @pttbb[2].idCommand  = %IDM_COPYCLIPBOARD
            @pttbb[2].fsState    = %TBSTATE_ENABLED
            @pttbb[2].fsStyle    = %BTNS_BUTTON
            @pttbb[2].dwData     = 0
            @pttbb[2].iString    = -1

            @pttbb[3].iBitmap    = 0
            @pttbb[3].idCommand  = 0
            @pttbb[3].fsState    = %TBSTATE_ENABLED
            @pttbb[3].fsStyle    = %BTNS_SEP
            @pttbb[3].dwData     = 0
            @pttbb[3].iString    = -1

            @pttbb[4].iBitmap    = 3
            @pttbb[4].idCommand  = %IDM_COPYTOFOLDER
            @pttbb[4].fsState    = %TBSTATE_ENABLED
            @pttbb[4].fsStyle    = %BTNS_BUTTON
            @pttbb[4].dwData     = 0
            @pttbb[4].iString    = -1

            @pttbb[5].iBitmap    = 4
            @pttbb[5].idCommand  = %IDM_CUTCLIPBOARD
            @pttbb[5].fsState    = %TBSTATE_ENABLED
            @pttbb[5].fsStyle    = %BTNS_CHECK
            @pttbb[5].dwData     = 0
            @pttbb[5].iString    = -1

            @pttbb[6].iBitmap    = 5
            @pttbb[6].idCommand  = %IDM_DELETE
            @pttbb[6].fsState    = %TBSTATE_ENABLED
            @pttbb[6].fsStyle    = %BTNS_BUTTON
            @pttbb[6].dwData     = 0
            @pttbb[6].iString    = -1

            @pttbb[7].iBitmap    = 6
            @pttbb[7].idCommand  = %IDM_FAVORITES
            @pttbb[7].fsState    = %TBSTATE_ENABLED
            @pttbb[7].fsStyle    = %BTNS_BUTTON
            @pttbb[7].dwData     = 0
            @pttbb[7].iString    = -1

            @pttbb[8].iBitmap    = 0
            @pttbb[8].idCommand  = 0
            @pttbb[8].fsState    = %TBSTATE_ENABLED
            @pttbb[8].fsStyle    = %BTNS_SEP
            @pttbb[8].dwData     = 0
            @pttbb[8].iString    = -1

            @pttbb[9].iBitmap    = 7
            @pttbb[9].idCommand  = %IDM_FOLDERCLOSED
            @pttbb[9].fsState    = %TBSTATE_ENABLED
            @pttbb[9].fsStyle    = %BTNS_BUTTON
            @pttbb[9].dwData     = 0
            @pttbb[9].iString    = -1

            @pttbb[10].iBitmap    = 8
            @pttbb[10].idCommand  = %IDM_FOLDEROPEN
            @pttbb[10].fsState    = %TBSTATE_ENABLED
            @pttbb[10].fsStyle    = %BTNS_BUTTON
            @pttbb[10].dwData     = 0
            @pttbb[10].iString    = -1

            @pttbb[11].iBitmap    = 9
            @pttbb[11].idCommand  = %IDM_FOLDEROPTIONS
            @pttbb[11].fsState    = %TBSTATE_ENABLED
            @pttbb[11].fsStyle    = %BTNS_DROPDOWN
            @pttbb[11].dwData     = 0
            @pttbb[11].iString    = -1

            @pttbb[12].iBitmap   = 10
            @pttbb[12].idCommand = %IDM_FOLDERS
            @pttbb[12].fsState   = %TBSTATE_ENABLED
            @pttbb[12].fsStyle   = %BTNS_BUTTON
            @pttbb[12].dwData    = 0
            @pttbb[12].iString   = -1

            @pttbb[13].iBitmap    = 0
            @pttbb[13].idCommand  = 0
            @pttbb[13].fsState    = %TBSTATE_ENABLED
            @pttbb[13].fsStyle    = %BTNS_SEP
            @pttbb[13].dwData     = 0
            @pttbb[13].iString    = -1

            @pttbb[14].iBitmap   = 11
            @pttbb[14].idCommand = %IDM_HISTORY
            @pttbb[14].fsState   = %TBSTATE_ENABLED
            @pttbb[14].fsStyle   = %BTNS_BUTTON
            @pttbb[14].dwData    = 0
            @pttbb[14].iString   = -1

            @pttbb[15].iBitmap   = 12
            @pttbb[15].idCommand = %IDM_HOME
            @pttbb[15].fsState   = %TBSTATE_ENABLED
            @pttbb[15].fsStyle   = %BTNS_BUTTON
            @pttbb[15].dwData    = 0
            @pttbb[15].iString   = -1

            SendMessage hWndChild, %TB_ADDBUTTONS, 16, BYVAL pttbb
            ' Free memory that was allocated for the button info
            HeapFree GetProcessHeap(), 0, BYVAL pttbb
            ' Update the size of the toolbar
            SendMessage hWndChild, %TB_AUTOSIZE, 0, 0
         END IF

         FUNCTION = %FALSE
         EXIT FUNCTION
   END SELECT

   FUNCTION = DefWindowProc(hWnd, uMsg, wParam, lParam)

END FUNCTION
'=========================================================================================


José Roca

#9
 
Floating Toolbar Demo

This example registers a class called "FLOATINGTOOLBAR" that will be used to create a container window for the Toolbar. Idea taken from an example posted by Jules Marchildon in the PowerBASIC Forums: Floating Toolbar Demo


'#########################################################################################
' Toolbar Control example
'#########################################################################################

#DIM ALL
#COMPILE EXE
#INCLUDE ONCE "ToolbarCtrl.inc"
#RESOURCE "EX_TOOLBAR_04.PBR"

GLOBAL   ghInstance              AS DWORD    ' handle of the application instance

'--------------------------- [ Command Identifiers ] ---------------------------

%IDM_ARROWLEFT                               = 28000
%IDM_ARROWRIGHT                              = 28001
%IDM_COPYCLIPBOARD                           = 28002
%IDM_COPYTOFOLDER                            = 28003
%IDM_CUTCLIPBOARD                            = 28004
%IDM_DELETE                                  = 28005
%IDM_FAVORITES                               = 28006
%IDM_FOLDERCLOSED                            = 28007
%IDM_FOLDEROPEN                              = 28008
%IDM_FOLDEROPTIONS                           = 28009
%IDM_FOLDERS                                 = 28010
%IDM_HISTORY                                 = 28011
%IDM_HOME                                    = 28012
%IDM_MAIL                                    = 28013

'--------------------------- [ Control Identifiers ] ---------------------------

%IDC_TOOLBAR                                 = 101


'-------------------------------------------------------------------------------
'
' PROCEDURE: WinMain
' PURPOSE:   Program entry point, calls initialization function, processes
'            message loop.
'
'-------------------------------------------------------------------------------

FUNCTION WinMain _
   ( _
   BYVAL hInstance      AS DWORD, _       ' handle of current instance
   BYVAL hPrevInstance  AS DWORD, _       ' handle of previous instance(not used in Win32)
   BYVAL pszCmdLine     AS ASCIIZ PTR, _  ' address of command line
   BYVAL nCmdShow       AS LONG _         ' show state of window
   ) AS LONG

   LOCAL szClassName        AS ASCIIZ * %MAX_PATH         ' class name
   LOCAL szToolbarClassName AS ASCIIZ * %MAX_PATH         ' class name
   LOCAL twcx               AS WNDCLASSEX                 ' class information
   LOCAL tmsg               AS tagMsg                     ' message information
   LOCAL ticc               AS INIT_COMMON_CONTROLSEX     ' specifies common control classes to register
   LOCAL hWnd               AS DWORD                      ' handle of main window

   ' Save the handle of the application instance
   ghInstance = hInstance

   ' Register the main window
   szClassName        = "EX_TOOLBAR_03"
   twcx.cbSize        = SIZEOF(twcx)                              ' size of WNDCLASSEX structure
   twcx.style         = %CS_DBLCLKS                               ' class styles
   twcx.lpfnWndProc   = CODEPTR(WndProc)                          ' address of window procedure used by class
   twcx.cbClsExtra    = 0                                         ' extra class bytes
   twcx.cbWndExtra    = 0                                         ' extra window bytes
   twcx.hInstance     = ghInstance                                ' instance of the process that is registering the window
   twcx.hIcon         = LoadIcon(%NULL, BYVAL %IDI_APPLICATION)   ' handle of class icon
   twcx.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)       ' handle of class cursor
   twcx.hbrBackground = %COLOR_BTNFACE + 1                        ' brush used to fill background of window's client area
   twcx.lpszMenuName  = %NULL                                     ' resource identifier of the class menu
   twcx.lpszClassName = VARPTR(szClassName)                       ' class name
   twcx.hIconSm       = %NULL                                     ' handle of small icon shown in caption/system Taskbar
   IF ISFALSE RegisterClassEx(twcx) THEN
      FUNCTION = %TRUE
      EXIT FUNCTION
   END IF

   ' Register Floating toolbar window
   szToolbarClassName = "FLOATINGTOOLBAR"
   twcx.cbSize        = SIZEOF(twcx)                              ' size of WNDCLASSEX structure
   twcx.style         = %CS_DBLCLKS                               ' class styles
   twcx.lpfnWndProc   = CODEPTR(FloatProc)                        ' address of window procedure used by class
   twcx.cbClsExtra    = 0                                         ' extra class bytes
   twcx.cbWndExtra    = 0                                         ' extra window bytes
   twcx.hInstance     = ghInstance                                ' instance of the process that is registering the window
   twcx.hIcon         = LoadIcon(%NULL, BYVAL %IDI_APPLICATION)   ' handle of class icon
   twcx.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)       ' handle of class cursor
   twcx.hbrBackground = %COLOR_BTNFACE + 1                        ' brush used to fill background of window's client area
   twcx.lpszMenuName  = %NULL                                     ' resource identifier of the class menu
   twcx.lpszClassName = VARPTR(szToolbarClassName)                ' class name
   twcx.hIconSm       = %NULL                                     ' handle of small icon shown in caption/system Taskbar
   IF ISFALSE RegisterClassEx(twcx) THEN
      FUNCTION = %TRUE
      EXIT FUNCTION
   END IF

   ' Load the common controls library and
   ' specify the classes to register.
   ticc.dwSize = SIZEOF(ticc)
   ticc.dwICC  = %ICC_BAR_CLASSES
   InitCommonControlsEx ticc

   ' Create the Form1 window
   hWnd = CreateWindowEx(%WS_EX_WINDOWEDGE, _                                          ' extended styles
                         szClassName, _                                                ' class name
                         "Floating Toolbar Demo", _                                    ' caption
                         %WS_OVERLAPPEDWINDOW OR %WS_VISIBLE, _                        ' window styles
                         %CW_USEDEFAULT, 0, _                                          ' left, top
                         %CW_USEDEFAULT, 0, _                                          ' width, height
                         %NULL, %NULL, _                                               ' handle of owner, menu handle
                         ghInstance, BYVAL %NULL)                                      ' handle of instance, creation parameters

   ' If window could not be created, return "failure"
   IF ISFALSE hWnd THEN
      FUNCTION = %FALSE
      EXIT FUNCTION
   END IF

   ' Make the window visible; update its client area
   ShowWindow hWnd, nCmdShow
   UpdateWindow hWnd

   ' Main message loop of program.
   ' Acquire and dispatch messages until a WM_QUIT message is received.
   WHILE ISTRUE GetMessage(tmsg, BYVAL %NULL, 0, 0)
      IF ISFALSE IsDialogMessage(hWnd, tmsg) THEN
         TranslateMessage tmsg
         DispatchMessage tmsg
      END IF
   WEND

   FUNCTION = tmsg.wParam

END FUNCTION

'-------------------------------------------------------------------------------
'
' PROCEDURE: WndProc
' PURPOSE:   Processes messages for the Form1 window.
'
'-------------------------------------------------------------------------------

FUNCTION WndProc _
   ( _
   BYVAL hWnd     AS DWORD, _ ' window handle
   BYVAL uMsg     AS DWORD, _ ' type of message
   BYVAL wParam   AS DWORD, _ ' first message parameter
   BYVAL lParam   AS LONG _   ' second message parameter
   ) EXPORT AS LONG

   LOCAL sBtnText       AS STRING               ' toolbar button caption
   LOCAL ttbb           AS TBBUTTON             ' specifies or receives the attributes of a toolbar button
   LOCAL ttbab          AS TBADDBITMAP          ' specifies the images to add to a toolbar
   LOCAL ptnmhdr        AS NMHDR PTR            ' information about a notification message
   LOCAL ptttdi         AS NMTTDISPINFO PTR     ' tooltip notification message information
   LOCAL pttbb          AS TBBUTTON PTR         ' address of array of toolbar button info
   LOCAL hWndToolbar    AS DWORD                ' handle of the parent toolbar window
   LOCAL hWndChild      AS DWORD                ' handle of child window
   LOCAL hFont          AS DWORD                ' handle of font used by form
   LOCAL lMsgResult     AS LONG                 ' value returned to message after message is processed
   LOCAL hImageList     AS DWORD                ' handle of imagelist control
   LOCAL hImage         AS DWORD                ' handle of bitmap

   SELECT CASE uMsg

      CASE %WM_COMMAND

         SELECT CASE LOWRD(wParam)

            CASE %IDCANCEL
               IF HIWRD(wParam) = %BN_CLICKED THEN
                  SendMessage hWnd, %WM_CLOSE, wParam, lParam
                  FUNCTION = %FALSE
                  EXIT FUNCTION
               END IF

         END SELECT

      CASE %WM_SYSCOLORCHANGE
         ' Forward this message to common controls so that they will
         ' be properly updated when the user changes the color settings.
         SendMessage GetDlgItem(hWnd, %IDC_TOOLBAR), %WM_SYSCOLORCHANGE, wParam, lParam

      CASE %WM_DESTROY
         ' Destroy the image lists
         hWndChild = GetDlgItem(hWnd, %IDC_TOOLBAR)
         ImageList_Destroy SendMessage(hWndChild, %TB_SETIMAGELIST, 0, %NULL)
         ImageList_Destroy SendMessage(hWndChild, %TB_SETDISABLEDIMAGELIST, 0, %NULL)
         ImageList_Destroy SendMessage(hWndChild, %TB_SETHOTIMAGELIST, 0, %NULL)
         ' End the application
         PostQuitMessage 0
         FUNCTION = %FALSE
         EXIT FUNCTION

      CASE %WM_CREATE
         ' Create font used by container
         hFont = GetStockObject(%DEFAULT_GUI_FONT)

         ' Create a floating toobar window
         hWndToolbar = CreateWindowEx (%WS_EX_TOOLWINDOW OR %WS_EX_WINDOWEDGE, _
                                       "FLOATINGTOOLBAR", _
                                       "ToolBar", BYVAL %NULL, _
                                       500, 150, 68, 240,_
                                       hWnd, BYVAL %NULL, ghInstance, BYVAL %NULL)
         SendMessage hWndToolbar, %WM_SETFONT, hFont, %TRUE

         ShowWindow hWndToolbar, %SW_SHOW
         UpdateWindow hWndToolbar

         ' Create the toolbar control
         hWndChild = CreateWindowEx(%NULL, _                                              ' extended styles
                                    "ToolbarWindow32", _                                  ' class name
                                    "", _                                                 ' caption
                                    %WS_CHILD OR %WS_VISIBLE OR _                         ' window styles
                                    %CCS_TOP OR %TBSTYLE_TOOLTIPS OR _
                                    %TBSTYLE_WRAPABLE, _                                  ' class styles
                                    0, 0, _                                               ' left, top
                                    0, 0, _                                               ' width, height
                                    hWndToolbar, %IDC_TOOLBAR, _                          ' handle of parent, control ID
                                    ghInstance, BYVAL %NULL)                              ' handle of instance, creation parameters

         ' Set the imagelist used with default images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBNOR", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hWndChild, %TB_SETIMAGELIST, 0, hImageList

         ' Set the imagelist used with disabled images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBDIS", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hWndChild, %TB_SETDISABLEDIMAGELIST, 0, hImageList

         ' Set the imagelist used with hot images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBHOT", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hWndChild, %TB_SETHOTIMAGELIST, 0, hImageList

         ' Allocate memory for the button info array
         pttbb = HeapAlloc(GetProcessHeap(), %HEAP_ZERO_MEMORY, 14 * SIZEOF(ttbb))
         IF ISTRUE pttbb THEN
            ' Send the TB_BUTTONSTRUCTSIZE message, for backward compatibility
            SendMessage hWndChild, %TB_BUTTONSTRUCTSIZE, SIZEOF(ttbb), 0
            ' Set the size of the bitmaps
            SendMessage hWndChild, %TB_SETBITMAPSIZE, 0, MAKLNG(24, 24)
            ' Add buttons to the toolbar
            @pttbb[0].iBitmap    = 0
            @pttbb[0].idCommand  = %IDM_ARROWLEFT
            @pttbb[0].fsState    = %TBSTATE_ENABLED
            @pttbb[0].fsStyle    = %BTNS_BUTTON
            @pttbb[0].dwData     = 0
            @pttbb[0].iString    = -1

            @pttbb[1].iBitmap    = 1
            @pttbb[1].idCommand  = %IDM_ARROWRIGHT
            @pttbb[1].fsState    = 0
            @pttbb[1].fsStyle    = %BTNS_BUTTON
            @pttbb[1].dwData     = 0
            @pttbb[1].iString    = -1

            @pttbb[2].iBitmap    = 2
            @pttbb[2].idCommand  = %IDM_COPYCLIPBOARD
            @pttbb[2].fsState    = %TBSTATE_ENABLED
            @pttbb[2].fsStyle    = %BTNS_BUTTON
            @pttbb[2].dwData     = 0
            @pttbb[2].iString    = -1

            @pttbb[3].iBitmap    = 3
            @pttbb[3].idCommand  = %IDM_COPYTOFOLDER
            @pttbb[3].fsState    = %TBSTATE_ENABLED
            @pttbb[3].fsStyle    = %BTNS_BUTTON
            @pttbb[3].dwData     = 0
            @pttbb[3].iString    = -1

            @pttbb[4].iBitmap    = 4
            @pttbb[4].idCommand  = %IDM_CUTCLIPBOARD
            @pttbb[4].fsState    = %TBSTATE_ENABLED
            @pttbb[4].fsStyle    = %BTNS_BUTTON
            @pttbb[4].dwData     = 0
            @pttbb[4].iString    = -1

            @pttbb[5].iBitmap    = 5
            @pttbb[5].idCommand  = %IDM_DELETE
            @pttbb[5].fsState    = %TBSTATE_ENABLED
            @pttbb[5].fsStyle    = %BTNS_BUTTON
            @pttbb[5].dwData     = 0
            @pttbb[5].iString    = -1

            @pttbb[6].iBitmap    = 6
            @pttbb[6].idCommand  = %IDM_FAVORITES
            @pttbb[6].fsState    = %TBSTATE_ENABLED
            @pttbb[6].fsStyle    = %BTNS_BUTTON
            @pttbb[6].dwData     = 0
            @pttbb[6].iString    = -1

            @pttbb[7].iBitmap    = 7
            @pttbb[7].idCommand  = %IDM_FOLDERCLOSED
            @pttbb[7].fsState    = %TBSTATE_ENABLED
            @pttbb[7].fsStyle    = %BTNS_BUTTON
            @pttbb[7].dwData     = 0
            @pttbb[7].iString    = -1

            @pttbb[8].iBitmap    = 8
            @pttbb[8].idCommand  = %IDM_FOLDEROPEN
            @pttbb[8].fsState    = 0
            @pttbb[8].fsStyle    = %BTNS_BUTTON
            @pttbb[8].dwData     = 0
            @pttbb[8].iString    = -1

            @pttbb[9].iBitmap    = 9
            @pttbb[9].idCommand  = %IDM_FOLDEROPTIONS
            @pttbb[9].fsState    = %TBSTATE_ENABLED
            @pttbb[9].fsStyle    = %BTNS_BUTTON
            @pttbb[9].dwData     = 0
            @pttbb[9].iString    = -1

            @pttbb[10].iBitmap   = 10
            @pttbb[10].idCommand = %IDM_FOLDERS
            @pttbb[10].fsState   = %TBSTATE_ENABLED
            @pttbb[10].fsStyle   = %BTNS_BUTTON
            @pttbb[10].dwData    = 0
            @pttbb[10].iString   = -1

            @pttbb[11].iBitmap   = 11
            @pttbb[11].idCommand = %IDM_HISTORY
            @pttbb[11].fsState   = %TBSTATE_ENABLED
            @pttbb[11].fsStyle   = %BTNS_BUTTON
            @pttbb[11].dwData    = 0
            @pttbb[11].iString   = -1

            @pttbb[12].iBitmap   = 12
            @pttbb[12].idCommand = %IDM_HOME
            @pttbb[12].fsState   = %TBSTATE_ENABLED
            @pttbb[12].fsStyle   = %BTNS_BUTTON
            @pttbb[12].dwData    = 0
            @pttbb[12].iString   = -1

            @pttbb[13].iBitmap   = 16
            @pttbb[13].idCommand = %IDM_MAIL
            @pttbb[13].fsState   = %TBSTATE_ENABLED
            @pttbb[13].fsStyle   = %BTNS_BUTTON
            @pttbb[13].dwData    = 0
            @pttbb[13].iString   = -1

            SendMessage hWndChild, %TB_ADDBUTTONS, 14, BYVAL pttbb
            ' Free memory that was allocated for the button info
            HeapFree GetProcessHeap(), 0, BYVAL pttbb
            ' Update the size of the toolbar
            SendMessage hWndChild, %TB_AUTOSIZE, 0, 0
         END IF

         FUNCTION = %FALSE
         EXIT FUNCTION
   END SELECT

   FUNCTION = DefWindowProc(hWnd, uMsg, wParam, lParam)

END FUNCTION
'=========================================================================================

'-------------------------------------------------------------------------------
'
' PROCEDURE: FloatProc
' PURPOSE:   Processes messages for the Toolbar window.
'
'-------------------------------------------------------------------------------

FUNCTION FloatProc _
   ( _
   BYVAL hWnd     AS DWORD, _ ' window handle
   BYVAL uMsg     AS DWORD, _ ' type of message
   BYVAL wParam   AS DWORD, _ ' first message parameter
   BYVAL lParam   AS LONG _   ' second message parameter
   ) EXPORT AS LONG

   LOCAL ptnmhdr        AS NMHDR PTR            ' information about a notification message
   LOCAL ptttdi         AS NMTTDISPINFO PTR     ' tooltip notification message information
   LOCAL pttbb          AS TBBUTTON PTR         ' address of array of toolbar button info

   SELECT CASE uMsg

      CASE %WM_COMMAND

         ' -------------------------------------------------------
         ' Messages from the Toolbar are handled here.
         ' ------------------------------------------------------

         SELECT CASE LOWRD(wParam)

            CASE %IDCANCEL
               IF HIWRD(wParam) = %BN_CLICKED THEN
                  SendMessage hWnd, %WM_CLOSE, wParam, lParam
                  FUNCTION = %FALSE
                  EXIT FUNCTION
               END IF

            CASE %IDM_ARROWLEFT
               MSGBOX "Arrow left button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_ARROWRIGHT
               MSGBOX "Arrow right button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_COPYCLIPBOARD
               MSGBOX "Copy to clipboard button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_COPYTOFOLDER
               MSGBOX "Copy to folder button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_CUTCLIPBOARD
               MSGBOX "Cut to clipboard button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_DELETE
               MSGBOX "Delete button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FAVORITES
               MSGBOX "Favorites button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDERCLOSED
               MSGBOX "Folder closed button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDEROPEN
               MSGBOX "Folder open button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDEROPTIONS
               MSGBOX "Folder options button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDERS
               MSGBOX "Folders button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_HISTORY
               MSGBOX "History button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_HOME
               MSGBOX "Home button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_MAIL
               MSGBOX "Mail button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

         END SELECT

      CASE %WM_NOTIFY

         ' -------------------------------------------------------
         ' Notification messages are handled here.
         ' The TTN_GETDISPINFO message is sent by a ToolTip control
         ' to retrieve information needed to display a ToolTip window.
         ' ------------------------------------------------------
         ptnmhdr = lParam

         SELECT CASE @ptnmhdr.code
            CASE %TTN_GETDISPINFO
               ptttdi        = lParam
               @ptttdi.hinst = ghInstance

               SELECT CASE @ptttdi.hdr.hwndFrom
                  ' The TB_GETTOOLTIPS message retrieves the handle to the ToolTip control,
                  ' if any, associated with the toolbar.
                  CASE SendMessage(GetDlgItem(hWnd, %IDC_TOOLBAR), %TB_GETTOOLTIPS, 0, 0)
                     @ptttdi.lpszText = @ptttdi.hdr.idFrom
                     EXIT FUNCTION
               END SELECT
         END SELECT

   END SELECT

   FUNCTION = DefWindowProc(hWnd, uMsg, wParam, lParam)

END FUNCTION
'=========================================================================================


José Roca

#10
 
Vertical Toolbar Demo

To create a vertical toolbar we need to use the CCS_NORESIZE and TBSTYLE_WRAPABLE styles when creating the control. Adding the TBSTYLE_FLAT and WS_TABSTOP styles makes the toolbar navigable using the arrow keys.


         hWndChild = CreateWindowEx(%NULL, _                                              ' extended styles
                                    "ToolbarWindow32", _                                  ' class name
                                    "", _                                                 ' caption
                                    %WS_CHILD OR %WS_VISIBLE OR _                         ' window styles
                                    %CCS_NORESIZE OR %CCS_NODIVIDER OR _                  ' class styles
                                    %TBSTYLE_TOOLTIPS OR %TBSTYLE_WRAPABLE OR _
                                    %TBSTYLE_FLAT OR %WS_TABSTOP, _
                                    2, 0, _                                               ' left, top
                                    51, 362, _                                            ' width, height
                                    hWnd, %IDC_TOOLBAR, _                                 ' handle of parent, control ID
                                    ghInstance, BYVAL %NULL)                              ' handle of instance, creation parameters


And then set the number of rows sending the TB_SETROWS message:


            ' Set the number of rows
            SendMessage hWndChild, %TB_SETROWS, MAKDWD(12, %FALSE), BYVAL VARPTR(trc)



'#########################################################################################
' Toolbar Control example
'#########################################################################################

#DIM ALL
#COMPILE EXE
#INCLUDE ONCE "ToolbarCtrl.inc"
#RESOURCE "EX_TOOLBAR_05.PBR"

GLOBAL   ghInstance              AS DWORD    ' handle of the application instance

'--------------------------- [ Command Identifiers ] ---------------------------

%IDM_ARROWLEFT                               = 28000
%IDM_ARROWRIGHT                              = 28001
%IDM_COPYCLIPBOARD                           = 28002
%IDM_COPYTOFOLDER                            = 28003
%IDM_CUTCLIPBOARD                            = 28004
%IDM_DELETE                                  = 28005
%IDM_FAVORITES                               = 28006
%IDM_FOLDERCLOSED                            = 28007
%IDM_FOLDEROPEN                              = 28008
%IDM_FOLDEROPTIONS                           = 28009
%IDM_FOLDERS                                 = 28010
%IDM_HISTORY                                 = 28011
%IDM_HOME                                    = 28012

'--------------------------- [ Control Identifiers ] ---------------------------

%IDC_TOOLBAR                                 = 101


'-------------------------------------------------------------------------------
'
' PROCEDURE: WinMain
' PURPOSE:   Program entry point, calls initialization function, processes
'            message loop.
'
'-------------------------------------------------------------------------------

FUNCTION WinMain _
   ( _
   BYVAL hInstance      AS DWORD, _       ' handle of current instance
   BYVAL hPrevInstance  AS DWORD, _       ' handle of previous instance(not used in Win32)
   BYVAL pszCmdLine     AS ASCIIZ PTR, _  ' address of command line
   BYVAL nCmdShow       AS LONG _         ' show state of window
   ) AS LONG

   LOCAL szClassName       AS ASCIIZ * %MAX_PATH         ' class name
   LOCAL twcx              AS WNDCLASSEX                 ' class information
   LOCAL tmsg              AS tagMsg                     ' message information
   LOCAL ticc              AS INIT_COMMON_CONTROLSEX     ' specifies common control classes to register
   LOCAL hWnd              AS DWORD                      ' handle of main window

   ' Save the handle of the application instance
   ghInstance = hInstance

   ' Register the main window
   szClassName        = "EX_TOOLBAR_05"
   twcx.cbSize        = SIZEOF(twcx)                              ' size of WNDCLASSEX structure
   twcx.style         = %CS_DBLCLKS                               ' class styles
   twcx.lpfnWndProc   = CODEPTR(WndProc)                          ' address of window procedure used by class
   twcx.cbClsExtra    = 0                                         ' extra class bytes
   twcx.cbWndExtra    = 0                                         ' extra window bytes
   twcx.hInstance     = ghInstance                                ' instance of the process that is registering the window
   twcx.hIcon         = LoadIcon(%NULL, BYVAL %IDI_APPLICATION)   ' handle of class icon
   twcx.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)       ' handle of class cursor
   twcx.hbrBackground = %COLOR_BTNFACE + 1                        ' brush used to fill background of window's client area
   twcx.lpszMenuName  = %NULL                                     ' resource identifier of the class menu
   twcx.lpszClassName = VARPTR(szClassName)                       ' class name
   twcx.hIconSm       = %NULL                                     ' handle of small icon shown in caption/system Taskbar
   IF ISFALSE RegisterClassEx(twcx) THEN
      FUNCTION = %TRUE
      EXIT FUNCTION
   END IF

   ' Load the common controls library and
   ' specify the classes to register.
   ticc.dwSize = SIZEOF(ticc)
   ticc.dwICC  = %ICC_BAR_CLASSES
   InitCommonControlsEx ticc

   ' Create the Form1 window
   hWnd = CreateWindowEx(%WS_EX_WINDOWEDGE, _                                          ' extended styles
                         szClassName, _                                                ' class name
                         "Vertical Toolbar Demo", _                                    ' caption
                         %WS_OVERLAPPEDWINDOW OR %WS_VISIBLE, _                        ' window styles
                         %CW_USEDEFAULT, 0, _                                          ' left, top
                         %CW_USEDEFAULT, 0, _                                          ' width, height
                         %NULL, %NULL, _                                               ' handle of owner, menu handle
                         ghInstance, BYVAL %NULL)                                      ' handle of instance, creation parameters

   ' If window could not be created, return "failure"
   IF ISFALSE hWnd THEN
      FUNCTION = %FALSE
      EXIT FUNCTION
   END IF

   ' Make the window visible; update its client area
   ShowWindow hWnd, nCmdShow
   UpdateWindow hWnd

   ' Main message loop of program.
   ' Acquire and dispatch messages until a WM_QUIT message is received.
   WHILE ISTRUE GetMessage(tmsg, BYVAL %NULL, 0, 0)
      IF ISFALSE IsDialogMessage(hWnd, tmsg) THEN
         TranslateMessage tmsg
         DispatchMessage tmsg
      END IF
   WEND

   FUNCTION = tmsg.wParam

END FUNCTION

'-------------------------------------------------------------------------------
'
' PROCEDURE: WndProc
' PURPOSE:   Processes messages for the Form1 window.
'
'-------------------------------------------------------------------------------

FUNCTION WndProc _
   ( _
   BYVAL hWnd     AS DWORD, _ ' window handle
   BYVAL uMsg     AS DWORD, _ ' type of message
   BYVAL wParam   AS DWORD, _ ' first message parameter
   BYVAL lParam   AS LONG _   ' second message parameter
   ) EXPORT AS LONG

   LOCAL sBtnText       AS STRING               ' toolbar button caption
   LOCAL ttbb           AS TBBUTTON             ' specifies or receives the attributes of a toolbar button
   LOCAL ttbab          AS TBADDBITMAP          ' specifies the images to add to a toolbar
   LOCAL trc            AS RECT                 ' bounding or formatting rectangle
   LOCAL ptnmhdr        AS NMHDR PTR            ' information about a notification message
   LOCAL ptttdi         AS NMTTDISPINFO PTR     ' tooltip notification message information
   LOCAL pttbb          AS TBBUTTON PTR         ' address of array of toolbar button info
   LOCAL hWndChild      AS DWORD                ' handle of child window
   LOCAL hFont          AS DWORD                ' handle of font used by form
   LOCAL lMsgResult     AS LONG                 ' value returned to message after message is processed
   LOCAL hImageList     AS DWORD                ' handle of imagelist control
   LOCAL hImage         AS DWORD                ' handle of bitmap

   SELECT CASE uMsg

      CASE %WM_COMMAND

         ' -------------------------------------------------------
         ' Messages from the Toolbar are handled here.
         ' ------------------------------------------------------

         SELECT CASE LOWRD(wParam)

            CASE %IDCANCEL
               IF HIWRD(wParam) = %BN_CLICKED THEN
                  SendMessage hWnd, %WM_CLOSE, wParam, lParam
                  FUNCTION = %FALSE
                  EXIT FUNCTION
               END IF

            CASE %IDM_ARROWLEFT
               MSGBOX "Arrow left button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_ARROWRIGHT
               MSGBOX "Arrow right button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_COPYCLIPBOARD
               MSGBOX "Copy to clipboard button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_COPYTOFOLDER
               MSGBOX "Copy to folder button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_CUTCLIPBOARD
               MSGBOX "Cut to clipboard button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_DELETE
               MSGBOX "Delete button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FAVORITES
               MSGBOX "Favorites button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDERCLOSED
               MSGBOX "Folder closed button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDEROPEN
               MSGBOX "Folder open button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDEROPTIONS
               MSGBOX "Folder options button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDERS
               MSGBOX "Folders button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_HISTORY
               MSGBOX "History button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_HOME
               MSGBOX "Home button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

         END SELECT

      CASE %WM_NOTIFY

         ' -------------------------------------------------------
         ' Notification messages are handled here.
         ' The TTN_GETDISPINFO message is sent by a ToolTip control
         ' to retrieve information needed to display a ToolTip window.
         ' ------------------------------------------------------
         ptnmhdr = lParam

         SELECT CASE @ptnmhdr.code
            CASE %TTN_GETDISPINFO
               ptttdi        = lParam
               @ptttdi.hinst = ghInstance

               SELECT CASE @ptttdi.hdr.hwndFrom
                  ' The TB_GETTOOLTIPS message retrieves the handle to the ToolTip control,
                  ' if any, associated with the toolbar.
                  CASE SendMessage(GetDlgItem(hWnd, %IDC_TOOLBAR), %TB_GETTOOLTIPS, 0, 0)
                     @ptttdi.lpszText = @ptttdi.hdr.idFrom
                     EXIT FUNCTION
               END SELECT
         END SELECT

      CASE %WM_SYSCOLORCHANGE
         ' Forward this message to common controls so that they will
         ' be properly updated when the user changes the color settings.
         SendMessage GetDlgItem(hWnd, %IDC_TOOLBAR), %WM_SYSCOLORCHANGE, wParam, lParam

      CASE %WM_DESTROY
         ' Destroy the image lists
         hWndChild = GetDlgItem(hWnd, %IDC_TOOLBAR)
         ImageList_Destroy SendMessage(hWndChild, %TB_SETIMAGELIST, 0, %NULL)
         ImageList_Destroy SendMessage(hWndChild, %TB_SETDISABLEDIMAGELIST, 0, %NULL)
         ImageList_Destroy SendMessage(hWndChild, %TB_SETHOTIMAGELIST, 0, %NULL)
         ' End the application
         PostQuitMessage 0
         FUNCTION = %FALSE
         EXIT FUNCTION

      CASE %WM_SIZE
         IF wParam <> %SIZE_MINIMIZED THEN
            ' Update the size and position of the Toolbar control
            SendMessage GetDlgItem(hWnd, %IDC_TOOLBAR), %TB_AUTOSIZE, 0, 0
         END IF
         FUNCTION = %FALSE
         EXIT FUNCTION

      CASE %WM_CREATE
         ' Create font used by container
         hFont = GetStockObject(%DEFAULT_GUI_FONT)

         ' Create the toolbar control
         hWndChild = CreateWindowEx(%NULL, _                                              ' extended styles
                                    "ToolbarWindow32", _                                  ' class name
                                    "", _                                                 ' caption
                                    %WS_CHILD OR %WS_VISIBLE OR _                         ' window styles
                                    %CCS_NORESIZE OR %CCS_NODIVIDER OR _                  ' class styles
                                    %TBSTYLE_TOOLTIPS OR %TBSTYLE_WRAPABLE OR _
                                    %TBSTYLE_FLAT OR %WS_TABSTOP, _
                                    2, 0, _                                               ' left, top
                                    51, 362, _                                            ' width, height
                                    hWnd, %IDC_TOOLBAR, _                                 ' handle of parent, control ID
                                    ghInstance, BYVAL %NULL)                              ' handle of instance, creation parameters
         SendMessage hWndChild, %WM_SETFONT, hFont, %TRUE

         ' Set the imagelist used with default images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBNOR", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hWndChild, %TB_SETIMAGELIST, 0, hImageList

         ' Set the imagelist used with disabled images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBDIS", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hWndChild, %TB_SETDISABLEDIMAGELIST, 0, hImageList

         ' Set the imagelist used with hot images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBHOT", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hWndChild, %TB_SETHOTIMAGELIST, 0, hImageList

         ' Allocate memory for the button info array
         pttbb = HeapAlloc(GetProcessHeap(), %HEAP_ZERO_MEMORY, 12 * SIZEOF(ttbb))
         IF ISTRUE pttbb THEN
            ' Send the TB_BUTTONSTRUCTSIZE message, for backward compatibility
            SendMessage hWndChild, %TB_BUTTONSTRUCTSIZE, SIZEOF(ttbb), 0
            ' Set the size of the bitmaps
            SendMessage hWndChild, %TB_SETBITMAPSIZE, 0, MAKLNG(24, 24)
            ' Add buttons to the toolbar
            @pttbb[0].iBitmap    = 0
            @pttbb[0].idCommand  = %IDM_ARROWLEFT
            @pttbb[0].fsState    = %TBSTATE_ENABLED
            @pttbb[0].fsStyle    = %BTNS_BUTTON
            @pttbb[0].dwData     = 0
            @pttbb[0].iString    = -1

            @pttbb[1].iBitmap    = 1
            @pttbb[1].idCommand  = %IDM_ARROWRIGHT
            @pttbb[1].fsState    = %TBSTATE_ENABLED
            @pttbb[1].fsStyle    = %BTNS_BUTTON
            @pttbb[1].dwData     = 0
            @pttbb[1].iString    = -1

            @pttbb[2].iBitmap    = 2
            @pttbb[2].idCommand  = %IDM_COPYCLIPBOARD
            @pttbb[2].fsState    = %TBSTATE_ENABLED
            @pttbb[2].fsStyle    = %BTNS_BUTTON
            @pttbb[2].dwData     = 0
            @pttbb[2].iString    = -1

            @pttbb[3].iBitmap    = 3
            @pttbb[3].idCommand  = %IDM_COPYTOFOLDER
            @pttbb[3].fsState    = %TBSTATE_ENABLED
            @pttbb[3].fsStyle    = %BTNS_BUTTON
            @pttbb[3].dwData     = 0
            @pttbb[3].iString    = -1

            @pttbb[4].iBitmap    = 4
            @pttbb[4].idCommand  = %IDM_CUTCLIPBOARD
            @pttbb[4].fsState    = %TBSTATE_ENABLED
            @pttbb[4].fsStyle    = %BTNS_BUTTON
            @pttbb[4].dwData     = 0
            @pttbb[4].iString    = -1

            @pttbb[5].iBitmap    = 5
            @pttbb[5].idCommand  = %IDM_DELETE
            @pttbb[5].fsState    = %TBSTATE_ENABLED
            @pttbb[5].fsStyle    = %BTNS_BUTTON
            @pttbb[5].dwData     = 0
            @pttbb[5].iString    = -1

            @pttbb[6].iBitmap    = 6
            @pttbb[6].idCommand  = %IDM_FAVORITES
            @pttbb[6].fsState    = %TBSTATE_ENABLED
            @pttbb[6].fsStyle    = %BTNS_BUTTON
            @pttbb[6].dwData     = 0
            @pttbb[6].iString    = -1

            @pttbb[7].iBitmap    = 7
            @pttbb[7].idCommand  = %IDM_FOLDERCLOSED
            @pttbb[7].fsState    = %TBSTATE_ENABLED
            @pttbb[7].fsStyle    = %BTNS_BUTTON
            @pttbb[7].dwData     = 0
            @pttbb[7].iString    = -1

            @pttbb[8].iBitmap    = 8
            @pttbb[8].idCommand  = %IDM_FOLDEROPEN
            @pttbb[8].fsState    = %TBSTATE_ENABLED
            @pttbb[8].fsStyle    = %BTNS_BUTTON
            @pttbb[8].dwData     = 0
            @pttbb[8].iString    = -1

            @pttbb[9].iBitmap    = 9
            @pttbb[9].idCommand  = %IDM_FOLDEROPTIONS
            @pttbb[9].fsState    = %TBSTATE_ENABLED
            @pttbb[9].fsStyle    = %BTNS_BUTTON
            @pttbb[9].dwData     = 0
            @pttbb[9].iString    = -1

            @pttbb[10].iBitmap   = 10
            @pttbb[10].idCommand = %IDM_FOLDERS
            @pttbb[10].fsState   = %TBSTATE_ENABLED
            @pttbb[10].fsStyle   = %BTNS_BUTTON
            @pttbb[10].dwData    = 0
            @pttbb[10].iString   = -1

            @pttbb[11].iBitmap   = 11
            @pttbb[11].idCommand = %IDM_HISTORY
            @pttbb[11].fsState   = %TBSTATE_ENABLED
            @pttbb[11].fsStyle   = %BTNS_BUTTON
            @pttbb[11].dwData    = 0
            @pttbb[11].iString   = -1

            SendMessage hWndChild, %TB_ADDBUTTONS, 12, BYVAL pttbb
            ' Free memory that was allocated for the button info
            HeapFree GetProcessHeap(), 0, BYVAL pttbb
            ' Set the number of rows
            SendMessage hWndChild, %TB_SETROWS, MAKDWD(12, %FALSE), BYVAL VARPTR(trc)
            ' Update the size of the toolbar
            SendMessage hWndChild, %TB_AUTOSIZE, 0, 0
         END IF

         FUNCTION = %FALSE
         EXIT FUNCTION
   END SELECT

   FUNCTION = DefWindowProc(hWnd, uMsg, wParam, lParam)

END FUNCTION
'=========================================================================================


José Roca

#11
 
Popup Toolbar Demo

This example creates a vertical toolbar and a second toolbar that is initially hidden. When the "Favorites" icon is clicked, the hidden toolbar is shown, and is hidden again when you click the "Favorites" icon again or you click in other part of the dialog. For simplicity, the popup toolbar uses the same image lists that the vertical toolbar, although different icons. You can create and use new image lists purposely made for the popup toolbar. This example is based in an example by Börje Hagsten: Vertical Toolbar Demo


'#########################################################################################
' Toolbar Control example
'#########################################################################################

' SED_PBWIN
#DIM ALL
#COMPILE EXE
#INCLUDE ONCE "ToolbarCtrl.inc"
#RESOURCE "EX_TOOLBAR_06.PBR"

GLOBAL   ghInstance              AS DWORD    ' handle of the application instance

'--------------------------- [ Command Identifiers ] ---------------------------

%IDM_ARROWLEFT                               = 28000
%IDM_ARROWRIGHT                              = 28001
%IDM_COPYCLIPBOARD                           = 28002
%IDM_COPYTOFOLDER                            = 28003
%IDM_CUTCLIPBOARD                            = 28004
%IDM_DELETE                                  = 28005
%IDM_FAVORITES                               = 28006
%IDM_FOLDERCLOSED                            = 28007
%IDM_FOLDEROPEN                              = 28008
%IDM_FOLDEROPTIONS                           = 28009
%IDM_FOLDERS                                 = 28010
%IDM_HISTORY                                 = 28011
%IDM_HOME                                    = 28012
%IDM_MAIL                                    = 28013
%IDM_MOVETOFOLDER                            = 28014
%IDM_NEWDOCUMENT                             = 28015
%IDM_OPENDOCUMENT                            = 28016
%IDM_PASTECLIPBOARD                          = 28017
%IDM_PRINT                                   = 28018

'--------------------------- [ Control Identifiers ] ---------------------------

%IDC_TOOLBAR                                 = 101
%IDC_POPUPTOOLBAR                            = 102


'-------------------------------------------------------------------------------
'
' PROCEDURE: WinMain
' PURPOSE:   Program entry point, calls initialization function, processes
'            message loop.
'
'-------------------------------------------------------------------------------

FUNCTION WinMain _
   ( _
   BYVAL hInstance      AS DWORD, _       ' handle of current instance
   BYVAL hPrevInstance  AS DWORD, _       ' handle of previous instance(not used in Win32)
   BYVAL pszCmdLine     AS ASCIIZ PTR, _  ' address of command line
   BYVAL nCmdShow       AS LONG _         ' show state of window
   ) AS LONG

   LOCAL szClassName       AS ASCIIZ * %MAX_PATH         ' class name
   LOCAL twcx              AS WNDCLASSEX                 ' class information
   LOCAL tmsg              AS tagMsg                     ' message information
   LOCAL ticc              AS INIT_COMMON_CONTROLSEX     ' specifies common control classes to register
   LOCAL hWnd              AS DWORD                      ' handle of main window

   ' Save the handle of the application instance
   ghInstance = hInstance

   ' Register the main window
   szClassName        = "EX_TOOLBAR_05"
   twcx.cbSize        = SIZEOF(twcx)                              ' size of WNDCLASSEX structure
   twcx.style         = %CS_DBLCLKS                               ' class styles
   twcx.lpfnWndProc   = CODEPTR(WndProc)                          ' address of window procedure used by class
   twcx.cbClsExtra    = 0                                         ' extra class bytes
   twcx.cbWndExtra    = 0                                         ' extra window bytes
   twcx.hInstance     = ghInstance                                ' instance of the process that is registering the window
   twcx.hIcon         = LoadIcon(%NULL, BYVAL %IDI_APPLICATION)   ' handle of class icon
   twcx.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)       ' handle of class cursor
   twcx.hbrBackground = %COLOR_BTNFACE + 1                        ' brush used to fill background of window's client area
   twcx.lpszMenuName  = %NULL                                     ' resource identifier of the class menu
   twcx.lpszClassName = VARPTR(szClassName)                       ' class name
   twcx.hIconSm       = %NULL                                     ' handle of small icon shown in caption/system Taskbar
   IF ISFALSE RegisterClassEx(twcx) THEN
      FUNCTION = %TRUE
      EXIT FUNCTION
   END IF

   ' Load the common controls library and
   ' specify the classes to register.
   ticc.dwSize = SIZEOF(ticc)
   ticc.dwICC  = %ICC_BAR_CLASSES
   InitCommonControlsEx ticc

   ' Create the Form1 window
   hWnd = CreateWindowEx(%WS_EX_WINDOWEDGE, _                                          ' extended styles
                         szClassName, _                                                ' class name
                         "Popup Toolbar Demo", _                                       ' caption
                         %WS_OVERLAPPEDWINDOW OR %WS_VISIBLE, _                        ' window styles
                         %CW_USEDEFAULT, 0, _                                          ' left, top
                         %CW_USEDEFAULT, 0, _                                          ' width, height
                         %NULL, %NULL, _                                               ' handle of owner, menu handle
                         ghInstance, BYVAL %NULL)                                      ' handle of instance, creation parameters

   ' If window could not be created, return "failure"
   IF ISFALSE hWnd THEN
      FUNCTION = %FALSE
      EXIT FUNCTION
   END IF

   ' Make the window visible; update its client area
   ShowWindow hWnd, nCmdShow
   UpdateWindow hWnd

   ' Main message loop of program.
   ' Acquire and dispatch messages until a WM_QUIT message is received.
   WHILE ISTRUE GetMessage(tmsg, BYVAL %NULL, 0, 0)
      IF ISFALSE IsDialogMessage(hWnd, tmsg) THEN
         TranslateMessage tmsg
         DispatchMessage tmsg
      END IF
   WEND

   FUNCTION = tmsg.wParam

END FUNCTION

'-------------------------------------------------------------------------------
'
' PROCEDURE: WndProc
' PURPOSE:   Processes messages for the Form1 window.
'
'-------------------------------------------------------------------------------

FUNCTION WndProc _
   ( _
   BYVAL hWnd     AS DWORD, _ ' window handle
   BYVAL uMsg     AS DWORD, _ ' type of message
   BYVAL wParam   AS DWORD, _ ' first message parameter
   BYVAL lParam   AS LONG _   ' second message parameter
   ) EXPORT AS LONG

   LOCAL sBtnText       AS STRING               ' toolbar button caption
   LOCAL ttbb           AS TBBUTTON             ' specifies or receives the attributes of a toolbar button
   LOCAL ttbab          AS TBADDBITMAP          ' specifies the images to add to a toolbar
   LOCAL trc            AS RECT                 ' bounding or formatting rectangle
   LOCAL ptnmhdr        AS NMHDR PTR            ' information about a notification message
   LOCAL ptttdi         AS NMTTDISPINFO PTR     ' tooltip notification message information
   LOCAL pttbb          AS TBBUTTON PTR         ' address of array of toolbar button info
   LOCAL hWndChild      AS DWORD                ' handle of child window
   LOCAL hFont          AS DWORD                ' handle of font used by form
   LOCAL lMsgResult     AS LONG                 ' value returned to message after message is processed
   LOCAL hImageList     AS DWORD                ' handle of imagelist control
   LOCAL hImage         AS DWORD                ' handle of bitmap
   LOCAL hToolbar       AS DWORD                ' toolbar window handle
   LOCAL hPopupToolbar  AS DWORD                ' popup toolbar window handle

   SELECT CASE uMsg

      CASE %WM_LBUTTONDOWN                                                        ' mouse click anywhere in dialog
         hToolbar = GetDlgItem(hWnd, %IDC_TOOLBAR)                                ' toolbar window handle
         hPopupToolbar = GetDlgItem(hWnd, %IDC_POPUPTOOLBAR)                      ' popup toolbar window handle
         IF IsWindowVisible(hPopupToolbar) THEN                                   ' if popup is visible
            ShowWindow hPopupToolbar, %SW_HIDE                                    ' hide it and....
            SendMessage hToolbar, %TB_CHECKBUTTON, %IDM_FAVORITES, MAKLNG(%FALSE, 0)  ' ... pop up pressed button
         END IF
         FUNCTION = %FALSE
         EXIT FUNCTION

      CASE %WM_COMMAND

         ' -------------------------------------------------------
         ' Messages from the Toolbar are handled here.
         ' ------------------------------------------------------

         SELECT CASE LOWRD(wParam)

            CASE %IDCANCEL
               IF HIWRD(wParam) = %BN_CLICKED THEN
                  SendMessage hWnd, %WM_CLOSE, wParam, lParam
                  FUNCTION = %FALSE
                  EXIT FUNCTION
               END IF

            CASE %IDM_ARROWLEFT
               ' Pass message to WM_LBUTTONDOWN
               SendMessage hwnd, %WM_LBUTTONDOWN, 0, 0
               MSGBOX "Arrow left button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_ARROWRIGHT
               ' Pass message to WM_LBUTTONDOWN
               SendMessage hwnd, %WM_LBUTTONDOWN, 0, 0
               MSGBOX "Arrow right button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_COPYCLIPBOARD
               ' Pass message to WM_LBUTTONDOWN
               SendMessage hwnd, %WM_LBUTTONDOWN, 0, 0
               MSGBOX "Copy to clipboard button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_COPYTOFOLDER
               ' Pass message to WM_LBUTTONDOWN
               SendMessage hwnd, %WM_LBUTTONDOWN, 0, 0
               MSGBOX "Copy to folder button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_CUTCLIPBOARD
               ' Pass message to WM_LBUTTONDOWN
               SendMessage hwnd, %WM_LBUTTONDOWN, 0, 0
               MSGBOX "Cut to clipboard button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_DELETE
               ' Pass message to WM_LBUTTONDOWN
               SendMessage hwnd, %WM_LBUTTONDOWN, 0, 0
               MSGBOX "Delete button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FAVORITES
               hToolbar = GetDlgItem(hWnd, %IDC_TOOLBAR)               ' toolbar window handle
               hPopupToolbar = GetDlgItem(hWnd, %IDC_POPUPTOOLBAR)     ' popup toolbar window handle
               IF (GetKeyState(%VK_SPACE) AND &H8000) THEN             ' trap and act on spacebar
                  IF (SendMessage(hToolbar, %TB_GETSTATE, %IDM_FAVORITES, 0) AND %TBSTATE_CHECKED) THEN
                     SendMessage hToolbar, %TB_CHECKBUTTON, %IDM_FAVORITES, MAKLNG(%FALSE, 0)  ' ... pop up pressed button
                  ELSE
                     SendMessage hToolbar, %TB_CHECKBUTTON, %IDM_FAVORITES, MAKLNG(%TRUE, 0)  ' ... pop up pressed button
                     SetFocus hPopupToolbar
                  END IF
               END IF
               IF (SendMessage(hToolbar, %TB_GETSTATE, %IDM_FAVORITES, 0) AND %TBSTATE_CHECKED) THEN
                  SendMessage hToolbar, %TB_GETITEMRECT, 6, VARPTR(trc)                 ' get button's position
                  SetWindowPos hPopupToolbar, 0, trc.nRight + 2, trc.nTop + 2, 0, 0, _  ' move popup there
                               %SWP_NOSIZE OR %SWP_NOZORDER
                  ShowWindow hPopupToolbar, %SW_SHOW                                    ' and show it
               ELSE
                  SendMessage hwnd, %WM_LBUTTONDOWN, 0, 0                               ' else pass message to %WM_LBUTTONDOWN
               END IF
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDERCLOSED
               ' Pass message to WM_LBUTTONDOWN
               SendMessage hwnd, %WM_LBUTTONDOWN, 0, 0
               MSGBOX "Folder closed button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDEROPEN
               ' Pass message to WM_LBUTTONDOWN
               SendMessage hwnd, %WM_LBUTTONDOWN, 0, 0
               MSGBOX "Folder open button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDEROPTIONS
               ' Pass message to WM_LBUTTONDOWN
               SendMessage hwnd, %WM_LBUTTONDOWN, 0, 0
               MSGBOX "Folder options button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDERS
               ' Pass message to WM_LBUTTONDOWN
               SendMessage hwnd, %WM_LBUTTONDOWN, 0, 0
               MSGBOX "Folders button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_HISTORY
               ' Pass message to WM_LBUTTONDOWN
               SendMessage hwnd, %WM_LBUTTONDOWN, 0, 0
               MSGBOX "History button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            ' *** Popup toolbar buttons ***

            CASE %IDM_MAIL
               MSGBOX "Mail button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_MOVETOFOLDER
               MSGBOX "Move to Folder button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_NEWDOCUMENT
               MSGBOX "New Document button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_OPENDOCUMENT
               MSGBOX "Open Document button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_PASTECLIPBOARD
               MSGBOX "Paste Clipboard button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_PRINT
               MSGBOX "Print button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

         END SELECT

      CASE %WM_NOTIFY

         ' -------------------------------------------------------
         ' Notification messages are handled here.
         ' The TTN_GETDISPINFO message is sent by a ToolTip control
         ' to retrieve information needed to display a ToolTip window.
         ' ------------------------------------------------------
         ptnmhdr = lParam

         SELECT CASE @ptnmhdr.code
            CASE %TTN_GETDISPINFO
               ptttdi        = lParam
               @ptttdi.hinst = ghInstance

               SELECT CASE @ptttdi.hdr.hwndFrom
                  ' The TB_GETTOOLTIPS message retrieves the handle to the ToolTip control,
                  ' if any, associated with the toolbar.
                  CASE SendMessage(GetDlgItem(hWnd, %IDC_TOOLBAR), %TB_GETTOOLTIPS, 0, 0)
                     @ptttdi.lpszText = @ptttdi.hdr.idFrom
                     EXIT FUNCTION
                  CASE SendMessage(GetDlgItem(hWnd, %IDC_POPUPTOOLBAR), %TB_GETTOOLTIPS, 0, 0)
                     @ptttdi.lpszText = @ptttdi.hdr.idFrom
                     EXIT FUNCTION
               END SELECT
         END SELECT

      CASE %WM_SYSCOLORCHANGE
         ' Forward this message to common controls so that they will
         ' be properly updated when the user changes the color settings.
         SendMessage GetDlgItem(hWnd, %IDC_TOOLBAR), %WM_SYSCOLORCHANGE, wParam, lParam

      CASE %WM_DESTROY
         ' Destroy the image lists
         hWndChild = GetDlgItem(hWnd, %IDC_TOOLBAR)
         ImageList_Destroy SendMessage(hWndChild, %TB_SETIMAGELIST, 0, %NULL)
         ImageList_Destroy SendMessage(hWndChild, %TB_SETDISABLEDIMAGELIST, 0, %NULL)
         ImageList_Destroy SendMessage(hWndChild, %TB_SETHOTIMAGELIST, 0, %NULL)
         ' End the application
         PostQuitMessage 0
         FUNCTION = %FALSE
         EXIT FUNCTION

      CASE %WM_SIZE
         IF wParam <> %SIZE_MINIMIZED THEN
            ' Update the size and position of the Toolbar control
            SendMessage GetDlgItem(hWnd, %IDC_TOOLBAR), %TB_AUTOSIZE, 0, 0
         END IF
         FUNCTION = %FALSE
         EXIT FUNCTION

      CASE %WM_CREATE
         ' Create font used by container
         hFont = GetStockObject(%DEFAULT_GUI_FONT)

         ' Create the toolbar control
         hToolbar = CreateWindowEx(%NULL, _                                               ' extended styles
                                    "ToolbarWindow32", _                                  ' class name
                                    "", _                                                 ' caption
                                    %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR _          ' window styles
                                    %CCS_NORESIZE OR %CCS_NODIVIDER OR _                  ' class styles
                                    %TBSTYLE_TOOLTIPS OR %TBSTYLE_WRAPABLE OR _
                                    %TBSTYLE_FLAT, _
                                    2, 0, _                                               ' left, top
                                    51, 362, _                                            ' width, height
                                    hWnd, %IDC_TOOLBAR, _                                 ' handle of parent, control ID
                                    ghInstance, BYVAL %NULL)                              ' handle of instance, creation parameters
         SendMessage hToolbar, %WM_SETFONT, hFont, %TRUE

         ' Set the imagelist used with default images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBNOR", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hToolbar, %TB_SETIMAGELIST, 0, hImageList

         ' Set the imagelist used with disabled images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBDIS", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hToolbar, %TB_SETDISABLEDIMAGELIST, 0, hImageList

         ' Set the imagelist used with hot images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBHOT", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hToolbar, %TB_SETHOTIMAGELIST, 0, hImageList

         ' Allocate memory for the button info array
         pttbb = HeapAlloc(GetProcessHeap(), %HEAP_ZERO_MEMORY, 12 * SIZEOF(ttbb))
         IF ISTRUE pttbb THEN
            ' Send the TB_BUTTONSTRUCTSIZE message, for backward compatibility
            SendMessage hToolbar, %TB_BUTTONSTRUCTSIZE, SIZEOF(ttbb), 0
            ' Set the size of the bitmaps
            SendMessage hToolbar, %TB_SETBITMAPSIZE, 0, MAKLNG(24, 24)
            ' Add buttons to the toolbar
            @pttbb[0].iBitmap    = 0
            @pttbb[0].idCommand  = %IDM_ARROWLEFT
            @pttbb[0].fsState    = %TBSTATE_ENABLED
            @pttbb[0].fsStyle    = %BTNS_BUTTON
            @pttbb[0].dwData     = 0
            @pttbb[0].iString    = -1

            @pttbb[1].iBitmap    = 1
            @pttbb[1].idCommand  = %IDM_ARROWRIGHT
            @pttbb[1].fsState    = %TBSTATE_ENABLED
            @pttbb[1].fsStyle    = %BTNS_BUTTON
            @pttbb[1].dwData     = 0
            @pttbb[1].iString    = -1

            @pttbb[2].iBitmap    = 2
            @pttbb[2].idCommand  = %IDM_COPYCLIPBOARD
            @pttbb[2].fsState    = %TBSTATE_ENABLED
            @pttbb[2].fsStyle    = %BTNS_BUTTON
            @pttbb[2].dwData     = 0
            @pttbb[2].iString    = -1

            @pttbb[3].iBitmap    = 3
            @pttbb[3].idCommand  = %IDM_COPYTOFOLDER
            @pttbb[3].fsState    = %TBSTATE_ENABLED
            @pttbb[3].fsStyle    = %BTNS_BUTTON
            @pttbb[3].dwData     = 0
            @pttbb[3].iString    = -1

            @pttbb[4].iBitmap    = 4
            @pttbb[4].idCommand  = %IDM_CUTCLIPBOARD
            @pttbb[4].fsState    = %TBSTATE_ENABLED
            @pttbb[4].fsStyle    = %BTNS_BUTTON
            @pttbb[4].dwData     = 0
            @pttbb[4].iString    = -1

            @pttbb[5].iBitmap    = 5
            @pttbb[5].idCommand  = %IDM_DELETE
            @pttbb[5].fsState    = %TBSTATE_ENABLED
            @pttbb[5].fsStyle    = %BTNS_BUTTON
            @pttbb[5].dwData     = 0
            @pttbb[5].iString    = -1

            @pttbb[6].iBitmap    = 6
            @pttbb[6].idCommand  = %IDM_FAVORITES
            @pttbb[6].fsState    = %TBSTATE_ENABLED
            @pttbb[6].fsStyle    = %BTNS_CHECK
            @pttbb[6].dwData     = 0
            @pttbb[6].iString    = -1

            @pttbb[7].iBitmap    = 7
            @pttbb[7].idCommand  = %IDM_FOLDERCLOSED
            @pttbb[7].fsState    = %TBSTATE_ENABLED
            @pttbb[7].fsStyle    = %BTNS_BUTTON
            @pttbb[7].dwData     = 0
            @pttbb[7].iString    = -1

            @pttbb[8].iBitmap    = 8
            @pttbb[8].idCommand  = %IDM_FOLDEROPEN
            @pttbb[8].fsState    = %TBSTATE_ENABLED
            @pttbb[8].fsStyle    = %BTNS_BUTTON
            @pttbb[8].dwData     = 0
            @pttbb[8].iString    = -1

            @pttbb[9].iBitmap    = 9
            @pttbb[9].idCommand  = %IDM_FOLDEROPTIONS
            @pttbb[9].fsState    = %TBSTATE_ENABLED
            @pttbb[9].fsStyle    = %BTNS_BUTTON
            @pttbb[9].dwData     = 0
            @pttbb[9].iString    = -1

            @pttbb[10].iBitmap   = 10
            @pttbb[10].idCommand = %IDM_FOLDERS
            @pttbb[10].fsState   = %TBSTATE_ENABLED
            @pttbb[10].fsStyle   = %BTNS_BUTTON
            @pttbb[10].dwData    = 0
            @pttbb[10].iString   = -1

            @pttbb[11].iBitmap   = 11
            @pttbb[11].idCommand = %IDM_HISTORY
            @pttbb[11].fsState   = %TBSTATE_ENABLED
            @pttbb[11].fsStyle   = %BTNS_BUTTON
            @pttbb[11].dwData    = 0
            @pttbb[11].iString   = -1

            SendMessage hToolbar, %TB_ADDBUTTONS, 12, BYVAL pttbb
            ' Free memory that was allocated for the button info
            HeapFree GetProcessHeap(), 0, BYVAL pttbb
            ' Set the number of rows
            SendMessage hToolbar, %TB_SETROWS, MAKDWD(12, %FALSE), BYVAL VARPTR(trc)
            ' Update the size of the toolbar
            SendMessage hToolbar, %TB_AUTOSIZE, 0, 0
         END IF

         ' Create the popup toolbar control
         hPopupToolbar = CreateWindowEx(%NULL, _                                          ' extended styles
                                    "ToolbarWindow32", _                                  ' class name
                                    "", _                                                 ' caption
                                    %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR _          ' window styles
                                    %CCS_NORESIZE OR %CCS_NODIVIDER OR _                  ' class styles
                                    %TBSTYLE_TOOLTIPS OR %TBSTYLE_FLAT, _
                                    0, 0, _                                               ' left, top
                                    200, 34, _                                            ' width, height
                                    hWnd, %IDC_POPUPTOOLBAR, _                            ' handle of parent, control ID
                                    ghInstance, BYVAL %NULL)                              ' handle of instance, creation parameters
         SendMessage hPopupToolbar, %WM_SETFONT, hFont, %TRUE

         ' Set the imagelist used with default images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBNOR", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hPopupToolbar, %TB_SETIMAGELIST, 0, hImageList

         ' Set the imagelist used with disabled images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBDIS", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hPopupToolbar, %TB_SETDISABLEDIMAGELIST, 0, hImageList

         ' Set the imagelist used with hot images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBHOT", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hPopupToolbar, %TB_SETHOTIMAGELIST, 0, hImageList

         ' Allocate memory for the button info array
         pttbb = HeapAlloc(GetProcessHeap(), %HEAP_ZERO_MEMORY, 6 * SIZEOF(ttbb))
         IF ISTRUE pttbb THEN
            ' Send the TB_BUTTONSTRUCTSIZE message, for backward compatibility
            SendMessage hPopupToolbar, %TB_BUTTONSTRUCTSIZE, SIZEOF(ttbb), 0
            ' Set the size of the bitmaps
            SendMessage hPopupToolbar, %TB_SETBITMAPSIZE, 0, MAKLNG(24, 24)
            ' Add buttons to the toolbar
            @pttbb[0].iBitmap    = 16
            @pttbb[0].idCommand  = %IDM_MAIL
            @pttbb[0].fsState    = %TBSTATE_ENABLED
            @pttbb[0].fsStyle    = %BTNS_BUTTON
            @pttbb[0].dwData     = 0
            @pttbb[0].iString    = -1

            @pttbb[1].iBitmap    = 17
            @pttbb[1].idCommand  = %IDM_MOVETOFOLDER
            @pttbb[1].fsState    = %TBSTATE_ENABLED
            @pttbb[1].fsStyle    = %BTNS_BUTTON
            @pttbb[1].dwData     = 0
            @pttbb[1].iString    = -1

            @pttbb[2].iBitmap    = 18
            @pttbb[2].idCommand  = %IDM_NEWDOCUMENT
            @pttbb[2].fsState    = %TBSTATE_ENABLED
            @pttbb[2].fsStyle    = %BTNS_BUTTON
            @pttbb[2].dwData     = 0
            @pttbb[2].iString    = -1

            @pttbb[3].iBitmap    = 19
            @pttbb[3].idCommand  = %IDM_OPENDOCUMENT
            @pttbb[3].fsState    = %TBSTATE_ENABLED
            @pttbb[3].fsStyle    = %BTNS_BUTTON
            @pttbb[3].dwData     = 0
            @pttbb[3].iString    = -1

            @pttbb[4].iBitmap    = 20
            @pttbb[4].idCommand  = %IDM_PASTECLIPBOARD
            @pttbb[4].fsState    = %TBSTATE_ENABLED
            @pttbb[4].fsStyle    = %BTNS_BUTTON
            @pttbb[4].dwData     = 0
            @pttbb[4].iString    = -1

            @pttbb[5].iBitmap    = 21
            @pttbb[5].idCommand  = %IDM_PRINT
            @pttbb[5].fsState    = %TBSTATE_ENABLED
            @pttbb[5].fsStyle    = %BTNS_BUTTON
            @pttbb[5].dwData     = 0
            @pttbb[5].iString    = -1

            SendMessage hPopupToolbar, %TB_ADDBUTTONS, 6, BYVAL pttbb
            ' Free memory that was allocated for the button info
            HeapFree GetProcessHeap(), 0, BYVAL pttbb
            ' Update the size of the toolbar
            SendMessage hPopupToolbar, %TB_AUTOSIZE, 0, 0
            ' Hide the popup toolbar
            ShowWindow hPopupToolbar, %SW_HIDE
         END IF

         FUNCTION = %FALSE
         EXIT FUNCTION
   END SELECT

   FUNCTION = DefWindowProc(hWnd, uMsg, wParam, lParam)

END FUNCTION
'=========================================================================================


Resource file:


// Resource script

////////////////////////////////////////////////////////////////////////////////
//
//  Menu/Toolbar Identifiers
//

#define IDM_ARROWLEFT                        28000
#define IDM_ARROWRIGHT                       28001
#define IDM_COPYCLIPBOARD                    28002
#define IDM_COPYTOFOLDER                     28003
#define IDM_CUTCLIPBOARD                     28004
#define IDM_DELETE                           28005
#define IDM_FAVORITES                        28006
#define IDM_FOLDERCLOSED                     28007
#define IDM_FOLDEROPEN                       28008
#define IDM_FOLDEROPTIONS                    28009
#define IDM_FOLDERS                          28010
#define IDM_HISTORY                          28011
#define IDM_HOME                             28012
#define IDM_MAIL                             28013
#define IDM_MOVETOFOLDER                     28014
#define IDM_NEWDOCUMENT                      28015
#define IDM_OPENDOCUMENT                     28016
#define IDM_PASTECLIPBOARD                   28017
#define IDM_PRINT                            28018

////////////////////////////////////////////////////////////////////////////////
//
// Application Bitmap Strips.
//

TBNOR  BITMAP Toolbar24Normal.BMP
TBHOT  BITMAP Toolbar24Hot.BMP
TBDIS  BITMAP Toolbar24Disabled.BMP

////////////////////////////////////////////////////////////////////////////////
//
//  Toolbar tooltip string table
//

STRINGTABLE DISCARDABLE
BEGIN
   IDM_ARROWLEFT              "Arrow Left"
   IDM_ARROWRIGHT             "Arrow Right"
   IDM_COPYCLIPBOARD          "Copy to Clipboard"
   IDM_COPYTOFOLDER           "Copy to Folder"
   IDM_CUTCLIPBOARD           "Cut to Clipboard"
   IDM_DELETE                 "Delete"
   IDM_FAVORITES              "Favorites"
   IDM_FOLDERCLOSED           "Folder Closed"
   IDM_FOLDEROPEN             "Folder Open"
   IDM_FOLDEROPTIONS          "Folder Options"
   IDM_FOLDERS                "Folders"
   IDM_HISTORY                "History"
   IDM_HOME                   "Home"
   IDM_MAIL                   "Mail"
   IDM_MOVETOFOLDER           "Move to Folder"
   IDM_NEWDOCUMENT            "New Document"
   IDM_OPENDOCUMENT           "Open Document"
   IDM_PASTECLIPBOARD         "Paste Clipboard"
   IDM_PRINT                  "Print"
END


José Roca

#12
 
Double Toolbar Demo

This example creates two toolbars, one at the top and another at the bottom. For simplicity, the bottom toolbar uses the same image lists that the top toolbar, although different icons. You can create and use new image lists purposely made for the bottom toolbar.


'#########################################################################################
' Toolbar Control example
'#########################################################################################

' SED_PBWIN
#DIM ALL
#COMPILE EXE
#INCLUDE ONCE "ToolbarCtrl.inc"
#RESOURCE "EX_TOOLBAR_07.PBR"

GLOBAL   ghInstance              AS DWORD    ' handle of the application instance

'--------------------------- [ Command Identifiers ] ---------------------------

%IDM_ARROWLEFT                               = 28000
%IDM_ARROWRIGHT                              = 28001
%IDM_COPYCLIPBOARD                           = 28002
%IDM_COPYTOFOLDER                            = 28003
%IDM_CUTCLIPBOARD                            = 28004
%IDM_DELETE                                  = 28005
%IDM_FAVORITES                               = 28006
%IDM_FOLDERCLOSED                            = 28007
%IDM_FOLDEROPEN                              = 28008
%IDM_FOLDEROPTIONS                           = 28009
%IDM_FOLDERS                                 = 28010
%IDM_HISTORY                                 = 28011
%IDM_HOME                                    = 28012
%IDM_MAIL                                    = 28013
%IDM_MOVETOFOLDER                            = 28014
%IDM_NEWDOCUMENT                             = 28015
%IDM_OPENDOCUMENT                            = 28016
%IDM_PASTECLIPBOARD                          = 28017
%IDM_PRINT                                   = 28018
%IDM_PRINTPREVIEW                            = 28019
%IDM_DOCUMENTPROPERTIES                      = 28020
%IDM_REDOROUND                               = 28021
%IDM_REFRESH                                 = 28022
%IDM_SAVE                                    = 28023
%IDM_SEARCH                                  = 28024

'--------------------------- [ Control Identifiers ] ---------------------------

%IDC_TOPTOOLBAR                                 = 101
%IDC_BOTTOMTOOLBAR                            = 102


'-------------------------------------------------------------------------------
'
' PROCEDURE: WinMain
' PURPOSE:   Program entry point, calls initialization function, processes
'            message loop.
'
'-------------------------------------------------------------------------------

FUNCTION WinMain _
   ( _
   BYVAL hInstance      AS DWORD, _       ' handle of current instance
   BYVAL hPrevInstance  AS DWORD, _       ' handle of previous instance(not used in Win32)
   BYVAL pszCmdLine     AS ASCIIZ PTR, _  ' address of command line
   BYVAL nCmdShow       AS LONG _         ' show state of window
   ) AS LONG

   LOCAL szClassName       AS ASCIIZ * %MAX_PATH         ' class name
   LOCAL twcx              AS WNDCLASSEX                 ' class information
   LOCAL tmsg              AS tagMsg                     ' message information
   LOCAL ticc              AS INIT_COMMON_CONTROLSEX     ' specifies common control classes to register
   LOCAL hWnd              AS DWORD                      ' handle of main window

   ' Save the handle of the application instance
   ghInstance = hInstance

   ' Register the main window
   szClassName        = "EX_TOOLBAR_05"
   twcx.cbSize        = SIZEOF(twcx)                              ' size of WNDCLASSEX structure
   twcx.style         = %CS_DBLCLKS                               ' class styles
   twcx.lpfnWndProc   = CODEPTR(WndProc)                          ' address of window procedure used by class
   twcx.cbClsExtra    = 0                                         ' extra class bytes
   twcx.cbWndExtra    = 0                                         ' extra window bytes
   twcx.hInstance     = ghInstance                                ' instance of the process that is registering the window
   twcx.hIcon         = LoadIcon(%NULL, BYVAL %IDI_APPLICATION)   ' handle of class icon
   twcx.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)       ' handle of class cursor
   twcx.hbrBackground = %COLOR_BTNFACE + 1                        ' brush used to fill background of window's client area
   twcx.lpszMenuName  = %NULL                                     ' resource identifier of the class menu
   twcx.lpszClassName = VARPTR(szClassName)                       ' class name
   twcx.hIconSm       = %NULL                                     ' handle of small icon shown in caption/system Taskbar
   IF ISFALSE RegisterClassEx(twcx) THEN
      FUNCTION = %TRUE
      EXIT FUNCTION
   END IF

   ' Load the common controls library and
   ' specify the classes to register.
   ticc.dwSize = SIZEOF(ticc)
   ticc.dwICC  = %ICC_BAR_CLASSES
   InitCommonControlsEx ticc

   ' Create the Form1 window
   hWnd = CreateWindowEx(%WS_EX_WINDOWEDGE, _                                          ' extended styles
                         szClassName, _                                                ' class name
                         "Double Toolbar Demo", _                                      ' caption
                         %WS_OVERLAPPEDWINDOW OR %WS_VISIBLE, _                        ' window styles
                         %CW_USEDEFAULT, 0, _                                          ' left, top
                         %CW_USEDEFAULT, 0, _                                          ' width, height
                         %NULL, %NULL, _                                               ' handle of owner, menu handle
                         ghInstance, BYVAL %NULL)                                      ' handle of instance, creation parameters

   ' If window could not be created, return "failure"
   IF ISFALSE hWnd THEN
      FUNCTION = %FALSE
      EXIT FUNCTION
   END IF

   ' Make the window visible; update its client area
   ShowWindow hWnd, nCmdShow
   UpdateWindow hWnd

   ' Main message loop of program.
   ' Acquire and dispatch messages until a WM_QUIT message is received.
   WHILE ISTRUE GetMessage(tmsg, BYVAL %NULL, 0, 0)
      IF ISFALSE IsDialogMessage(hWnd, tmsg) THEN
         TranslateMessage tmsg
         DispatchMessage tmsg
      END IF
   WEND

   FUNCTION = tmsg.wParam

END FUNCTION

'-------------------------------------------------------------------------------
'
' PROCEDURE: WndProc
' PURPOSE:   Processes messages for the Form1 window.
'
'-------------------------------------------------------------------------------

FUNCTION WndProc _
   ( _
   BYVAL hWnd     AS DWORD, _ ' window handle
   BYVAL uMsg     AS DWORD, _ ' type of message
   BYVAL wParam   AS DWORD, _ ' first message parameter
   BYVAL lParam   AS LONG _   ' second message parameter
   ) EXPORT AS LONG

   LOCAL sBtnText       AS STRING               ' toolbar button caption
   LOCAL ttbb           AS TBBUTTON             ' specifies or receives the attributes of a toolbar button
   LOCAL ttbab          AS TBADDBITMAP          ' specifies the images to add to a toolbar
   LOCAL ptnmhdr        AS NMHDR PTR            ' information about a notification message
   LOCAL ptttdi         AS NMTTDISPINFO PTR     ' tooltip notification message information
   LOCAL pttbb          AS TBBUTTON PTR         ' address of array of toolbar button info
   LOCAL hWndChild      AS DWORD                ' handle of child window
   LOCAL hFont          AS DWORD                ' handle of font used by form
   LOCAL lMsgResult     AS LONG                 ' value returned to message after message is processed
   LOCAL hImageList     AS DWORD                ' handle of imagelist control
   LOCAL hImage         AS DWORD                ' handle of bitmap
   LOCAL hTopToolbar    AS DWORD                ' top toolbar window handle
   LOCAL hBottomToolbar AS DWORD                ' bottom toolbar window handle

   SELECT CASE uMsg

      CASE %WM_COMMAND

         ' -------------------------------------------------------
         ' Messages from the Toolbar are handled here.
         ' ------------------------------------------------------

         SELECT CASE LOWRD(wParam)

            CASE %IDCANCEL
               IF HIWRD(wParam) = %BN_CLICKED THEN
                  SendMessage hWnd, %WM_CLOSE, wParam, lParam
                  FUNCTION = %FALSE
                  EXIT FUNCTION
               END IF

            ' *** Top toolbar buttons ***

            CASE %IDM_ARROWLEFT
               MSGBOX "Arrow left button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_ARROWRIGHT
               MSGBOX "Arrow right button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_COPYCLIPBOARD
               MSGBOX "Copy to clipboard button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_COPYTOFOLDER
               MSGBOX "Copy to folder button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_CUTCLIPBOARD
               MSGBOX "Cut to clipboard button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_DELETE
               MSGBOX "Delete button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FAVORITES
               MSGBOX "Favorites button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDERCLOSED
               MSGBOX "Folder closed button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDEROPEN
               MSGBOX "Folder open button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDEROPTIONS
               MSGBOX "Folder options button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDERS
               MSGBOX "Folders button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_HISTORY
               MSGBOX "History button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            ' *** Bottom toolbar buttons ***

            CASE %IDM_MAIL
               MSGBOX "Mail button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_MOVETOFOLDER
               MSGBOX "Move to Folder button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_NEWDOCUMENT
               MSGBOX "New Document button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_OPENDOCUMENT
               MSGBOX "Open Document button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_PASTECLIPBOARD
               MSGBOX "Paste Clipboard button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_PRINT
               MSGBOX "Print button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

         END SELECT

      CASE %WM_NOTIFY

         ' -------------------------------------------------------
         ' Notification messages are handled here.
         ' The TTN_GETDISPINFO message is sent by a ToolTip control
         ' to retrieve information needed to display a ToolTip window.
         ' ------------------------------------------------------
         ptnmhdr = lParam

         SELECT CASE @ptnmhdr.code
            CASE %TTN_GETDISPINFO
               ptttdi        = lParam
               @ptttdi.hinst = ghInstance

               SELECT CASE @ptttdi.hdr.hwndFrom
                  ' The TB_GETTOOLTIPS message retrieves the handle to the ToolTip control,
                  ' if any, associated with the toolbar.
                  CASE SendMessage(GetDlgItem(hWnd, %IDC_TOPTOOLBAR), %TB_GETTOOLTIPS, 0, 0)
                     @ptttdi.lpszText = @ptttdi.hdr.idFrom
                     EXIT FUNCTION
                  CASE SendMessage(GetDlgItem(hWnd, %IDC_BOTTOMTOOLBAR), %TB_GETTOOLTIPS, 0, 0)
                     @ptttdi.lpszText = @ptttdi.hdr.idFrom
                     EXIT FUNCTION
               END SELECT
         END SELECT

      CASE %WM_SYSCOLORCHANGE
         ' Forward this message to common controls so that they will
         ' be properly updated when the user changes the color settings.
         SendMessage GetDlgItem(hWnd, %IDC_TOPTOOLBAR), %WM_SYSCOLORCHANGE, wParam, lParam

      CASE %WM_DESTROY
         ' Destroy the image lists
         hWndChild = GetDlgItem(hWnd, %IDC_TOPTOOLBAR)
         ImageList_Destroy SendMessage(hWndChild, %TB_SETIMAGELIST, 0, %NULL)
         ImageList_Destroy SendMessage(hWndChild, %TB_SETDISABLEDIMAGELIST, 0, %NULL)
         ImageList_Destroy SendMessage(hWndChild, %TB_SETHOTIMAGELIST, 0, %NULL)
         ' End the application
         PostQuitMessage 0
         FUNCTION = %FALSE
         EXIT FUNCTION

      CASE %WM_SIZE
         IF wParam <> %SIZE_MINIMIZED THEN
            ' Update the size and position of the toolbars
            SendMessage GetDlgItem(hWnd, %IDC_TOPTOOLBAR), %TB_AUTOSIZE, 0, 0
            SendMessage GetDlgItem(hWnd, %IDC_BOTTOMTOOLBAR), %TB_AUTOSIZE, 0, 0
         END IF
         FUNCTION = %FALSE
         EXIT FUNCTION

      CASE %WM_CREATE
         ' Create font used by container
         hFont = GetStockObject(%DEFAULT_GUI_FONT)

         ' Create the toolbar control
         hTopToolbar = CreateWindowEx(%NULL, _                                               ' extended styles
                                    "ToolbarWindow32", _                                  ' class name
                                    "", _                                                 ' caption
                                    %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR _          ' window styles
                                    %CCS_TOP OR %CCS_NODIVIDER OR _                       ' class styles
                                    %TBSTYLE_TOOLTIPS OR %TBSTYLE_FLAT, _
                                    2, 0, _                                               ' left, top
                                    51, 362, _                                            ' width, height
                                    hWnd, %IDC_TOPTOOLBAR, _                                 ' handle of parent, control ID
                                    ghInstance, BYVAL %NULL)                              ' handle of instance, creation parameters
         SendMessage hTopToolbar, %WM_SETFONT, hFont, %TRUE

         ' Set the imagelist used with default images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBNOR", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hTopToolbar, %TB_SETIMAGELIST, 0, hImageList

         ' Set the imagelist used with disabled images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBDIS", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hTopToolbar, %TB_SETDISABLEDIMAGELIST, 0, hImageList

         ' Set the imagelist used with hot images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBHOT", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hTopToolbar, %TB_SETHOTIMAGELIST, 0, hImageList

         ' Allocate memory for the button info array
         pttbb = HeapAlloc(GetProcessHeap(), %HEAP_ZERO_MEMORY, 12 * SIZEOF(ttbb))
         IF ISTRUE pttbb THEN
            ' Send the TB_BUTTONSTRUCTSIZE message, for backward compatibility
            SendMessage hTopToolbar, %TB_BUTTONSTRUCTSIZE, SIZEOF(ttbb), 0
            ' Set the size of the bitmaps
            SendMessage hTopToolbar, %TB_SETBITMAPSIZE, 0, MAKLNG(24, 24)
            ' Add buttons to the toolbar
            @pttbb[0].iBitmap    = 0
            @pttbb[0].idCommand  = %IDM_ARROWLEFT
            @pttbb[0].fsState    = %TBSTATE_ENABLED
            @pttbb[0].fsStyle    = %BTNS_BUTTON
            @pttbb[0].dwData     = 0
            @pttbb[0].iString    = -1

            @pttbb[1].iBitmap    = 1
            @pttbb[1].idCommand  = %IDM_ARROWRIGHT
            @pttbb[1].fsState    = %TBSTATE_ENABLED
            @pttbb[1].fsStyle    = %BTNS_BUTTON
            @pttbb[1].dwData     = 0
            @pttbb[1].iString    = -1

            @pttbb[2].iBitmap    = 2
            @pttbb[2].idCommand  = %IDM_COPYCLIPBOARD
            @pttbb[2].fsState    = %TBSTATE_ENABLED
            @pttbb[2].fsStyle    = %BTNS_BUTTON
            @pttbb[2].dwData     = 0
            @pttbb[2].iString    = -1

            @pttbb[3].iBitmap    = 3
            @pttbb[3].idCommand  = %IDM_COPYTOFOLDER
            @pttbb[3].fsState    = %TBSTATE_ENABLED
            @pttbb[3].fsStyle    = %BTNS_BUTTON
            @pttbb[3].dwData     = 0
            @pttbb[3].iString    = -1

            @pttbb[4].iBitmap    = 4
            @pttbb[4].idCommand  = %IDM_CUTCLIPBOARD
            @pttbb[4].fsState    = %TBSTATE_ENABLED
            @pttbb[4].fsStyle    = %BTNS_BUTTON
            @pttbb[4].dwData     = 0
            @pttbb[4].iString    = -1

            @pttbb[5].iBitmap    = 5
            @pttbb[5].idCommand  = %IDM_DELETE
            @pttbb[5].fsState    = %TBSTATE_ENABLED
            @pttbb[5].fsStyle    = %BTNS_BUTTON
            @pttbb[5].dwData     = 0
            @pttbb[5].iString    = -1

            @pttbb[6].iBitmap    = 6
            @pttbb[6].idCommand  = %IDM_FAVORITES
            @pttbb[6].fsState    = %TBSTATE_ENABLED
            @pttbb[6].fsStyle    = %BTNS_CHECK
            @pttbb[6].dwData     = 0
            @pttbb[6].iString    = -1

            @pttbb[7].iBitmap    = 7
            @pttbb[7].idCommand  = %IDM_FOLDERCLOSED
            @pttbb[7].fsState    = %TBSTATE_ENABLED
            @pttbb[7].fsStyle    = %BTNS_BUTTON
            @pttbb[7].dwData     = 0
            @pttbb[7].iString    = -1

            @pttbb[8].iBitmap    = 8
            @pttbb[8].idCommand  = %IDM_FOLDEROPEN
            @pttbb[8].fsState    = %TBSTATE_ENABLED
            @pttbb[8].fsStyle    = %BTNS_BUTTON
            @pttbb[8].dwData     = 0
            @pttbb[8].iString    = -1

            @pttbb[9].iBitmap    = 9
            @pttbb[9].idCommand  = %IDM_FOLDEROPTIONS
            @pttbb[9].fsState    = %TBSTATE_ENABLED
            @pttbb[9].fsStyle    = %BTNS_BUTTON
            @pttbb[9].dwData     = 0
            @pttbb[9].iString    = -1

            @pttbb[10].iBitmap   = 10
            @pttbb[10].idCommand = %IDM_FOLDERS
            @pttbb[10].fsState   = %TBSTATE_ENABLED
            @pttbb[10].fsStyle   = %BTNS_BUTTON
            @pttbb[10].dwData    = 0
            @pttbb[10].iString   = -1

            @pttbb[11].iBitmap   = 11
            @pttbb[11].idCommand = %IDM_HISTORY
            @pttbb[11].fsState   = %TBSTATE_ENABLED
            @pttbb[11].fsStyle   = %BTNS_BUTTON
            @pttbb[11].dwData    = 0
            @pttbb[11].iString   = -1

            SendMessage hTopToolbar, %TB_ADDBUTTONS, 12, BYVAL pttbb
            ' Free memory that was allocated for the button info
            HeapFree GetProcessHeap(), 0, BYVAL pttbb
            ' Update the size of the toolbar
            SendMessage hTopToolbar, %TB_AUTOSIZE, 0, 0
         END IF

         ' Create the popup toolbar control
         hBottomToolbar = CreateWindowEx(%NULL, _                                          ' extended styles
                                    "ToolbarWindow32", _                                  ' class name
                                    "", _                                                 ' caption
                                    %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR _          ' window styles
                                    %CCS_BOTTOM OR %CCS_NODIVIDER OR _                    ' class styles
                                    %TBSTYLE_TOOLTIPS OR %TBSTYLE_FLAT, _
                                    0, 0, _                                               ' left, top
                                    200, 34, _                                            ' width, height
                                    hWnd, %IDC_BOTTOMTOOLBAR, _                            ' handle of parent, control ID
                                    ghInstance, BYVAL %NULL)                              ' handle of instance, creation parameters
         SendMessage hBottomToolbar, %WM_SETFONT, hFont, %TRUE

         ' Set the imagelist used with default images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBNOR", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hBottomToolbar, %TB_SETIMAGELIST, 0, hImageList

         ' Set the imagelist used with disabled images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBDIS", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hBottomToolbar, %TB_SETDISABLEDIMAGELIST, 0, hImageList

         ' Set the imagelist used with hot images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBHOT", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hBottomToolbar, %TB_SETHOTIMAGELIST, 0, hImageList

         ' Allocate memory for the button info array
         pttbb = HeapAlloc(GetProcessHeap(), %HEAP_ZERO_MEMORY, 12 * SIZEOF(ttbb))
         IF ISTRUE pttbb THEN
            ' Send the TB_BUTTONSTRUCTSIZE message, for backward compatibility
            SendMessage hBottomToolbar, %TB_BUTTONSTRUCTSIZE, SIZEOF(ttbb), 0
            ' Set the size of the bitmaps
            SendMessage hBottomToolbar, %TB_SETBITMAPSIZE, 0, MAKLNG(24, 24)
            ' Add buttons to the toolbar
            @pttbb[0].iBitmap    = 16
            @pttbb[0].idCommand  = %IDM_MAIL
            @pttbb[0].fsState    = %TBSTATE_ENABLED
            @pttbb[0].fsStyle    = %BTNS_BUTTON
            @pttbb[0].dwData     = 0
            @pttbb[0].iString    = -1

            @pttbb[1].iBitmap    = 17
            @pttbb[1].idCommand  = %IDM_MOVETOFOLDER
            @pttbb[1].fsState    = %TBSTATE_ENABLED
            @pttbb[1].fsStyle    = %BTNS_BUTTON
            @pttbb[1].dwData     = 0
            @pttbb[1].iString    = -1

            @pttbb[2].iBitmap    = 18
            @pttbb[2].idCommand  = %IDM_NEWDOCUMENT
            @pttbb[2].fsState    = %TBSTATE_ENABLED
            @pttbb[2].fsStyle    = %BTNS_BUTTON
            @pttbb[2].dwData     = 0
            @pttbb[2].iString    = -1

            @pttbb[3].iBitmap    = 19
            @pttbb[3].idCommand  = %IDM_OPENDOCUMENT
            @pttbb[3].fsState    = %TBSTATE_ENABLED
            @pttbb[3].fsStyle    = %BTNS_BUTTON
            @pttbb[3].dwData     = 0
            @pttbb[3].iString    = -1

            @pttbb[4].iBitmap    = 20
            @pttbb[4].idCommand  = %IDM_PASTECLIPBOARD
            @pttbb[4].fsState    = %TBSTATE_ENABLED
            @pttbb[4].fsStyle    = %BTNS_BUTTON
            @pttbb[4].dwData     = 0
            @pttbb[4].iString    = -1

            @pttbb[5].iBitmap    = 21
            @pttbb[5].idCommand  = %IDM_PRINT
            @pttbb[5].fsState    = %TBSTATE_ENABLED
            @pttbb[5].fsStyle    = %BTNS_BUTTON
            @pttbb[5].dwData     = 0
            @pttbb[5].iString    = -1

            @pttbb[6].iBitmap    = 22
            @pttbb[6].idCommand  = %IDM_PRINTPREVIEW
            @pttbb[6].fsState    = %TBSTATE_ENABLED
            @pttbb[6].fsStyle    = %BTNS_BUTTON
            @pttbb[6].dwData     = 0
            @pttbb[6].iString    = -1

            @pttbb[7].iBitmap    = 23
            @pttbb[7].idCommand  = %IDM_DOCUMENTPROPERTIES
            @pttbb[7].fsState    = %TBSTATE_ENABLED
            @pttbb[7].fsStyle    = %BTNS_BUTTON
            @pttbb[7].dwData     = 0
            @pttbb[7].iString    = -1

            @pttbb[8].iBitmap    = 25
            @pttbb[8].idCommand  = %IDM_REDOROUND
            @pttbb[8].fsState    = %TBSTATE_ENABLED
            @pttbb[8].fsStyle    = %BTNS_BUTTON
            @pttbb[8].dwData     = 0
            @pttbb[8].iString    = -1

            @pttbb[9].iBitmap    = 27
            @pttbb[9].idCommand  = %IDM_REFRESH
            @pttbb[9].fsState    = %TBSTATE_ENABLED
            @pttbb[9].fsStyle    = %BTNS_BUTTON
            @pttbb[9].dwData     = 0
            @pttbb[9].iString    = -1

            @pttbb[10].iBitmap   = 28
            @pttbb[10].idCommand = %IDM_SAVE
            @pttbb[10].fsState   = %TBSTATE_ENABLED
            @pttbb[10].fsStyle   = %BTNS_BUTTON
            @pttbb[10].dwData    = 0
            @pttbb[10].iString   = -1

            @pttbb[11].iBitmap   = 30
            @pttbb[11].idCommand = %IDM_SEARCH
            @pttbb[11].fsState   = %TBSTATE_ENABLED
            @pttbb[11].fsStyle   = %BTNS_BUTTON
            @pttbb[11].dwData    = 0
            @pttbb[11].iString   = -1

            SendMessage hBottomToolbar, %TB_ADDBUTTONS, 12, BYVAL pttbb
            ' Free memory that was allocated for the button info
            HeapFree GetProcessHeap(), 0, BYVAL pttbb
            ' Update the size of the toolbar
            SendMessage hBottomToolbar, %TB_AUTOSIZE, 0, 0
         END IF

         FUNCTION = %FALSE
         EXIT FUNCTION
   END SELECT

   FUNCTION = DefWindowProc(hWnd, uMsg, wParam, lParam)

END FUNCTION
'=========================================================================================


Resource file:


// Resource script

////////////////////////////////////////////////////////////////////////////////
//
//  Menu/Toolbar Identifiers
//

#define IDM_ARROWLEFT                        28000
#define IDM_ARROWRIGHT                       28001
#define IDM_COPYCLIPBOARD                    28002
#define IDM_COPYTOFOLDER                     28003
#define IDM_CUTCLIPBOARD                     28004
#define IDM_DELETE                           28005
#define IDM_FAVORITES                        28006
#define IDM_FOLDERCLOSED                     28007
#define IDM_FOLDEROPEN                       28008
#define IDM_FOLDEROPTIONS                    28009
#define IDM_FOLDERS                          28010
#define IDM_HISTORY                          28011
#define IDM_HOME                             28012
#define IDM_MAIL                             28013
#define IDM_MOVETOFOLDER                     28014
#define IDM_NEWDOCUMENT                      28015
#define IDM_OPENDOCUMENT                     28016
#define IDM_PASTECLIPBOARD                   28017
#define IDM_PRINT                            28018
#define IDM_PRINTPREVIEW                     28019
#define IDM_DOCUMENTPROPERTIES               28020
#define IDM_REDOROUND                        28021
#define IDM_REFRESH                          28022
#define IDM_SAVE                             28023
#define IDM_SEARCH                           28024


////////////////////////////////////////////////////////////////////////////////
//
// Application Bitmap Strips.
//

TBNOR  BITMAP Toolbar24Normal.BMP
TBHOT  BITMAP Toolbar24Hot.BMP
TBDIS  BITMAP Toolbar24Disabled.BMP

////////////////////////////////////////////////////////////////////////////////
//
//  Toolbar tooltip string table
//

STRINGTABLE DISCARDABLE
BEGIN
   IDM_ARROWLEFT              "Arrow Left"
   IDM_ARROWRIGHT             "Arrow Right"
   IDM_COPYCLIPBOARD          "Copy to Clipboard"
   IDM_COPYTOFOLDER           "Copy to Folder"
   IDM_CUTCLIPBOARD           "Cut to Clipboard"
   IDM_DELETE                 "Delete"
   IDM_FAVORITES              "Favorites"
   IDM_FOLDERCLOSED           "Folder Closed"
   IDM_FOLDEROPEN             "Folder Open"
   IDM_FOLDEROPTIONS          "Folder Options"
   IDM_FOLDERS                "Folders"
   IDM_HISTORY                "History"
   IDM_HOME                   "Home"
   IDM_MAIL                   "Mail"
   IDM_MOVETOFOLDER           "Move to Folder"
   IDM_NEWDOCUMENT            "New Document"
   IDM_OPENDOCUMENT           "Open Document"
   IDM_PASTECLIPBOARD         "Paste Clipboard"
   IDM_PRINT                  "Print"
   IDM_PRINTPREVIEW           "Print Preview"
   IDM_DOCUMENTPROPERTIES     "Document Properties"
   IDM_REDOROUND              "Redo"
   IDM_REFRESH                "Refresh"
   IDM_SAVE                   "Save"
   IDM_SEARCH                 "Search"
END


José Roca

#13
 
Placing a Combobox in the Toolbar

SetParent is used to embed the combobox in the toolbar. SetParent can be used because the combobox sends its notifications to the original parent. This eliminates the need to subclass the toolbar. A separator is used to make room for the combobox in the toolbar. The iBitmap member of the TBBUTTON structure is used to set the width of the separator.

Based on an example by Dominic Mitchell: http://www.powerbasic.com/support/forums/Forum4/HTML/008228.html


'#########################################################################################
' Toolbar Control example
'#########################################################################################

#DIM ALL
#COMPILE EXE
#INCLUDE ONCE "ToolbarCtrl.inc"
#RESOURCE "EX_TOOLBAR_03.PBR"

GLOBAL   ghInstance              AS DWORD    ' handle of the application instance

'--------------------------- [ Command Identifiers ] ---------------------------

%IDM_ARROWLEFT                               = 28000
%IDM_ARROWRIGHT                              = 28001
%IDM_COPYCLIPBOARD                           = 28002
%IDM_COPYTOFOLDER                            = 28003
%IDM_CUTCLIPBOARD                            = 28004
%IDM_DELETE                                  = 28005
%IDM_FAVORITES                               = 28006
%IDM_FOLDERCLOSED                            = 28007
%IDM_FOLDEROPEN                              = 28008
%IDM_FOLDEROPTIONS                           = 28009
%IDM_FOLDERS                                 = 28010

'--------------------------- [ Control Identifiers ] ---------------------------

%IDC_TOOLBAR                                 = 101
%IDC_COMBO                                   = 102


'-------------------------------------------------------------------------------
'
' PROCEDURE: WinMain
' PURPOSE:   Program entry point, calls initialization function, processes
'            message loop.
'
'-------------------------------------------------------------------------------

FUNCTION WinMain _
   ( _
   BYVAL hInstance      AS DWORD, _       ' handle of current instance
   BYVAL hPrevInstance  AS DWORD, _       ' handle of previous instance(not used in Win32)
   BYVAL pszCmdLine     AS ASCIIZ PTR, _  ' address of command line
   BYVAL nCmdShow       AS LONG _         ' show state of window
   ) AS LONG

   LOCAL szClassName       AS ASCIIZ * %MAX_PATH         ' class name
   LOCAL twcx              AS WNDCLASSEX                 ' class information
   LOCAL tmsg              AS tagMsg                     ' message information
   LOCAL ticc              AS INIT_COMMON_CONTROLSEX     ' specifies common control classes to register
   LOCAL hWnd              AS DWORD                      ' handle of main window

   ' Save the handle of the application instance
   ghInstance = hInstance

   ' Register the Form1 window
   szClassName        = "EX_TOOLBAR_03"
   twcx.cbSize        = SIZEOF(twcx)                              ' size of WNDCLASSEX structure
   twcx.style         = %CS_DBLCLKS                               ' class styles
   twcx.lpfnWndProc   = CODEPTR(Form1_WndProc)                    ' address of window procedure used by class
   twcx.cbClsExtra    = 0                                         ' extra class bytes
   twcx.cbWndExtra    = 0                                         ' extra window bytes
   twcx.hInstance     = ghInstance                                ' instance of the process that is registering the window
   twcx.hIcon         = LoadIcon(%NULL, BYVAL %IDI_APPLICATION)   ' handle of class icon
   twcx.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)       ' handle of class cursor
   twcx.hbrBackground = %COLOR_BTNFACE + 1                        ' brush used to fill background of window's client area
   twcx.lpszMenuName  = %NULL                                     ' resource identifier of the class menu
   twcx.lpszClassName = VARPTR(szClassName)                       ' class name
   twcx.hIconSm       = %NULL                                     ' handle of small icon shown in caption/system Taskbar
   IF ISFALSE RegisterClassEx(twcx) THEN
      FUNCTION = %TRUE
      EXIT FUNCTION
   END IF

   ' Load the common controls library and
   ' specify the classes to register.
   ticc.dwSize = SIZEOF(ticc)
   ticc.dwICC  = %ICC_BAR_CLASSES
   InitCommonControlsEx ticc

   ' Create the Form1 window
   hWnd = CreateWindowEx(%WS_EX_WINDOWEDGE, _                                          ' extended styles
                         szClassName, _                                                ' class name
                         "Toolbar Demo", _                                             ' caption
                         %WS_OVERLAPPEDWINDOW OR %WS_VISIBLE, _                        ' window styles
                         %CW_USEDEFAULT, 0, _                                          ' left, top
                         %CW_USEDEFAULT, 0, _                                          ' width, height
                         %NULL, %NULL, _                                               ' handle of owner, menu handle
                         ghInstance, BYVAL %NULL)                                      ' handle of instance, creation parameters

   ' If window could not be created, return "failure"
   IF ISFALSE hWnd THEN
      FUNCTION = %FALSE
      EXIT FUNCTION
   END IF

   ' Make the window visible; update its client area
   ShowWindow hWnd, nCmdShow
   UpdateWindow hWnd

   ' Main message loop of program.
   ' Acquire and dispatch messages until a WM_QUIT message is received.
   WHILE ISTRUE GetMessage(tmsg, BYVAL %NULL, 0, 0)
      IF ISFALSE IsDialogMessage(hWnd, tmsg) THEN
         TranslateMessage tmsg
         DispatchMessage tmsg
      END IF
   WEND

   FUNCTION = tmsg.wParam

END FUNCTION

'-------------------------------------------------------------------------------
'
' PROCEDURE: Form1_WndProc
' PURPOSE:   Processes messages for the Form1 window.
'
'-------------------------------------------------------------------------------

FUNCTION Form1_WndProc _
   ( _
   BYVAL hWnd     AS DWORD, _ ' window handle
   BYVAL uMsg     AS DWORD, _ ' type of message
   BYVAL wParam   AS DWORD, _ ' first message parameter
   BYVAL lParam   AS LONG _   ' second message parameter
   ) EXPORT AS LONG

   LOCAL sBtnText       AS STRING               ' toolbar button caption
   LOCAL ttbb           AS TBBUTTON             ' specifies or receives the attributes of a toolbar button
   LOCAL ttbab          AS TBADDBITMAP          ' specifies the images to add to a toolbar
   LOCAL ptnmhdr        AS NMHDR PTR            ' information about a notification message
   LOCAL ptttdi         AS NMTTDISPINFO PTR     ' tooltip notification message information
   LOCAL pttbb          AS TBBUTTON PTR         ' address of array of toolbar button info
   LOCAL hFont          AS DWORD                ' handle of font used by form
   LOCAL lMsgResult     AS LONG                 ' value returned to message after message is processed
   LOCAL hImageList     AS DWORD                ' handle of imagelist control
   LOCAL hImage         AS DWORD                ' handle of bitmap
   LOCAL tbn            AS TBNOTIFY PTR         ' for toolbar notification messages
   LOCAL rc             AS RECT                 ' bounding rectangle for a specified toolbar button
   LOCAL szItem         AS ASCIIZ * 256         ' working variable
   LOCAL hToolbar       AS DWORD                ' handle of the tooolbar
   LOCAL hCombo         AS DWORD                ' handle of the combobox

   SELECT CASE uMsg

      CASE %WM_COMMAND

         ' -------------------------------------------------------
         ' Messages from the Toolbar are handled here.
         ' ------------------------------------------------------

         SELECT CASE LOWRD(wParam)

            CASE %IDCANCEL
               IF HIWRD(wParam) = %BN_CLICKED THEN
                  SendMessage hWnd, %WM_CLOSE, wParam, lParam
                  FUNCTION = %FALSE
                  EXIT FUNCTION
               END IF

            CASE %IDM_ARROWLEFT
               MSGBOX "Arrow left button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_ARROWRIGHT
               MSGBOX "Arrow right button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_COPYCLIPBOARD
               MSGBOX "Copy to clipboard button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_COPYTOFOLDER
               MSGBOX "Copy to folder button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_CUTCLIPBOARD
               MSGBOX "Cut to clipboard button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_DELETE
               MSGBOX "Delete button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FAVORITES
               MSGBOX "Favorites button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDERCLOSED
               MSGBOX "Folder closed button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDEROPEN
               MSGBOX "Folder open button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDEROPTIONS
               MSGBOX "Folder options button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDERS
               MSGBOX "Folders button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

         END SELECT

      CASE %WM_NOTIFY

         ' -------------------------------------------------------
         ' Notification messages are handled here.
         ' The TTN_GETDISPINFO message is sent by a ToolTip control
         ' to retrieve information needed to display a ToolTip window.
         ' ------------------------------------------------------
         ptnmhdr = lParam
         tbn = lParam

         SELECT CASE @ptnmhdr.code
            CASE %TTN_GETDISPINFO
               ptttdi        = lParam
               @ptttdi.hinst = ghInstance
               SELECT CASE @ptttdi.hdr.hwndFrom
                  ' The TB_GETTOOLTIPS message retrieves the handle to the ToolTip control,
                  ' if any, associated with the toolbar.
                  CASE SendMessage(GetDlgItem(hWnd, %IDC_TOOLBAR), %TB_GETTOOLTIPS, 0, 0)
                     @ptttdi.lpszText = @ptttdi.hdr.idFrom
                     EXIT FUNCTION
               END SELECT
         END SELECT

      CASE %WM_SYSCOLORCHANGE
         ' Forward this message to common controls so that they will
         ' be properly updated when the user changes the color settings.
         SendMessage GetDlgItem(hWnd, %IDC_TOOLBAR), %WM_SYSCOLORCHANGE, wParam, lParam

      CASE %WM_DESTROY
         ' Destroy the image lists
         hToolbar = GetDlgItem(hWnd, %IDC_TOOLBAR)
         ImageList_Destroy SendMessage(hToolbar, %TB_SETIMAGELIST, 0, %NULL)
         ImageList_Destroy SendMessage(hToolbar, %TB_SETDISABLEDIMAGELIST, 0, %NULL)
         ImageList_Destroy SendMessage(hToolbar, %TB_SETHOTIMAGELIST, 0, %NULL)
         ' End the application
         PostQuitMessage 0
         FUNCTION = %FALSE
         EXIT FUNCTION

      CASE %WM_SIZE
         IF wParam <> %SIZE_MINIMIZED THEN
            ' Update the size and position of the Toolbar control
            SendMessage GetDlgItem(hWnd, %IDC_TOOLBAR), %TB_AUTOSIZE, 0, 0
         END IF
         FUNCTION = %FALSE
         EXIT FUNCTION

      CASE %WM_CREATE
         ' Create font used by container
         hFont = GetStockObject(%DEFAULT_GUI_FONT)

         ' Create the toolbar control
         hToolbar = CreateWindowEx(%NULL, _                                              ' extended styles
                                    "ToolbarWindow32", _                                  ' class name
                                    "", _                                                 ' caption
                                    %WS_CHILD OR %WS_VISIBLE OR _                         ' window styles
                                    %CCS_TOP OR %TBSTYLE_TOOLTIPS OR _
                                    %TBSTYLE_FLAT, _                                      ' class styles
                                    0, 0, _                                               ' left, top
                                    345, 116, _                                           ' width, height
                                    hWnd, %IDC_TOOLBAR, _                                 ' handle of parent, control ID
                                    ghInstance, BYVAL %NULL)                              ' handle of instance, creation parameters
         SendMessage hToolbar, %WM_SETFONT, hFont, %TRUE

         ' Set the extended class styles for the control
         SendMessage hToolbar, %TB_SETEXTENDEDSTYLE, 0, %TBSTYLE_EX_DRAWDDARROWS

         ' Set the imagelist used with default images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBNOR", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hToolbar, %TB_SETIMAGELIST, 0, hImageList

         ' Set the imagelist used with disabled images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBDIS", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hToolbar, %TB_SETDISABLEDIMAGELIST, 0, hImageList

         ' Set the imagelist used with hot images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBHOT", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hToolbar, %TB_SETHOTIMAGELIST, 0, hImageList

         ' Allocate memory for the button info array
         pttbb = HeapAlloc(GetProcessHeap(), %HEAP_ZERO_MEMORY, 13 * SIZEOF(ttbb))
         IF ISTRUE pttbb THEN
            ' Send the TB_BUTTONSTRUCTSIZE message, for backward compatibility
            SendMessage hToolbar, %TB_BUTTONSTRUCTSIZE, SIZEOF(ttbb), 0
            ' Set the size of the bitmaps
            SendMessage hToolbar, %TB_SETBITMAPSIZE, 0, MAKLNG(24, 24)
            ' Add buttons to the toolbar
            @pttbb[0].iBitmap    = 0
            @pttbb[0].idCommand  = %IDM_ARROWLEFT
            @pttbb[0].fsState    = %TBSTATE_ENABLED
            @pttbb[0].fsStyle    = %BTNS_CHECKGROUP
            @pttbb[0].dwData     = 0
            @pttbb[0].iString    = -1

            @pttbb[1].iBitmap    = 1
            @pttbb[1].idCommand  = %IDM_ARROWRIGHT
            @pttbb[1].fsState    = %TBSTATE_ENABLED
            @pttbb[1].fsStyle    = %BTNS_CHECKGROUP
            @pttbb[1].dwData     = 0
            @pttbb[1].iString    = -1

            @pttbb[2].iBitmap    = 2
            @pttbb[2].idCommand  = %IDM_COPYCLIPBOARD
            @pttbb[2].fsState    = %TBSTATE_ENABLED
            @pttbb[2].fsStyle    = %BTNS_BUTTON
            @pttbb[2].dwData     = 0
            @pttbb[2].iString    = -1

            @pttbb[3].iBitmap    = 0
            @pttbb[3].idCommand  = 0
            @pttbb[3].fsState    = %TBSTATE_ENABLED
            @pttbb[3].fsStyle    = %BTNS_SEP
            @pttbb[3].dwData     = 0
            @pttbb[3].iString    = -1

            @pttbb[4].iBitmap    = 3
            @pttbb[4].idCommand  = %IDM_COPYTOFOLDER
            @pttbb[4].fsState    = %TBSTATE_ENABLED
            @pttbb[4].fsStyle    = %BTNS_BUTTON
            @pttbb[4].dwData     = 0
            @pttbb[4].iString    = -1

            @pttbb[5].iBitmap    = 4
            @pttbb[5].idCommand  = %IDM_CUTCLIPBOARD
            @pttbb[5].fsState    = %TBSTATE_ENABLED
            @pttbb[5].fsStyle    = %BTNS_CHECK
            @pttbb[5].dwData     = 0
            @pttbb[5].iString    = -1

            @pttbb[6].iBitmap    = 5
            @pttbb[6].idCommand  = %IDM_DELETE
            @pttbb[6].fsState    = %TBSTATE_ENABLED
            @pttbb[6].fsStyle    = %BTNS_BUTTON
            @pttbb[6].dwData     = 0
            @pttbb[6].iString    = -1

            @pttbb[7].iBitmap    = 6
            @pttbb[7].idCommand  = %IDM_FAVORITES
            @pttbb[7].fsState    = %TBSTATE_ENABLED
            @pttbb[7].fsStyle    = %BTNS_BUTTON
            @pttbb[7].dwData     = 0
            @pttbb[7].iString    = -1

            @pttbb[8].iBitmap    = 210   ' Make room for the combobox
            @pttbb[8].idCommand  = 0
            @pttbb[8].fsState    = %TBSTATE_ENABLED
            @pttbb[8].fsStyle    = %BTNS_SEP
            @pttbb[8].dwData     = 0
            @pttbb[8].iString    = -1

            @pttbb[9].iBitmap    = 7
            @pttbb[9].idCommand  = %IDM_FOLDERCLOSED
            @pttbb[9].fsState    = %TBSTATE_ENABLED
            @pttbb[9].fsStyle    = %BTNS_BUTTON
            @pttbb[9].dwData     = 0
            @pttbb[9].iString    = -1

            @pttbb[10].iBitmap    = 8
            @pttbb[10].idCommand  = %IDM_FOLDEROPEN
            @pttbb[10].fsState    = %TBSTATE_ENABLED
            @pttbb[10].fsStyle    = %BTNS_BUTTON
            @pttbb[10].dwData     = 0
            @pttbb[10].iString    = -1

            @pttbb[11].iBitmap    = 9
            @pttbb[11].idCommand  = %IDM_FOLDEROPTIONS
            @pttbb[11].fsState    = %TBSTATE_ENABLED
            @pttbb[11].fsStyle    = %BTNS_BUTTON
            @pttbb[11].dwData     = 0
            @pttbb[11].iString    = -1

            @pttbb[12].iBitmap   = 10
            @pttbb[12].idCommand = %IDM_FOLDERS
            @pttbb[12].fsState   = %TBSTATE_ENABLED
            @pttbb[12].fsStyle   = %BTNS_BUTTON
            @pttbb[12].dwData    = 0
            @pttbb[12].iString   = -1

            SendMessage hToolbar, %TB_ADDBUTTONS, 13, BYVAL pttbb
            ' Free memory that was allocated for the button info
            HeapFree GetProcessHeap(), 0, BYVAL pttbb
            ' Update the size of the toolbar
            SendMessage hToolbar, %TB_AUTOSIZE, 0, 0
         END IF

         ' Create the Combo1 combobox
         hCombo = CreateWindowEx(%WS_EX_CLIENTEDGE, _                                  ' extended styles
                                    "Combobox", _                                         ' class name
                                    "", _                                                 ' caption
                                    %WS_CHILD OR %WS_VISIBLE OR %WS_VSCROLL OR _          ' window styles
                                    %WS_BORDER OR %WS_TABSTOP OR _
                                    %CBS_DROPDOWN OR %CBS_HASSTRINGS OR %CBS_SORT, _      ' class styles
                                    228, 5, _                                            ' left, top
                                    200, 105, _                                           ' width, height
                                    hWnd, %IDC_COMBO, _                                   ' handle of parent, control ID
                                    ghInstance, BYVAL %NULL)                              ' handle of instance, creation parameters
         SendMessage hCombo, %WM_SETFONT, hFont, %TRUE
         SetParent hCombo, hToolbar

         ' Add the initial items
         ' Turn off repainting
         SendMessage hCombo, %WM_SETREDRAW, %FALSE, 0
         szItem = "Item 5"
         SendMessage hCombo, %CB_ADDSTRING, 0, BYVAL VARPTR(szItem)
         szItem = "Item 4"
         SendMessage hCombo, %CB_ADDSTRING, 0, BYVAL VARPTR(szItem)
         szItem = "Item 3"
         SendMessage hCombo, %CB_ADDSTRING, 0, BYVAL VARPTR(szItem)
         szItem = "Item 2"
         SendMessage hCombo, %CB_ADDSTRING, 0, BYVAL VARPTR(szItem)
         szItem = "Item 1"
         SendMessage hCombo, %CB_ADDSTRING, 0, BYVAL VARPTR(szItem)
         szItem = "Item 0"
         SendMessage hCombo, %CB_ADDSTRING, 0, BYVAL VARPTR(szItem)
         ' Turn on repainting
         SendMessage hCombo, %WM_SETREDRAW, %TRUE, 0
         InvalidateRect hCombo, BYVAL %NULL, %TRUE
         UpdateWindow hCombo

         FUNCTION = %FALSE
         EXIT FUNCTION
   END SELECT

   FUNCTION = DefWindowProc(hWnd, uMsg, wParam, lParam)

END FUNCTION
'=========================================================================================


José Roca

#14
 
Customizing the Toolbar

Adding the CCS_ADJUSTABLE style flag when you create the toolbar adds drag and drop functionality, allowing users to to move tools to another location on the toolbar or delete them by dragging them off the toolbar. It provides users a quick and easy way to organize their toolbar, but does not allow them to add tools.

Sending a TB_CUSTOMIZE message displays the Customize Toolbar dialog box. However, if you don't process the TBN_QUERYINSERT and TBN_QUERYDELETE notification messages and return TRUE the dialog will flash and disappear. Also, if you don't process the TBN_GETBUTTONINFO message and fill the tbbutton member of the NMTOOLBAR structure with the button information, you will be able to delete but not to insert buttons.

Here is the needed code to process these messages:


   LOCAL ptnmhdr        AS NMHDR PTR            ' information about a notification message
   LOCAL ptnmtb         AS NMTOOLBAR PTR        ' for toolbar notification messages


      CASE %WM_NOTIFY

         ptnmhdr = lParam
         ptnmtb = lParam

         SELECT CASE @ptnmhdr.code

            CASE %TBN_QUERYINSERT
               FUNCTION = %TRUE
               EXIT FUNCTION

            CASE %TBN_QUERYDELETE
               FUNCTION = %TRUE
               EXIT FUNCTION
               
            CASE %TBN_GETBUTTONINFO
               IF @ptnmtb.iItem => 0 AND @ptnmtb.iItem <= 15 THEN
                  @ptnmtb.tbButton = tbb(@ptnmtb.iItem)
                  FUNCTION = %TRUE
                  EXIT FUNCTION
               END IF


tbb is an array of TBUTTON structures that we will fill after the toolbar has been created as follows:


   DIM   tbb(16)        AS STATIC TBBUTTON      ' toolbar buttons information

            ' Collect button information
            FOR i = 0 TO 15     ' number of toolbar buttons (16)
               SendMessage hToolBar, %TB_GETBUTTON, i, VARPTR(tbb(i))
            NEXT


Here is the full code listing:


'#########################################################################################
' Toolbar Control example
'#########################################################################################

#DIM ALL
#COMPILE EXE
#INCLUDE ONCE "ToolbarCtrl.inc"
#RESOURCE "EX_TOOLBAR_03.PBR"

GLOBAL   ghInstance              AS DWORD    ' handle of the application instance

'--------------------------- [ Command Identifiers ] ---------------------------

%IDM_ARROWLEFT                               = 28000
%IDM_ARROWRIGHT                              = 28001
%IDM_COPYCLIPBOARD                           = 28002
%IDM_COPYTOFOLDER                            = 28003
%IDM_CUTCLIPBOARD                            = 28004
%IDM_DELETE                                  = 28005
%IDM_FAVORITES                               = 28006
%IDM_FOLDERCLOSED                            = 28007
%IDM_FOLDEROPEN                              = 28008
%IDM_FOLDEROPTIONS                           = 28009
%IDM_FOLDERS                                 = 28010
%IDM_HISTORY                                 = 28011
%IDM_HOME                                    = 28012

'--------------------------- [ Control Identifiers ] ---------------------------

%IDC_TOOLBAR                                 = 101
%IDC_BUTTON                                  = 102

'-------------------------------------------------------------------------------
'
' PROCEDURE: WinMain
' PURPOSE:   Program entry point, calls initialization function, processes
'            message loop.
'
'-------------------------------------------------------------------------------

FUNCTION WinMain _
   ( _
   BYVAL hInstance      AS DWORD, _       ' handle of current instance
   BYVAL hPrevInstance  AS DWORD, _       ' handle of previous instance(not used in Win32)
   BYVAL pszCmdLine     AS ASCIIZ PTR, _  ' address of command line
   BYVAL nCmdShow       AS LONG _         ' show state of window
   ) AS LONG

   LOCAL szClassName       AS ASCIIZ * %MAX_PATH         ' class name
   LOCAL twcx              AS WNDCLASSEX                 ' class information
   LOCAL tmsg              AS tagMsg                     ' message information
   LOCAL ticc              AS INIT_COMMON_CONTROLSEX     ' specifies common control classes to register
   LOCAL hWnd              AS DWORD                      ' handle of main window

   ' Save the handle of the application instance
   ghInstance = hInstance

   ' Register the Form1 window
   szClassName        = "EX_TOOLBAR_03"
   twcx.cbSize        = SIZEOF(twcx)                              ' size of WNDCLASSEX structure
   twcx.style         = %CS_DBLCLKS                               ' class styles
   twcx.lpfnWndProc   = CODEPTR(Form1_WndProc)                    ' address of window procedure used by class
   twcx.cbClsExtra    = 0                                         ' extra class bytes
   twcx.cbWndExtra    = 0                                         ' extra window bytes
   twcx.hInstance     = ghInstance                                ' instance of the process that is registering the window
   twcx.hIcon         = LoadIcon(%NULL, BYVAL %IDI_APPLICATION)   ' handle of class icon
   twcx.hCursor       = LoadCursor(%NULL, BYVAL %IDC_ARROW)       ' handle of class cursor
   twcx.hbrBackground = %COLOR_BTNFACE + 1                        ' brush used to fill background of window's client area
   twcx.lpszMenuName  = %NULL                                     ' resource identifier of the class menu
   twcx.lpszClassName = VARPTR(szClassName)                       ' class name
   twcx.hIconSm       = %NULL                                     ' handle of small icon shown in caption/system Taskbar
   IF ISFALSE RegisterClassEx(twcx) THEN
      FUNCTION = %TRUE
      EXIT FUNCTION
   END IF

   ' Load the common controls library and
   ' specify the classes to register.
   ticc.dwSize = SIZEOF(ticc)
   ticc.dwICC  = %ICC_BAR_CLASSES
   InitCommonControlsEx ticc

   ' Create the Form1 window
   hWnd = CreateWindowEx(%WS_EX_WINDOWEDGE, _                                          ' extended styles
                         szClassName, _                                                ' class name
                         "Customizing Toolbar", _                                      ' caption
                         %WS_OVERLAPPEDWINDOW OR %WS_VISIBLE, _                        ' window styles
                         %CW_USEDEFAULT, 0, _                                          ' left, top
                         %CW_USEDEFAULT, 0, _                                          ' width, height
                         %NULL, %NULL, _                                               ' handle of owner, menu handle
                         ghInstance, BYVAL %NULL)                                      ' handle of instance, creation parameters

   ' If window could not be created, return "failure"
   IF ISFALSE hWnd THEN
      FUNCTION = %FALSE
      EXIT FUNCTION
   END IF

   ' Make the window visible; update its client area
   ShowWindow hWnd, nCmdShow
   UpdateWindow hWnd

   ' Main message loop of program.
   ' Acquire and dispatch messages until a WM_QUIT message is received.
   WHILE ISTRUE GetMessage(tmsg, BYVAL %NULL, 0, 0)
      IF ISFALSE IsDialogMessage(hWnd, tmsg) THEN
         TranslateMessage tmsg
         DispatchMessage tmsg
      END IF
   WEND

   FUNCTION = tmsg.wParam

END FUNCTION

'-------------------------------------------------------------------------------
'
' PROCEDURE: Form1_WndProc
' PURPOSE:   Processes messages for the Form1 window.
'
'-------------------------------------------------------------------------------

FUNCTION Form1_WndProc _
   ( _
   BYVAL hWnd     AS DWORD, _ ' window handle
   BYVAL uMsg     AS DWORD, _ ' type of message
   BYVAL wParam   AS DWORD, _ ' first message parameter
   BYVAL lParam   AS LONG _   ' second message parameter
   ) EXPORT AS LONG

   LOCAL sBtnText       AS STRING               ' toolbar button caption
   LOCAL ttbb           AS TBBUTTON             ' specifies or receives the attributes of a toolbar button
   LOCAL ttbab          AS TBADDBITMAP          ' specifies the images to add to a toolbar
   LOCAL ptnmhdr        AS NMHDR PTR            ' information about a notification message
   LOCAL ptttdi         AS NMTTDISPINFO PTR     ' tooltip notification message information
   LOCAL pttbb          AS TBBUTTON PTR         ' address of array of toolbar button info
   LOCAL hToolbar       AS DWORD                ' handle of the toolbar
   LOCAL hButton        AS DWORD                ' handle of the button
   LOCAL hFont          AS DWORD                ' handle of font used by form
   LOCAL lMsgResult     AS LONG                 ' value returned to message after message is processed
   LOCAL hImageList     AS DWORD                ' handle of imagelist control
   LOCAL hImage         AS DWORD                ' handle of bitmap
   LOCAL i              AS LONG                 ' loop counter
   LOCAL ptnmtb         AS NMTOOLBAR PTR        ' for toolbar notification messages
   DIM   tbb(16)        AS STATIC TBBUTTON      ' toolbar buttons information

   SELECT CASE uMsg

      CASE %WM_COMMAND

         ' -------------------------------------------------------
         ' Messages from the Toolbar are handled here.
         ' ------------------------------------------------------

         SELECT CASE LOWRD(wParam)

            CASE %IDCANCEL
               IF HIWRD(wParam) = %BN_CLICKED THEN
                  SendMessage hWnd, %WM_CLOSE, wParam, lParam
                  FUNCTION = %FALSE
                  EXIT FUNCTION
               END IF

            CASE %IDC_BUTTON
               IF HIWRD(wParam) = %BN_CLICKED THEN
                  SendMessage GetDlgItem(hWnd, %IDC_TOOLBAR), %TB_CUSTOMIZE, 0, 0
                  FUNCTION = %FALSE
                  EXIT FUNCTION
               END IF

            CASE %IDM_ARROWLEFT
               MSGBOX "Arrow Left button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_ARROWRIGHT
               MSGBOX "Arrow right button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_COPYCLIPBOARD
               MSGBOX "Copy to clipboard button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_COPYTOFOLDER
               MSGBOX "Copy to folder button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_CUTCLIPBOARD
               MSGBOX "Cut to clipboard button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_DELETE
               MSGBOX "Delete button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FAVORITES
               MSGBOX "Favorites button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDERCLOSED
               MSGBOX "Folder closed button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDEROPEN
               MSGBOX "Folder open button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDEROPTIONS
               MSGBOX "Folder options button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_FOLDERS
               MSGBOX "Folders button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_HISTORY
               MSGBOX "History button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

            CASE %IDM_HOME
               MSGBOX "Home button clicked"
               FUNCTION = %FALSE
               EXIT FUNCTION

         END SELECT

      CASE %WM_NOTIFY

         ' -------------------------------------------------------
         ' Notification messages are handled here.
         ' The TTN_GETDISPINFO message is sent by a ToolTip control
         ' to retrieve information needed to display a ToolTip window.
         ' ------------------------------------------------------
         ptnmhdr = lParam
         ptnmtb = lParam

         SELECT CASE @ptnmhdr.code

            CASE %TBN_QUERYINSERT
               FUNCTION = %TRUE
               EXIT FUNCTION

            CASE %TBN_QUERYDELETE
               FUNCTION = %TRUE
               EXIT FUNCTION

            CASE %TBN_GETBUTTONINFO
               IF @ptnmtb.iItem => 0 AND @ptnmtb.iItem <= 15 THEN
                  @ptnmtb.tbButton = tbb(@ptnmtb.iItem)
                  FUNCTION = %TRUE
                  EXIT FUNCTION
               END IF

            CASE %TTN_GETDISPINFO
               ptttdi        = lParam
               @ptttdi.hinst = ghInstance
               SELECT CASE @ptttdi.hdr.hwndFrom
                  ' The TB_GETTOOLTIPS message retrieves the handle to the ToolTip control,
                  ' if any, associated with the toolbar.
                  CASE SendMessage(GetDlgItem(hWnd, %IDC_TOOLBAR), %TB_GETTOOLTIPS, 0, 0)
                     @ptttdi.lpszText = @ptttdi.hdr.idFrom
                     EXIT FUNCTION
               END SELECT
         END SELECT

      CASE %WM_SYSCOLORCHANGE
         ' Forward this message to common controls so that they will
         ' be properly updated when the user changes the color settings.
         SendMessage GetDlgItem(hWnd, %IDC_TOOLBAR), %WM_SYSCOLORCHANGE, wParam, lParam

      CASE %WM_DESTROY
         ' Destroy the image lists
         hToolbar = GetDlgItem(hWnd, %IDC_TOOLBAR)
         ImageList_Destroy SendMessage(hToolbar, %TB_SETIMAGELIST, 0, %NULL)
         ImageList_Destroy SendMessage(hToolbar, %TB_SETDISABLEDIMAGELIST, 0, %NULL)
         ImageList_Destroy SendMessage(hToolbar, %TB_SETHOTIMAGELIST, 0, %NULL)
         ' End the application
         PostQuitMessage 0
         FUNCTION = %FALSE
         EXIT FUNCTION

      CASE %WM_SIZE
         IF wParam <> %SIZE_MINIMIZED THEN
            ' Update the size and position of the Toolbar control
            SendMessage GetDlgItem(hWnd, %IDC_TOOLBAR), %TB_AUTOSIZE, 0, 0
         END IF
         FUNCTION = %FALSE
         EXIT FUNCTION

      CASE %WM_CREATE
         ' Create font used by container
         hFont = GetStockObject(%DEFAULT_GUI_FONT)

         ' Create the Toolbar1 toolbar control
         hToolbar = CreateWindowEx (%NULL, _                                              ' extended styles
                                    "ToolbarWindow32", _                                  ' class name
                                    "", _                                                 ' caption
                                    %WS_CHILD OR %WS_VISIBLE OR _                         ' window styles
                                    %CCS_TOP OR %CCS_ADJUSTABLE OR _
                                    %TBSTYLE_TOOLTIPS OR %TBSTYLE_FLAT, _                                      ' class styles
                                    0, 0, _                                               ' left, top
                                    345, 116, _                                           ' width, height
                                    hWnd, %IDC_TOOLBAR, _                                 ' handle of parent, control ID
                                    ghInstance, BYVAL %NULL)                              ' handle of instance, creation parameters
         SendMessage hToolbar, %WM_SETFONT, hFont, %TRUE

         ' Set the extended class styles for the control
         SendMessage hToolbar, %TB_SETEXTENDEDSTYLE, 0, %TBSTYLE_EX_DRAWDDARROWS

         ' Set the imagelist used with default images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBNOR", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hToolbar, %TB_SETIMAGELIST, 0, hImageList

         ' Set the imagelist used with disabled images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBDIS", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hToolbar, %TB_SETDISABLEDIMAGELIST, 0, hImageList

         ' Set the imagelist used with hot images
         hImageList = ImageList_Create(24, 24, %ILC_MASK OR %ILC_COLOR24, 1, 0)
         hImage = LoadImage(ghInstance, "TBHOT", %IMAGE_BITMAP, 0, 0, %LR_DEFAULTSIZE)
         ImageList_AddMasked hImageList, hImage, RGB(255,0,255)
         DeleteObject hImage
         SendMessage hToolbar, %TB_SETHOTIMAGELIST, 0, hImageList

         ' Allocate memory for the button info array
         pttbb = HeapAlloc(GetProcessHeap(), %HEAP_ZERO_MEMORY, 16 * SIZEOF(ttbb))
         IF ISTRUE pttbb THEN
            ' Send the TB_BUTTONSTRUCTSIZE message, for backward compatibility
            SendMessage hToolbar, %TB_BUTTONSTRUCTSIZE, SIZEOF(ttbb), 0
            ' Set the size of the bitmaps
            SendMessage hToolbar, %TB_SETBITMAPSIZE, 0, MAKLNG(24, 24)
            ' Add buttons to the toolbar
            @pttbb[0].iBitmap    = 0
            @pttbb[0].idCommand  = %IDM_ARROWLEFT
            @pttbb[0].fsState    = %TBSTATE_ENABLED
            @pttbb[0].fsStyle    = %BTNS_BUTTON
            @pttbb[0].dwData     = 0
            @pttbb[0].iString    = -1

            @pttbb[1].iBitmap    = 1
            @pttbb[1].idCommand  = %IDM_ARROWRIGHT
            @pttbb[1].fsState    = %TBSTATE_ENABLED
            @pttbb[1].fsStyle    = %BTNS_BUTTON
            @pttbb[1].dwData     = 0
            @pttbb[1].iString    = -1

            @pttbb[2].iBitmap    = 2
            @pttbb[2].idCommand  = %IDM_COPYCLIPBOARD
            @pttbb[2].fsState    = %TBSTATE_ENABLED
            @pttbb[2].fsStyle    = %BTNS_BUTTON
            @pttbb[2].dwData     = 0
            @pttbb[2].iString    = -1

            @pttbb[3].iBitmap    = 0
            @pttbb[3].idCommand  = 0
            @pttbb[3].fsState    = %TBSTATE_ENABLED
            @pttbb[3].fsStyle    = %BTNS_SEP
            @pttbb[3].dwData     = 0
            @pttbb[3].iString    = -1

            @pttbb[4].iBitmap    = 3
            @pttbb[4].idCommand  = %IDM_COPYTOFOLDER
            @pttbb[4].fsState    = %TBSTATE_ENABLED
            @pttbb[4].fsStyle    = %BTNS_BUTTON
            @pttbb[4].dwData     = 0
            @pttbb[4].iString    = -1

            @pttbb[5].iBitmap    = 4
            @pttbb[5].idCommand  = %IDM_CUTCLIPBOARD
            @pttbb[5].fsState    = %TBSTATE_ENABLED
            @pttbb[5].fsStyle    = %BTNS_BUTTON
            @pttbb[5].dwData     = 0
            @pttbb[5].iString    = -1

            @pttbb[6].iBitmap    = 5
            @pttbb[6].idCommand  = %IDM_DELETE
            @pttbb[6].fsState    = %TBSTATE_ENABLED
            @pttbb[6].fsStyle    = %BTNS_BUTTON
            @pttbb[6].dwData     = 0
            @pttbb[6].iString    = -1

            @pttbb[7].iBitmap    = 6
            @pttbb[7].idCommand  = %IDM_FAVORITES
            @pttbb[7].fsState    = %TBSTATE_ENABLED
            @pttbb[7].fsStyle    = %BTNS_BUTTON
            @pttbb[7].dwData     = 0
            @pttbb[7].iString    = -1

            @pttbb[8].iBitmap    = 0
            @pttbb[8].idCommand  = 0
            @pttbb[8].fsState    = %TBSTATE_ENABLED
            @pttbb[8].fsStyle    = %BTNS_SEP
            @pttbb[8].dwData     = 0
            @pttbb[8].iString    = -1

            @pttbb[9].iBitmap    = 7
            @pttbb[9].idCommand  = %IDM_FOLDERCLOSED
            @pttbb[9].fsState    = %TBSTATE_ENABLED
            @pttbb[9].fsStyle    = %BTNS_BUTTON
            @pttbb[9].dwData     = 0
            @pttbb[9].iString    = -1

            @pttbb[10].iBitmap    = 8
            @pttbb[10].idCommand  = %IDM_FOLDEROPEN
            @pttbb[10].fsState    = %TBSTATE_ENABLED
            @pttbb[10].fsStyle    = %BTNS_BUTTON
            @pttbb[10].dwData     = 0
            @pttbb[10].iString    = -1

            @pttbb[11].iBitmap    = 9
            @pttbb[11].idCommand  = %IDM_FOLDEROPTIONS
            @pttbb[11].fsState    = %TBSTATE_ENABLED
            @pttbb[11].fsStyle    = %BTNS_BUTTON
            @pttbb[11].dwData     = 0
            @pttbb[11].iString    = -1

            @pttbb[12].iBitmap   = 10
            @pttbb[12].idCommand = %IDM_FOLDERS
            @pttbb[12].fsState   = %TBSTATE_ENABLED
            @pttbb[12].fsStyle   = %BTNS_BUTTON
            @pttbb[12].dwData    = 0
            @pttbb[12].iString   = -1

            @pttbb[13].iBitmap    = 0
            @pttbb[13].idCommand  = 0
            @pttbb[13].fsState    = %TBSTATE_ENABLED
            @pttbb[13].fsStyle    = %BTNS_SEP
            @pttbb[13].dwData     = 0
            @pttbb[13].iString    = -1

            @pttbb[14].iBitmap   = 11
            @pttbb[14].idCommand = %IDM_HISTORY
            @pttbb[14].fsState   = %TBSTATE_ENABLED
            @pttbb[14].fsStyle   = %BTNS_BUTTON
            @pttbb[14].dwData    = 0
            @pttbb[14].iString   = -1

            @pttbb[15].iBitmap   = 12
            @pttbb[15].idCommand = %IDM_HOME
            @pttbb[15].fsState   = %TBSTATE_ENABLED
            @pttbb[15].fsStyle   = %BTNS_BUTTON
            @pttbb[15].dwData    = 0
            @pttbb[15].iString   = -1

            SendMessage hToolbar, %TB_ADDBUTTONS, 16, BYVAL pttbb
            ' Free memory that was allocated for the button info
            HeapFree GetProcessHeap(), 0, BYVAL pttbb
            ' Update the size of the toolbar
            SendMessage hToolbar, %TB_AUTOSIZE, 0, 0

            ' Collect button information
            FOR i = 0 TO 15
               SendMessage hToolBar, %TB_GETBUTTON, i, VARPTR(tbb(i))
            NEXT

         END IF

         ' Create the TextBtn1 text button
         hButton = CreateWindowEx  (%NULL, _                                              ' extended styles
                                    "Button", _                                           ' class name
                                    "&Customize", _                                       ' caption
                                    %WS_CHILD OR %WS_VISIBLE OR %WS_TABSTOP OR _          ' window styles
                                    %BS_PUSHBUTTON OR %BS_CENTER OR %BS_VCENTER OR _      ' class styles
                                    %BS_FLAT, _
                                    440, 300, _                                           ' left, top
                                    76, 26, _                                             ' width, height
                                    hWnd, %IDC_BUTTON, _                                  ' handle of parent, control ID
                                    ghInstance, BYVAL %NULL)                              ' handle of instance, creation parameters
         SendMessage hButton, %WM_SETFONT, hFont, %TRUE

         FUNCTION = %FALSE
         EXIT FUNCTION
   END SELECT

   FUNCTION = DefWindowProc(hWnd, uMsg, wParam, lParam)

END FUNCTION
'=========================================================================================