L_TBAddButton

#include "ltTLB.h"

L_LTTLB_API L_INT L_TBAddButton( pToolbar, uButtonRefId, pButtonInfo, dwFlags )

pTOOLBARHANDLE pToolbar;

/* pointer to a toolbar handle */

L_UINT uButtonRefId;

/* button ID */

const pLBUTTONINFO pButtonInfo;

/* pointer to a structure */

L_UINT32 dwFlags;

/* flags */

Adds a new button to the toolbar.

Parameter

Description

pToolbar

Pointer to a toolbar handle that references the toolbar to which to add the button.

uButtonRefId

Reference to use for positioning new button inside the toolbar.

pButtonInfo

Point to a LBUTTONINFO structure containing data for the new button.

dwFlags

Flag that indicates where to add the new button, with respect to the button specified in uButtonRefId. Possible values are:

 

Flag

Meaning

 

TOOLBAR_ADD_BEFORE

Add this button before the button specified by uButtonRefId in the toolbar.

 

TOOLBAR_ADD_AFTER

Add this button after the button specified by uButtonRefId in the toolbar.

 

TOOLBAR_ADD_TOOL

If this flag is specified, the toolkit will create a new tool and make this button the first button of the new tool.

 

If this flag is not specified, the toolkit will add the new button to the same tool as uButtonRefId.

 

Note, if the toolbar contains no buttons, both uButtonRefId and dwFlags will be ignored and the new tool and button will be added to the toolbar.

Comments

As an example, if dwFlags is set to TOOLBAR_ADD_BEFORE | TOOLBAR_ADD_TOOL, then a new tool will be added before the button specified by uButtonRefId. If dwFlags is set to TOOLBAR_ADD_BEFORE, then the new button will be added before the button specified by uButtonRefId and it will become part of the same tool as the button specified by uButtonRefId.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes

Required DLLs and Libraries

LTTLB

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

See Also

Functions:

L_TBRemoveButton, L_TBGetButtonInfo, L_TBSetButtonInfo, L_TBGetToolbarInfo, L_TBSetToolbarInfo

Topics:

Getting and Setting Toolbar Button Information

Example

This example will create a new toolbar and add 2 tools with 2 buttons each.

#include "commctrl.h"

L_INT TBAddButtonExample(HWND hWndParent, HINSTANCE hInst, ppTOOLBARHANDLE ppToolbar)
{
   L_INT nRet;
   /* assume these resource IDs contain valid bitmaps */
   const L_INT nResId[ 4 ] = { IDB_BITMAP1, IDB_BITMAP2, IDB_BITMAP3, IDB_BITMAP4 };
   const L_TCHAR *szToolTipText[ 4 ] = { TEXT("Button 1"), TEXT("Button 2"), TEXT("Button 3"), TEXT("Button 4") };
   LBUTTONINFO ButtonInfo;
   L_INT i;
   L_UINT uRefId;
   L_UINT32 dwFlags;

   nRet = L_TBInit ( ppToolbar );
   if(nRet != SUCCESS)
      return nRet;
   nRet = L_TBCreate ( *ppToolbar, hWndParent, TEXT("Toolbar"), TOOLBAR_EMPTY );
   if(nRet != SUCCESS)
      return nRet;

   uRefId = 0;  /* we dont need a reference button when adding the first one */

   for( i = 0; i < 4; i++ )
   {
      ZeroMemory(&ButtonInfo, sizeof(LBUTTONINFO));
      ButtonInfo.uStructSize = sizeof(LBUTTONINFO);
      ButtonInfo.uID = i + 1;
      ButtonInfo.hBitmap = LoadBitmap( hInst,
                                       MAKEINTRESOURCE( nResId[ i ] ) );

      lstrcpy( ButtonInfo.szToolTipText, szToolTipText[ i ] );
      ButtonInfo.dwTag = 0L;
      ButtonInfo.fsState = TBSTATE_ENABLED;
 
      dwFlags = TOOLBAR_ADD_AFTER;
      if( i == 0 || i == 2 )
         dwFlags |= TOOLBAR_ADD_TOOL;

      nRet = L_TBAddButton( *ppToolbar, uRefId, &ButtonInfo, dwFlags );
      if(nRet != SUCCESS)
         return nRet;

      DeleteObject( ButtonInfo.hBitmap );  /* the toolbar toolkit keeps its own copy */

      uRefId = ButtonInfo.uID;  /* save last button ID */
   }

   if(SUCCESS == L_TBIsValid(*ppToolbar))
   {
      L_TBSetVisible(*ppToolbar, TRUE);
   }
   return SUCCESS;
}