Page 1 of 1

understanding window sizes

Posted: Sat Jun 12, 2004 12:06 pm
by blueznl
Code updated for 5.20+ (same information obtained with WidowWidth(), WindowHeight(), MenuHeight(), ToolBarHeight(), StatusBarHeight())

well, i was messing myself up, so i had to clarify this once and for all, if only for myself...

this should also be a lot of help to any beginner!

i would appreciate any commands and corrections...

Code: Select all

; purebasic survival guide - pb3.90 sp1
; windows_1.pb - 12.06.2004 ejn (blueznl)
; http://www.xs4all.nl/~bluez/datatalk/purebasic.htm
;
; - information on screen and dows
;
;
; *** constants
;
; haven't found a proper function or specification for these, so i'll have to do with assumptions
;
#buttonbarheight = 24
#statusbarheight = 20
;
;
;
; *** first open a window without menus, bars. etc.
;
; w_x and w_y are screen coordinates, the identify the left upper corner of the window
; w_w and w_h specify the size of the client area of the widow
;
w_x = 300                                        ; top left coord of the exterior
w_y = 200
w_w = 300                                        ; as passed on to openwindow, this specifies the interior size!
w_h = 200
;
main_h = OpenWindow(0,w_x,w_y,w_w,w_h,"basic window",#PB_Window_SystemMenu)
;
; the coordinates / dimensions of the interior
;
i_x = 0
i_y = 0
i_w = w_w
i_h = w_h
;
ListViewGadget(0,i_x,i_y,i_w,i_h)
AddGadgetItem(0,-1,"interior")
AddGadgetItem(0,-1,"x "+Str(i_x))
AddGadgetItem(0,-1,"y "+Str(i_y))
AddGadgetItem(0,-1,"w "+Str(i_w))
AddGadgetItem(0,-1,"h "+Str(i_h))
;
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
;
;
;
; *** the same thing, but now we add a menu
;
main_h = OpenWindow(0,w_x,w_y,w_w,w_h,"with a menu",#PB_Window_SystemMenu)
;
CreateMenu(0,main_h)
MenuTitle("Menu")
MenuItem(1,"Entry")
;
; with a menu added, the available height decreases and the reference point (0,0) of the interior moves
; menuheight() returns the size of the menu, wich is equal to the decrease in interior space
;
i_x = 0
i_y = 0
i_w = w_w
i_h = w_h - MenuHeight()                         ; so minus the menu bar height
;
ListViewGadget(0,i_x,i_y,i_w,i_h)
AddGadgetItem(0,-1,"interior")
AddGadgetItem(0,-1,"x "+Str(i_x))
AddGadgetItem(0,-1,"y "+Str(i_y))
AddGadgetItem(0,-1,"w "+Str(i_w))
AddGadgetItem(0,-1,"h "+Str(i_h))
;
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
;
;
;
; *** again, now with a menu and buttonbar
;
main_h = OpenWindow(0,w_x,w_y,w_w,w_h,"and a buttonbar",#PB_Window_SystemMenu)
;
CreateMenu(0,main_h)
MenuTitle("Menu")
MenuItem(1,"Entry")
;
CreateToolBar(0,main_h)
ToolBarStandardButton(1,#PB_ToolBarIcon_New)
;
; purebasic isn't always that consistent, adding a toolbar will not change the reference point, so
; we have to take that into account ourselves, the buttonbar size is hardcoded to #buttonbarheight pixels
; with the icons themselves being 16x16 pixels
;
i_x = 0
i_y = 0 + #buttonbarheight                                     ; add the size of the button bar
i_w = w_w
i_h = w_h - MenuHeight() - #buttonbarheight                    ; and subtract the size of the menu and the buttonbar 
;
ListViewGadget(0,i_x,i_y,i_w,i_h)
AddGadgetItem(0,-1,"interior")
AddGadgetItem(0,-1,"x "+Str(i_x))
AddGadgetItem(0,-1,"y "+Str(i_y))
AddGadgetItem(0,-1,"w "+Str(i_w))
AddGadgetItem(0,-1,"h "+Str(i_h))
;
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
;
;
;
; *** one more time, adding a statusbar
;
main_h = OpenWindow(0,w_x,w_y,w_w,w_h,"plus a statusbar",#PB_Window_SystemMenu)
;
CreateMenu(0,main_h)
MenuTitle("Menu")
MenuItem(1,"Entry")
;
CreateToolBar(0,main_h)
ToolBarStandardButton(1,#PB_ToolBarIcon_New)
;
CreateStatusBar(0,main_h)
;
; a statusbar appears to be always #statusbarheight pixels high
;
i_x = 0
i_y = 0 + #buttonbarheight                                                       ; add the size of the button bar
i_w = w_w
i_h = w_h - MenuHeight() - #buttonbarheight - #statusbarheight                   ; and subtract the size of menu, button, and statusbar
;
ListViewGadget(0,i_x,i_y,i_w,i_h)
AddGadgetItem(0,-1,"interior")
AddGadgetItem(0,-1,"x "+Str(i_x))
AddGadgetItem(0,-1,"y "+Str(i_y))
AddGadgetItem(0,-1,"w "+Str(i_w))
AddGadgetItem(0,-1,"h "+Str(i_h))
;
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
;
;
;
; *** mouse coordinates
;
main_h = OpenWindow(0,w_x,w_y,w_w,w_h,"mouse coordinates",#PB_Window_SystemMenu)
;
CreateMenu(0,main_h)
MenuTitle("Menu")
MenuItem(1,"Entry")
;
CreateToolBar(0,main_h)
ToolBarStandardButton(1,#PB_ToolBarIcon_New)
;
; being the inconsistent beast purebasic is, the mouse function Menuesn't return client coordinates, but
; instead returns the mouse position relative to the left upper corner of the window (!)
;
i_x = 0
i_y = 0+#buttonbarheight                         ; add the size of the button bar
i_w = w_w
i_h = w_h - MenuHeight() - #buttonbarheight      ; and subtract the size of the menu and the buttonbar 
;
c_w = (i_w-4)/3                                  ; column width fir 3 columns evenly spaced
ListIconGadget(0,i_x,i_y,i_w,i_h,"window",c_w)
AddGadgetColumn(0,1,"screen",c_w)
AddGadgetColumn(0,2,"client",c_w)
AddGadgetItem(0,-1,"")
AddGadgetItem(0,-1,"")
;
Repeat
  m_xw = WindowMouseX(0)                          ; these report the coordinates relative to upper left of dow
  m_yw = WindowMouseY(0)
  ;
  p.POINT                                        ; to obtain the proper coordinates we have to use winapi calls                                          
  GetCursorPos_(@p)
  m_xs = p\x                                     ; screen coordinates of mouse pointer
  m_ys = p\y
  ScreenToClient_(main_h,@p)                     
  m_x = p\x                                      ; finally, the real client coordinates
  m_y = p\y
  ;
  If m_x <> m_x_old Or m_y <> m_y_old
    SetGadgetItemText(0,0,"x "+Str(m_xw),0)
    SetGadgetItemText(0,1,"y "+Str(m_yw),0)
    SetGadgetItemText(0,0,"x "+Str(m_xs),1)
    SetGadgetItemText(0,1,"y "+Str(m_ys),1)
    SetGadgetItemText(0,0,"x "+Str(m_x),2)
    SetGadgetItemText(0,1,"y "+Str(m_y),2)
    m_x_old = m_x                                ; just so it only displays changes
    m_y_old = m_y
  EndIf
  ;
Until WaitWindowEvent() = #PB_Event_CloseWindow
;
;
;
; *** more information
;
main_h = OpenWindow(0,w_x,w_y,w_w,w_h,"more info",#PB_Window_SystemMenu)
;
; the coordinates / dimensions of the interior
;
i_x = 0
i_y = 0
i_w = w_w
i_h = w_h - #statusbarheight
;
CreateStatusBar(0,main_h)
ListViewGadget(0,i_x,i_y,i_w,i_h)
;
; using winapi we can retrieve a lot of information
; screensize...
;
s_w = GetSystemMetrics_(#SM_CXSCREEN)
s_h = GetSystemMetrics_(#SM_CYSCREEN)
;
AddGadgetItem(0,-1,"screen size")
AddGadgetItem(0,-1,"w "+Str(s_w))
AddGadgetItem(0,-1,"h "+Str(s_h))
AddGadgetItem(0,-1,"")
;
; available working area on the primary monitor
;
r.RECT
SystemParametersInfo_(#SPI_GETWORKAREA,0,@r,0)
wa_x = r\left
wa_y = r\top
wa_w = r\right - r\left
wa_h = r\bottom - r\top
;
AddGadgetItem(0,-1,"work area")
AddGadgetItem(0,-1,"x "+Str(wa_x))
AddGadgetItem(0,-1,"y "+Str(wa_y))
AddGadgetItem(0,-1,"w "+Str(wa_w))
AddGadgetItem(0,-1,"h "+Str(wa_h))
AddGadgetItem(0,-1,"")
;
; dimensions of a window border
; (note that sizes of resizable and non resizable windows are different)
;
b_x = GetSystemMetrics_(#SM_CXDLGFRAME)            ; non-resizable window   
b_y = GetSystemMetrics_(#SM_CXDLGFRAME)
;
AddGadgetItem(0,-1,"window border (sizable)")
AddGadgetItem(0,-1,"x "+Str(b_x))
AddGadgetItem(0,-1,"y "+Str(b_y))
AddGadgetItem(0,-1,"")
;
; dragbar or captionbar
; (note that there is a smaller style as well)
;
ca_h = GetSystemMetrics_(#SM_CYCAPTION)
;
AddGadgetItem(0,-1,"caption (dragbar)")
AddGadgetItem(0,-1,"h "+Str(ca_h))
AddGadgetItem(0,-1,"")
;
AddGadgetItem(0,-1,"window parameters")
AddGadgetItem(0,-1,"x "+Str(i_x))
AddGadgetItem(0,-1,"y "+Str(i_y))
AddGadgetItem(0,-1,"w "+Str(i_w))
AddGadgetItem(0,-1,"h "+Str(i_h))
AddGadgetItem(0,-1,"")
AddGadgetItem(0,-1,"interior")
AddGadgetItem(0,-1,"x "+Str(i_x))
AddGadgetItem(0,-1,"y "+Str(i_y))
AddGadgetItem(0,-1,"w "+Str(i_w))
AddGadgetItem(0,-1,"h "+Str(i_h))
AddGadgetItem(0,-1,"")
;
; using the above we can calculate the windows external dimensions
;
e_x = w_x
e_y = w_y
e_w = i_w + 2*b_x
e_h = i_h + 2*b_y + ca_h
;
AddGadgetItem(0,-1,"exterior")
AddGadgetItem(0,-1,"x "+Str(e_x))
AddGadgetItem(0,-1,"y "+Str(e_y))
AddGadgetItem(0,-1,"w "+Str(e_w))
AddGadgetItem(0,-1,"h "+Str(e_h))
AddGadgetItem(0,-1,"")
;
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
;
;
; 
; *** resize to full screen
;
; ok, let's try our knowledge and resize the widow to full screen, just fitting, with borders visible
; in the previous section we figured out the available space on the desktop on the primary screen (workarea)
;
w_x = wa_x
w_y = wa_y
w_w = wa_w - 2*b_x
w_h = wa_h - 2*b_y - ca_h
;
i_x = 0
i_y = 0
i_w = w_w
i_h = w_h - #statusbarheight
;
main_h = OpenWindow(0,w_x,w_y,w_w,w_h,"maximized to full screen",#PB_Window_SystemMenu)
ListViewGadget(0,i_x,i_y,i_w,i_h)
CreateStatusBar(0,main_h)
;
AddGadgetItem(0,-1,"screen size")
AddGadgetItem(0,-1,"w "+Str(s_w))
AddGadgetItem(0,-1,"h "+Str(s_h))
AddGadgetItem(0,-1,"")
AddGadgetItem(0,-1,"work area")
AddGadgetItem(0,-1,"x "+Str(wa_x))
AddGadgetItem(0,-1,"y "+Str(wa_y))
AddGadgetItem(0,-1,"w "+Str(wa_w))
AddGadgetItem(0,-1,"h "+Str(wa_h))
AddGadgetItem(0,-1,"")
AddGadgetItem(0,-1,"window border (not sizable)")
AddGadgetItem(0,-1,"x "+Str(b_x))
AddGadgetItem(0,-1,"y "+Str(b_y))
AddGadgetItem(0,-1,"")
AddGadgetItem(0,-1,"caption (dragbar)")
AddGadgetItem(0,-1,"h "+Str(ca_h))
AddGadgetItem(0,-1,"")
AddGadgetItem(0,-1,"window parameters")
AddGadgetItem(0,-1,"x "+Str(i_x))
AddGadgetItem(0,-1,"y "+Str(i_y))
AddGadgetItem(0,-1,"w "+Str(i_w))
AddGadgetItem(0,-1,"h "+Str(i_h))
AddGadgetItem(0,-1,"")
AddGadgetItem(0,-1,"interior")
AddGadgetItem(0,-1,"x "+Str(i_x))
AddGadgetItem(0,-1,"y "+Str(i_y))
AddGadgetItem(0,-1,"w "+Str(i_w))
AddGadgetItem(0,-1,"h "+Str(i_h))
AddGadgetItem(0,-1,"")
;
e_x = w_x
e_y = w_y
e_w = i_w + 2*b_x
e_h = i_h + 2*b_y + ca_h
;
AddGadgetItem(0,-1,"exterior")
AddGadgetItem(0,-1,"x "+Str(e_x))
AddGadgetItem(0,-1,"y "+Str(e_y))
AddGadgetItem(0,-1,"w "+Str(e_w))
AddGadgetItem(0,-1,"h "+Str(e_h))
AddGadgetItem(0,-1,"")
;
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
;
;
;
; *** a resizable window with an updated gadget
;
w_x = 300                                        
w_y = 200
w_w = 300                                        
w_h = 200
i_x = 0
i_y = 0
i_w = w_w
i_h = w_h - #statusbarheight
;
main_h = OpenWindow(0,w_x,w_y,w_w,w_h,"more info",#PB_Window_SystemMenu|#PB_Window_SizeGadget)
CreateStatusBar(0,main_h)
ListViewGadget(0,i_x,i_y,i_w,i_h)
AddGadgetItem(0,-1,"interior")
AddGadgetItem(0,-1,"x "+Str(i_x))
AddGadgetItem(0,-1,"y "+Str(i_y))
AddGadgetItem(0,-1,"w "+Str(i_w))
AddGadgetItem(0,-1,"h "+Str(i_h))
;
Repeat
  event = WaitWindowEvent()
  Select event
    Case #PB_Event_SizeWindow
      w_x = WindowX(0)
      w_y = WindowY(0)
      w_w = WindowWidth(0)
      w_h = WindowHeight(0)
      i_w = w_w
      i_h = w_h - #statusbarheight
      ResizeGadget(0,i_x,i_y,i_w,i_h)
      SetGadgetItemText(0,1,"x "+Str(i_x),0)
      SetGadgetItemText(0,2,"y "+Str(i_y),0)
      SetGadgetItemText(0,3,"w "+Str(i_w),0)
      SetGadgetItemText(0,4,"h "+Str(i_h),0)
  EndSelect
Until event = #PB_Event_CloseWindow

Posted: Mon Jun 14, 2004 3:10 pm
by Sparkie
Code updated for 5.20+
; haven't found a proper function or specification for these, so i'll have to do with assumptions
;
#buttonbarheight = 24
#statusbarheight = 20
Using the following code, here are my results on my WinXP:

XP skin support enabled-
Toolbar GetWindowRect_() height is 28
Toolbar GetClientRect_() height is 26
Statusbar GetWindowRect_() height is 23
Statusbar GetClientRect_() height is 23


XP skin support disabled-
Toolbar GetWindowRect_() height is 28
Toolbar GetClientRect_() height is 26
Statusbar GetWindowRect_() height is 20
Statusbar GetClientRect_() height is 20

Code: Select all

Enumeration
  #Window_0
EndEnumeration

Enumeration
  #ListIcon_0
EndEnumeration

Enumeration
  #MenuBar_0
  #ToolBar_0
EndEnumeration

Enumeration
  #StatusBar_0
EndEnumeration

Declare getinfo(htb.l, hsb.l)
Global hToolBar, hStatusbar

Procedure MyWindowCallBack(hwnd, msg, wParam, lParam) 
  
  result = #PB_ProcessPureBasicEvents
  Select msg
    
    Case #WM_MOVE
      getinfo(hToolBar, hStatusbar)
      
  EndSelect
  
  ProcedureReturn result
EndProcedure 

Procedure getinfo(htb.l, hsb.l)
  GetWindowRect_(htb, @tbarW.RECT)
  GetClientRect_(htb, @tbarC.RECT)
  GetWindowRect_(hsb, @sbarW.RECT)
  GetClientRect_(hsb, @sbarC.RECT)
  
  SetGadgetItemText(#ListIcon_0, 0, Str(tbarW\left), 1)
  SetGadgetItemText(#ListIcon_0, 0, Str(tbarW\right), 2)
  SetGadgetItemText(#ListIcon_0, 0, Str(tbarW\right - tbarW\left), 3)
  SetGadgetItemText(#ListIcon_0, 0, Str(tbarW\top), 4)
  SetGadgetItemText(#ListIcon_0, 0, Str(tbarW\bottom), 5)
  SetGadgetItemText(#ListIcon_0, 0, Str(tbarW\bottom - tbarW\top), 6)
  
  
  SetGadgetItemText(#ListIcon_0, 1, Str(tbarC\left), 1)
  SetGadgetItemText(#ListIcon_0, 1, Str(tbarC\right), 2)
  SetGadgetItemText(#ListIcon_0, 1, Str(tbarC\right - tbarC\left), 3)
  SetGadgetItemText(#ListIcon_0, 1, Str(tbarC\top), 4)
  SetGadgetItemText(#ListIcon_0, 1, Str(tbarC\bottom), 5)
  SetGadgetItemText(#ListIcon_0, 1, Str(tbarC\bottom - tbarC\top), 6)
  
  SetGadgetItemText(#ListIcon_0, 2, Str(sbarW\left), 1)
  SetGadgetItemText(#ListIcon_0, 2, Str(sbarW\right), 2)
  SetGadgetItemText(#ListIcon_0, 2, Str(sbarW\right - sbarW\left), 3)
  SetGadgetItemText(#ListIcon_0, 2, Str(sbarW\top), 4)
  SetGadgetItemText(#ListIcon_0, 2, Str(sbarW\bottom), 5)
  SetGadgetItemText(#ListIcon_0, 2, Str(sbarW\bottom - sbarW\top), 6)
  
  SetGadgetItemText(#ListIcon_0, 3, Str(sbarC\left), 1)
  SetGadgetItemText(#ListIcon_0, 3, Str(sbarC\right), 2)
  SetGadgetItemText(#ListIcon_0, 3, Str(sbarC\right - sbarC\left), 3)
  SetGadgetItemText(#ListIcon_0, 3, Str(sbarC\top), 4)
  SetGadgetItemText(#ListIcon_0, 3, Str(sbarC\bottom), 5)
  SetGadgetItemText(#ListIcon_0, 3, Str(sbarC\bottom - sbarC\top), 6)
  
EndProcedure

If OpenWindow(#Window_0, 0, 0, 600, 260, "Test Info",  #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_TitleBar )
  
  If CreateMenu(#MenuBar_0, WindowID(#Window_0))
    MenuTitle("Test")
  EndIf
  
  ListIconGadget(#ListIcon_0, 10, 70, 580, 100, "Item", 175, #PB_ListIcon_FullRowSelect)
  AddGadgetColumn(#ListIcon_0, 1, "Left pos", 70)
  AddGadgetColumn(#ListIcon_0, 2, "Right pos", 70)
  AddGadgetColumn(#ListIcon_0, 3, "Width", 60)
  AddGadgetColumn(#ListIcon_0, 4, "Top pos", 70)
  AddGadgetColumn(#ListIcon_0, 5, "Bottom pos", 70)
  AddGadgetColumn(#ListIcon_0, 6, "Height", 60)
  
  AddGadgetItem(#ListIcon_0, -1, "Toolbar GetWindowRect_()")
  AddGadgetItem(#ListIcon_0, -1, "Toolbar GetClientRect_()")
  AddGadgetItem(#ListIcon_0, -1, "Statusbar GetWindowRect_()")
  AddGadgetItem(#ListIcon_0, -1, "Statusbar GetClientRect_()")
  
  hToolBar =  CreateToolBar(#ToolBar_0, WindowID(#Window_0))
  ToolBarStandardButton(0, #PB_ToolBarIcon_New) 
  ToolBarStandardButton(1, #PB_ToolBarIcon_Open) 
  ToolBarStandardButton(2, #PB_ToolBarIcon_Save)
  ToolBarStandardButton(3, #PB_ToolBarIcon_Print) 
  ToolBarStandardButton(1, #PB_ToolBarIcon_Help) 
    
  hStatusbar = CreateStatusBar(#StatusBar_0, WindowID(#Window_0))
  AddStatusBarField(200)
  AddStatusBarField(400)
  StatusBarText(#StatusBar_0, 0, "Field0")
  StatusBarText(#StatusBar_0, 1, "Field1")
  getinfo(hToolBar, hStatusbar)
  SetWindowCallback(@MyWindowCallBack())
EndIf

Repeat
  
  event = WaitWindowEvent()
  
Until event = #PB_Event_CloseWindow

End

Posted: Mon Jun 14, 2004 4:03 pm
by blueznl
interesting, that means windows reports a toolbar to be 4 pixels larger than it actually appears on screen... hmmm?

or am i totally wrong now?

Posted: Mon Jun 14, 2004 6:55 pm
by Sparkie
Code updated for 5.20+

#TB_GETRECT and #TB_GETMAXSIZE both report Toolbar height of 22, which seems more realistic to me.

Code: Select all

Enumeration
  #Window_0
EndEnumeration

Enumeration
  #ListIcon_0
EndEnumeration

Enumeration
  #MenuBar_0
  #ToolBar_0
EndEnumeration

Enumeration
  #StatusBar_0
EndEnumeration

#TB_GETRECT = (#WM_USER + 51)
#TB_GETMAXSIZE = (#WM_USER + 83)

Declare getinfo(htb.l)
Global hToolBar

Procedure MyWindowCallBack(hwnd, msg, wParam, lParam) 
  
  result = #PB_ProcessPureBasicEvents
  Select msg
    
    Case #WM_MOVE
      getinfo(hToolBar)
   
  EndSelect
  
  ProcedureReturn result
EndProcedure 

Procedure getinfo(htb.l)
  GetWindowRect_(htb, @tbarW.RECT)
  GetClientRect_(htb, @tbarC.RECT)
  
  ;- get rect for item 0 (all other toolbar items are the same size?)
  SendMessage_(htb, #TB_GETRECT, 0, @tbInfo.RECT)
  SendMessage_(htb, #TB_GETMAXSIZE, 0, @tbSize.SIZE)
  
  SetGadgetItemText(#ListIcon_0, 0, Str(tbarW\left), 1)
  SetGadgetItemText(#ListIcon_0, 0, Str(tbarW\right), 2)
  SetGadgetItemText(#ListIcon_0, 0, Str(tbarW\right - tbarW\left), 3)
  SetGadgetItemText(#ListIcon_0, 0, Str(tbarW\top), 4)
  SetGadgetItemText(#ListIcon_0, 0, Str(tbarW\bottom), 5)
  SetGadgetItemText(#ListIcon_0, 0, Str(tbarW\bottom - tbarW\top), 6)
  
  SetGadgetItemText(#ListIcon_0, 1, Str(tbarC\left), 1)
  SetGadgetItemText(#ListIcon_0, 1, Str(tbarC\right), 2)
  SetGadgetItemText(#ListIcon_0, 1, Str(tbarC\right - tbarC\left), 3)
  SetGadgetItemText(#ListIcon_0, 1, Str(tbarC\top), 4)
  SetGadgetItemText(#ListIcon_0, 1, Str(tbarC\bottom), 5)
  SetGadgetItemText(#ListIcon_0, 1, Str(tbarC\bottom - tbarC\top), 6)
  
  SetGadgetItemText(#ListIcon_0, 2, Str(tbInfo\left), 1)
  SetGadgetItemText(#ListIcon_0, 2, Str(tbInfo\right), 2)
  SetGadgetItemText(#ListIcon_0, 2, Str(tbInfo\right - tbInfo\left), 3)
  SetGadgetItemText(#ListIcon_0, 2, Str(tbInfo\top), 4)
  SetGadgetItemText(#ListIcon_0, 2, Str(tbInfo\bottom), 5)
  SetGadgetItemText(#ListIcon_0, 2, Str(tbInfo\bottom - tbInfo\top), 6)
   
  SetGadgetItemText(#ListIcon_0, 3, Str(tbSize\cx), 3)
  SetGadgetItemText(#ListIcon_0, 3, Str(tbSize\cy), 6)
EndProcedure

If OpenWindow(#Window_0, 0, 0, 600, 260, "Test Info",  #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_TitleBar )
  
  If CreateMenu(#MenuBar_0, WindowID(#Window_0))
    MenuTitle("Test")
  EndIf
  
  ListIconGadget(#ListIcon_0, 10, 70, 580, 100, "Item", 175, #PB_ListIcon_FullRowSelect)
  AddGadgetColumn(#ListIcon_0, 1, "Left pos", 70)
  AddGadgetColumn(#ListIcon_0, 2, "Right pos", 70)
  AddGadgetColumn(#ListIcon_0, 3, "Width", 60)
  AddGadgetColumn(#ListIcon_0, 4, "Top pos", 70)
  AddGadgetColumn(#ListIcon_0, 5, "Bottom pos", 70)
  AddGadgetColumn(#ListIcon_0, 6, "Height", 60)
  
  AddGadgetItem(#ListIcon_0, -1, "Toolbar GetWindowRect_()")
  AddGadgetItem(#ListIcon_0, -1, "Toolbar GetClientRect_()")
  AddGadgetItem(#ListIcon_0, -1, "First Toolbar Item #TB_GETRECT")
  AddGadgetItem(#ListIcon_0, -1, "Toolbar #TB_GETMAXSIZE")
  
  hToolBar =  CreateToolBar(#ToolBar_0, WindowID(#Window_0))
  ToolBarStandardButton(0, #PB_ToolBarIcon_New) 
  ToolBarStandardButton(1, #PB_ToolBarIcon_Open) 
  ToolBarStandardButton(2, #PB_ToolBarIcon_Save)
  ToolBarStandardButton(3, #PB_ToolBarIcon_Print) 
  ToolBarStandardButton(1, #PB_ToolBarIcon_Help) 
    
  CreateStatusBar(#StatusBar_0, WindowID(#Window_0))
  AddStatusBarField(200)
  AddStatusBarField(400)
  StatusBarText(#StatusBar_0, 0, "Field0")
  StatusBarText(#StatusBar_0, 1, "Field1")
  getinfo(hToolBar)
  SetWindowCallback(@MyWindowCallBack())
EndIf

Repeat
  
  event = WaitWindowEvent()
  
Until event = #PB_Event_CloseWindow

End

Posted: Mon Apr 03, 2006 10:40 am
by Michael Vogel
And how to get the size of the rectangle of the statusbar fields?

Yes, this could be useful - I want to put a progress bar beside a status bar field - and it should have the same height.

Michael

Posted: Mon Apr 03, 2006 6:07 pm
by Trond
I'm quite sure that the height of a statusbar is not a constant, it changes when you change the default font in Windows.

Posted: Mon Apr 03, 2006 8:17 pm
by blueznl
i'm currently using this (3.94)

Code: Select all

Procedure x_statusbarheight(statusbar_h)                             ; returns height of specified statusbar
  Protected rect.RECT
  ;
  ; *** returns height of statusbar
  ;
  ; in:     statusbar_h > 0     - handle of statusbar
  ;         statusbar_h <= 0    - no statusbar, return 0
  ; retval: n                   - height of statusbar
  ;
  ; note: this routine does NOT check if the statusbar exists or not, you have to pass it the handle
  ;
  rect.RECT
  If statusbar_h > 0
    GetWindowRect_(statusbar_h,@rect)
    ProcedureReturn (rect\bottom-rect\top)
  Else
    ProcedureReturn 0
  EndIf
  ;
EndProcedure