Posts: 1,769
Threads: 410
Joined: Feb 2003
is there a way to set a toolbar to automatically reset its height depending on how many items are in it?
i have one that i programatically add lines to it but can't get it to auto expand with each addition.
thanks.
Posts: 12,097
Threads: 142
Joined: Dec 2002
Function TB_AdjustSize
;/
function hWnd
;Adjusts QM toolbar width and height so that all (and only) buttons would be visible.
;EXAMPLE
;TB_AdjustSize win("TOOLBAR17" "QM_toolbar")
def TB_BUTTONCOUNT 0x00000418
def TB_GETITEMRECT 0x0000041D
def TB_GETBUTTONSIZE 0x0000043A
dll user32 #AdjustWindowRectEx RECT*lpRect dsStyle bMenu dwEsStyle
int htb=id(9999 hWnd)
RECT r; int cx cy i
for i 0 SendMessage(htb TB_BUTTONCOUNT 0 0)
,SendMessage(htb TB_GETITEMRECT i &r)
,if(r.bottom-r.top<15) continue ;;hor sep
,if(r.right>cx) cx=r.right
,if(r.bottom>cy) cy=r.bottom
if(cx) r.right=cx; r.bottom=cy
else i=SendMessage(htb TB_GETBUTTONSIZE 0 0); r.right=i&0xffff; r.bottom=i>>16
r.left=0; r.top=0
AdjustWindowRectEx &r GetWinStyle(hWnd) 0 GetWinStyle(hWnd 1)
siz r.right-r.left r.bottom-r.top hWnd
Function __tb_auto_size. This toolbar hook function adjusts toolbar size automatically.
;/
function# hWnd message wParam lParam
dll user32 #GetCapture
sel message
,case WM_CREATE
,SetTimer hWnd 1 1000 0
,
,case WM_TIMER
,;KillTimer hWnd 1
,if(wParam=1)
,,if(GetCapture) ret
,,TB_AdjustSize hWnd
,
Toolbar example
;/hook __tb_auto_size
Macro395 :mac "Macro395"
Macro390 :mac "Macro390"
-
Macro395 :mac "Macro395"
Macro382 :mac "Macro382"
Macro401 :mac "Macro401"
Macro389 :mac "Macro389"
Posts: 1,769
Threads: 410
Joined: Feb 2003
i dont have the "GetCapture" identifier.
can you post that as well?
Posts: 12,097
Threads: 142
Joined: Dec 2002
Posts: 1,769
Threads: 410
Joined: Feb 2003
works great!!
wow a hook AND a manual function! thanks.
question: why use SetTimer instead of a "wait" function?
thanks.
Posts: 12,097
Threads: 142
Joined: Dec 2002
SetTimer is better in window procedure.
wait is better anywhere else.
Posts: 12,097
Threads: 142
Joined: Dec 2002
This version also has flags for toolbars that must have single horizontal or vertical line of buttons.
Function TB_AdjustSize
;/
function hWnd [flags] ;;flags: 1 horizontal tb, 2 vertical tb
;Adjusts QM toolbar width and height so that all (and only) buttons would be visible.
;EXAMPLE
;TB_AdjustSize win("TOOLBAR17" "QM_toolbar")
def TB_BUTTONCOUNT 0x00000418
def TB_GETITEMRECT 0x0000041D
def TB_GETBUTTONSIZE 0x0000043A
dll user32 #AdjustWindowRectEx RECT*lpRect dsStyle bMenu dwEsStyle
int htb=id(9999 hWnd)
RECT r; int cx cy i
for i 0 SendMessage(htb TB_BUTTONCOUNT 0 0)
,SendMessage(htb TB_GETITEMRECT i &r)
,if(r.bottom-r.top<15) continue ;;hor sep
,sel flags&3
,,case 1
,,if(r.right>cx) cx=r.right; else cx+r.right-r.left
,,if(cy=0) cy=r.bottom
,,case 2
,,if(r.bottom>cy) cy=r.bottom; else cy+r.bottom-r.top
,,if(cx=0) cx=r.right
,,case else
,,if(r.right>cx) cx=r.right
,,if(r.bottom>cy) cy=r.bottom
if(cx) r.right=cx; r.bottom=cy
else i=SendMessage(htb TB_GETBUTTONSIZE 0 0); r.right=i&0xffff; r.bottom=i>>16
r.left=0; r.top=0
AdjustWindowRectEx &r GetWinStyle(hWnd) 0 GetWinStyle(hWnd 1)
siz r.right-r.left r.bottom-r.top hWnd