Page 1 of 2

ToolBar height ?

Posted: Fri Jul 25, 2003 11:53 pm
by Flype
hello, how can i get the height of the toolbar in my window ?

Posted: Sat Jul 26, 2003 6:42 am
by Denis
Salut Flype,

send a message with TB_GETMETRICS value.

It retrives all Toolbar parameters.


A+

Denis

Posted: Sat Jul 26, 2003 4:23 pm
by Flype
thanks denis, but that's not all folk !

Structure TBMETRICS not in purebasic includes, so here is :

Code: Select all

Structure TBMETRICS
  cbSize.l
  dwMask.l
  cxPad.l
  cyPad.l
  cxBarPad.l
  cyBarPad.l
  cxButtonSpacing.l
  cyButtonSpacing.l
EndStructure
And the constante #TB_GETMETRICS isn't defined so what's its value ?

Code: Select all

ptbMetrics.TBMETRICS
ptbMetrics\cbSize = Sizeof( TBMETRICS )
SendMessage_( toolbar, #TB_GETMETRICS, 0, @ptbMetrics )

Posted: Sat Jul 26, 2003 4:47 pm
by ebs
Flype,

#TB_GETMETRICS = #WM_USER + 101

Eric

Posted: Sat Jul 26, 2003 5:19 pm
by Flype
very thank you ebs :wink:

Posted: Sat Jul 26, 2003 5:33 pm
by Flype
arrrg, in order to make it working i need those 3 API constantes :

#TBMF_PAD
#TBMF_BARPAD
#TBMF_BUTTONSPACING

as specified in MSDN documentation http://msdn.microsoft.com/library/defau ... etrics.asp

Posted: Sat Jul 26, 2003 5:41 pm
by Flype
this is how i coded it :
but it doesn't work (perhaps it works only with winXP )

Code: Select all

Structure TBMETRICS
  cbSize.l
  dwMask.l
  cxPad.l
  cyPad.l
  cxBarPad.l
  cyBarPad.l
  cxButtonSpacing.l
  cyButtonSpacing.l
EndStructure

#TBMF_PAD = 1
#TBMF_BARPAD = 2
#TBMF_BUTTONSPACING = 4
#TB_GETMETRICS = #WM_USER + 101

;=================================

If OpenWindow(0,0,0,400,300,#PB_Window_ScreenCentered|#PB_Window_SystemMenu,"Toolbar")
  
  toolbar = CreateToolBar( 0, WindowID() )
  ToolBarStandardButton( 0, #PB_ToolBarIcon_Save )
  ToolBarStandardButton( 1, #PB_ToolBarIcon_Delete )
  
  CreateGadgetList( WindowID() )
    
  ptbMetrics.TBMETRICS 
  ptbMetrics\cbSize = SizeOf( TBMETRICS )
  ptbMetrics\dwMask = #TBMF_PAD
  SendMessage_( toolbar, #TB_GETMETRICS, 0, @ptbMetrics )
  Debug ptbMetrics\cxPad
  Debug ptbMetrics\cyPad
  
  ComboBoxGadget( 3, 5, ptbMetrics\cyPad+10, 200, 120 )
  
  Repeat : Until WaitWindowEvent() = #WM_CLOSE

EndIf

Hello

Posted: Sat Jul 26, 2003 5:49 pm
by DominiqueB
Just try:

#TBMF_BARPAD = 2
#TBMF_BUTTONSPACING = 4
#TBMF_PAD = 1

Dominique

Posted: Sat Jul 26, 2003 5:57 pm
by Flype
i tried and it doesn't work on my win2000 :cry:
If someone can try it under winXP

It works .

Posted: Sat Jul 26, 2003 7:16 pm
by DominiqueB
In fact it can't works for you under w2000 !
Minimum is xp for the structure TBMETRICS.

Said into wsdk.

I've XP pro and your sample code works well for me.

So sad .

Dominique.

Posted: Sat Jul 26, 2003 7:28 pm
by Pupil
Maybe you can use API GetClientRect_() instead to get the height of the toolbar.

Posted: Sat Jul 26, 2003 7:46 pm
by Edwin Knoppert
On each size of the window it usually updates it's size by passing WM_SIZE to the tb.

After this is done, you can obtain height by using GetWindowRect_()
Subtract top from bottom = height

Posted: Sat Jul 26, 2003 8:05 pm
by GPI
Little snap out of jaPBe:

Code: Select all

ToolBarId=CreateToolBar(#tool_MainWindow,MainWin)
GetClientRect_(ToolBarId,rect.RECT)
ToolBarHeight=rect\bottom

Should work on all system.

Edit: on GetClientRect_() is rect\left rect\top always 0!

GPI

Posted: Sat Jul 26, 2003 8:12 pm
by Flype
yes, that's exactely what i want :D
and now it's so simple :oops: :

Code: Select all

If OpenWindow(0,0,0,300,100,#PB_Window_ScreenCentered|#PB_Window_SystemMenu,"Toolbar") 
  
  toolbar = CreateToolBar( 0, WindowID() ) 
  ToolBarStandardButton( 0, #PB_ToolBarIcon_Save ) 
  ToolBarStandardButton( 1, #PB_ToolBarIcon_Delete ) 
  
  CreateGadgetList( WindowID() ) 
  GetClientRect_( toolbar,rect.RECT) 
  ComboBoxGadget( 3, 5, rect\bottom, 200, 120 ) 
  
  Repeat : Until WaitWindowEvent() = #WM_CLOSE 

EndIf
and, so, the previous example works only on XP :? I should forget it ...

Posted: Sat Jul 26, 2003 10:49 pm
by Edwin Knoppert
GetClientRect is not the way to do it..
Unless you want the client area's height.

You where asking the toolbar's height.
This might result in the similar value for now but what if billy changes windows again?