L_TBAddButton

Summary

Adds a new button to the toolbar.

Syntax

#include "ltTLB.h"

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

Parameters

pTOOLBARHANDLE pToolbar

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

L_UINT uButtonRefId

Reference to use for positioning a new button inside the toolbar.

const pLBUTTONINFO pButtonInfo

Pointer to an LBUTTONINFO structure containing data for the new button.

L_UINT32 dwFlags

Flag that indicates where to add the new button, with respect to the button specified in uButtonRefId. If this flag is not specified, the toolkit will add the new button to the same tool as 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.

Note: If the toolbar does not contain any 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.

For adding a new button to an existing toolbar, you should use one of the existing buttons' uButtonRefId that you can retrieve by calling the L_TBGetToolbarInfo. You can then use the flags to either add the new button before or after any existing buttons.

Returns

Value Meaning
SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes

Required DLLs and Libraries

See Also

Functions

Topics

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; 
} 

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Toolbar C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.