Receiving Toolbar events
When a toolbar button is selected, the application is notified through a callback function. The callback function must adhere to the prototype described in TOOLBARCALLBACK. To set the callback function to use for notification, call L_TBSetCallback. To determine which callback function is currently being used, call L_TBGetCallback. The following is an example of processing toolbar events:
/* This example will create a toolbar and set its callback and then use some of
its buttons messages to dispaly messages to the user */
L_INT EXT_CALLBACK LeadToolbarProc
(
pTOOLBARHANDLE pToolbar,
L_UINT nButtonID,
L_UINT32 dwData,
L_VOID L_FAR *pUserData
)
{
switch ( nButtonID )
{
case ID_TOOL_PAINT_BRUSH:
{
MessageBox ( * ( HWND * ) pUserData, TEXT("BRUSH"), TEXT("Toolbar Message"), MB_OK ) ;
}
break ;
case ID_TOOL_PAINT_SHAPE_LINE:
{
MessageBox ( * ( HWND * ) pUserData, TEXT("LINE"), TEXT("Toolbar Message"), MB_OK ) ;
}
break ;
case ID_TOOL_PAINT_REGION_RECT:
{
MessageBox ( * ( HWND * ) pUserData, TEXT("RECT"), TEXT("Toolbar Message"), MB_OK ) ;
}
break ;
}
return SUCCESS ;
}
/* Global toolbar handle */
pTOOLBARHANDLE g_pLeadToolbar ;
L_INT ToolbarTest ( HWND hWnd )
{
static HWND hwndToolbarOwner ;
/* Save the owner window handle */
hwndToolbarOwner = hWnd ;
/* Initiate the toolbar handle */
L_TBInit ( &g_pLeadToolbar ) ;
if (SUCCESS == L_TBIsValid ( g_pLeadToolbar ) ) /* check the validity of the toolbar handle */
{
/* Create the toolbar */
L_TBCreate ( g_pLeadToolbar, hWnd, TEXT("Tools Window"), TOOLBAR_PAINT ) ;
/* Show the toolbar */
L_TBSetVisible ( g_pLeadToolbar, TRUE ) ;
/* Set the toolbar callback with the owner window as the user defined data */
L_TBSetCallback ( g_pLeadToolbar, LeadToolbarProc, ( L_VOID L_FAR * ) &hwndToolbarOwner ) ;
}
return SUCCESS ;
}