BCX_TOOLBAR function

Purpose: BCX_TOOLBAR creates a toolbar control.


 Syntax:

 hCtl = BCX_TOOLBAR(hWndParent, _
                         CtlID%, _
                       NumBtns%, _ 
                          Text$, _ 
                      BtnStyles, _ 
                        HBITMAP, _ 
                       ImgIndex, _ 
                      BtnWidth , _
                      BtnHeight, _ 
                   [, WinStyle%] _ 
                     [,Exstyle%])

 Parameters:

  • hCtl The return value is a handle to the new toolbar control if the function succeeds. If the function fails, the return value is NULL.
  • hWndParent Handle to the parent window of the toolbar being created.
  • CtlID Control ID.
  • NumBtns% Number of buttons on the toolbar
  • Text$ [OPTIONAL] string of names for the buttons In the format of "name1|name2" each separated by a "|" Each additional "|" will place separators(spaces) between those buttons "name1|||name2" will place 2 spaces between names 1 and 2.
  • BtnStyles [OPTIONAL] array specifying the style of each button.
  • HBITMAP [OPTIONAL] handle to a bitmap to be placed on each button.
  • ImgIndex [OPTIONAL] array specifying the order the bitmaps are placed on the buttons. The default will be in the order the bitmap is supplied in. This also allows use of windows built in images.
    Special note: The last entry in the index when using the built in images should be the image list. i.e. IDB_STD_LARGE_COLOR Check the WIn API Help and the example for the available options. For the HBITMAP enter HINST_COMMCTRL.
  • BtnWidth [OPTIONAL] The width of each button. This only has an effect if no text is being used, in which case, the longest name determines the button width.
  • BtnHeight [OPTIONAL] The height of each button.
  • Style% [OPTIONAL] If the WinStyle% parameter is used, the default Window Style for a BCX_TOOLBAR control, WS_CHILD | WS_BORDER, is replaced with the value in WinStyle%. See your Win32 SDK or PSDK Reference help for more information about valid Window Styles.
  • Exstyle% [OPTIONAL] The default Extended Window Style for a BCX_TOOLBAR control is 0. See your Win32 SDK or PSDK Reference help for more information about valid Extended Window Styles.

Remarks: BCX_TOOLBAR can use either a bitmap or imagelist. This is detected automatically. This makes it easier to use highcolor images and allows using an imagelist with any number of images. Loading a list is easy as:


 CONST GetImageListFile(A,B) = ImageList_LoadImage(NULL, _
                                                      A, _
                                                      B, _
                                                      0, _
                                      RGB(255, 0, 255), _
                                           IMAGE_BITMAP, _
                    LR_CREATEDIBSECTION|LR_LOADFROMFILE)

The RGB value is what ever color you want to be transparent.


 DIM RAW Imlist AS HIMAGELIST
 Imlist = GetImageListFile("FileName.bmp",32) '"filename", width of image

To make it easier to place separators in a toolbar that only contain bitmaps you can insert a minus sign as te first character to suppress the text labels but still insert separators, for example,


 tbText$ = "-OPEN|SAVE||NEW||EXIT"

Example 1: The minimal needed for a standard button bar with text labels


 HWND = BCX_TOOLBAR(HWND,ID,4,"OPEN|SAVE|SETUP|QUIT")

Example 2: The minimal needed for a standard button bar with text labels and built in windows icons.


 tbText$ = "||Open|Save||New|Options|About||Exit"
 
 SET ImIdx[]
   STD_FILEOPEN, _
   STD_FILESAVE, _
       STD_COPY, _
    STD_FILENEW, _
       STD_HELP, _
     STD_DELETE, _
 IDB_STD_SMALL_COLOR
 END SET
 
 HWND = BCX_TOOLBAR(Form1, ID, 6, tbText$, 0, HINST_COMMCTRL, ImIdx)

Example 3: Here is a complete example using the BCX_TOOLBAR function.


 'Toolbar control for BCX by Mike Henning Dec 2004
 'Modified for the BCX Help file by P.Kort.
 $BCXVERSION "5.05.06"
 $TURBO 256
 
 GUI "BcxToolbar", PIXELS
 
 GLOBAL Form1 AS HWND
 GLOBAL hToolBar AS HWND
 
 ENUM
 ID_Form1
 ID_Toolbar
 END ENUM
 
 SET ImIdx[]
   STD_FILEOPEN, _
   STD_FILESAVE, _
       STD_COPY, _
    STD_FILENEW, _
       STD_HELP, _
     STD_DELETE, _
 IDB_STD_SMALL_COLOR
 END SET
 
 '-----------------------------------------------------------------------------
 SUB FORMLOAD
 
 RAW tbText$
 tbText$ = "||Open|Save|Copy|New|About|Delete"
 
 Form1 = BCX_FORM("BCX Toolbar demo", 53, 43, 800, 600)
 hToolBar = BCX_TOOLBAR(Form1, ID_Toolbar, 6, tbText$, 0, HINST_COMMCTRL, ImIdx)
 
 MoveWindow(Form1, 0, 0, 600, 400, TRUE)
 SetClassLong(Form1, GCL_STYLE, CS_OWNDC)
 
 CENTER(Form1)
 ShowWindow(Form1, SW_SHOW)
 
 END SUB
 
 '-----------------------------------------------------------------------------
 
 BEGIN EVENTS
 SELECT CASE CBMSG
 
   '---------------------------
     CASE WM_EXITSIZEMOVE
   '---------------------------
     REFRESH(hWnd)
 
   '---------------------------
     CASE WM_SIZE
   '---------------------------
    
   IF wParam <> SIZE_MINIMIZED THEN
     SendMessage(hToolBar, Msg, wParam, lParam)
   END IF
 
   CASE WM_COMMAND
   IF CBCTL = ID_Toolbar + 1 THEN 'open
       MSGBOX "No : 1", "1", MB_ICONINFORMATION
   END IF
 
   IF CBCTL = ID_Toolbar + 4 THEN 'New
       MSGBOX "No : 4","New", MB_ICONINFORMATION
   END IF
 
   IF CBCTL = ID_Toolbar + 5 THEN 'About
       MSGBOX "No : 5","About", MB_ICONINFORMATION
   END IF
 
   CASE WM_CLOSE
   DestroyWindow(Form1)
   EXIT FUNCTION
 
 END SELECT
 END EVENTS