#include "ltwrappr.h"
L_INT LToolbar::AddButton(uButtonRefId, pButtonInfo, dwFlags )
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 | |
uButtonRefId | Reference to use for positioning the new button inside the toolbar. | |
pButtonInfo | Point to an 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. |
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 LToolbar::GetToolbarInfo. You can then use the flags to either add the new button before or after any existing buttons.
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.
Functions: |
LToolbar::RemoveButton, LToolbar::GetButtonInfo, LToolbar::SetButtonInfo, LToolbar::GetToolbarInfo, LToolbar::SetToolbarInfo, Class Members |
Topics: |
This example will create an empty toolbar and then add four buttons.
#define IDB_BITMAP1 101
#define IDB_BITMAP2 102
#define IDB_BITMAP3 103
#define IDB_BITMAP4 104
L_INT LToolbar__AddButtonExample( HWND hWnd, LToolbar* tlb)
{
L_INT nRet;
/*Assume that m_hWnd is a valid window handle*/
/* Initiate the toolbar handle */
nRet = tlb->Initialize ();
if(nRet != SUCCESS)
return nRet;
/* Check the validity of the handle */
if ( tlb->IsValid () )
{
POINT pt = { 0, 0 } ;
/* Initiate the point will be used to align the toolbar at the top-left of its owner client area */
::ClientToScreen ( hWnd, &pt ) ;
/* Create the toolbar */
nRet = tlb->Create (hWnd, TEXT("Tools Window"), TOOLBAR_EMPTY ) ;
if(nRet != SUCCESS)
return 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;
uRefId = 0; /* we dont need a reference button when adding the first one */
for( i = 0; i < 4; i++ )
{
ButtonInfo.uID = i + 1;
ButtonInfo.hBitmap = LoadBitmap(
(HINSTANCE) L_GETWINDOWLONGPTR( hWnd /*hWndParent*/, GWLP_HINSTANCE ),
MAKEINTRESOURCE( nResId[ i ] ) );
if(ButtonInfo.hBitmap)
{
lstrcpy( ButtonInfo.szToolTipText, szToolTipText[ i ] );
ButtonInfo.dwTag = 0L;
ButtonInfo.fsState = TBSTATE_ENABLED;
ButtonInfo.uStructSize=sizeof(LBUTTONINFO);
dwFlags = TOOLBAR_ADD_AFTER;
if( i == 0 || i == 2 )
dwFlags |= TOOLBAR_ADD_TOOL;
nRet = tlb->AddButton (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 */
}
}
/* Set the toolbar position */
nRet = tlb->SetPosition (&pt, TOOLBAR_POSITION_TOP | TOOLBAR_POSITION_LEFT ) ;
if(nRet != SUCCESS)
return nRet;
/* Show the toolbar */
nRet = tlb->SetVisible (TRUE ) ;
if(nRet != SUCCESS)
return nRet;
}
return SUCCESS;
}