Page 1 of 1

Change text button Toolbar

Posted: Thu Sep 07, 2006 3:14 pm
by Riccardo
Hi,
how is possible to change the text of a button in a toolbar?

Thank you

Posted: Thu Sep 07, 2006 7:55 pm
by James Bott
Have you tried: oBtn:setText("New Text")?

Posted: Fri Sep 08, 2006 6:06 am
by Antonio Linares
Riccardo,

You have to add this method to Class TToolBar:

Code: Select all

METHOD SetText( nButton, cText ) INLINE TBSetText( ::hWnd, nButton, cText )                            
And this code to your app:

Code: Select all

#pragma BEGINDUMP

#include <hbapi.h>
#include <Windows.h>
#include <CommCtrl.h>

HB_FUNC( TBSETTEXT )
{
   HWND hToolBar = ( HWND ) hb_parnl( 1 );
   TBBUTTONINFO tbi;

   memset( ( char * ) &tbi, 0, sizeof( tbi ) );

	tbi.dwMask  = TBIF_TEXT | TBIF_BYINDEX;
	tbi.cbSize  = sizeof( TBBUTTONINFO );
	tbi.pszText = hb_parc( 3 );
	tbi.cchText = hb_parclen( 3 );
	 
   SendMessage( hToolBar, TB_SETBUTTONINFO, hb_parni( 2 ) - 1, ( LPARAM ) &tbi );
}
Then use it this way:

Code: Select all

 oToolbar:SetText( 1, "Hello" ) // set first button text

Posted: Fri Sep 08, 2006 8:23 am
by Riccardo
Antonio,
thank you, works fine.

I've modify the Method Commad of the TToolBar to have the nId of the buttom when pressed:
Eval( bAction, Self ) -> Eval( bAction, Self, nID )

Bye
Riccardo

Posted: Fri Sep 08, 2006 8:29 am
by Antonio Linares
Riccardo,

> Eval( bAction, Self ) -> Eval( bAction, Self, nID )

Ok, we have also modified it here, though we may finally create a new Class TTBButton and the TBButton object will be supplied instead of nID.