05-15-2006, 10:12 PM
Function DT_TbAddButtons
Function DT_TbOnDestroy
Sample dialog, function dialog_toolbar
;/
function hwndTb firstBtnId $stringList $bitmapFile [styles] [flags] [maskColor] [ARRAY(int)&iconHandles] [defaultIcon] ;;flags: 1 icons
;Adds buttons to ToolbarWindow32 control.
;Call this function from dialog procedure, on WM_INITDIALOG. On WM_DESTROY, call DT_TbOnDestroy.
;hwndTb - toolbar control handle.
;firstBtnId - id of first button. Used for notifications in the same way as id of Button control.
;stringList - list of button label strings.
;;;Empty lines also add buttons.
;;;- adds separator. Separator size can be specified after -. Separators don't have id and image.
;bitmapFile - bmp file containing horizontally aligned 16x16 images. Color maskColor will be transparent.
;styles - toolbar styles to add.
;flags - 1 - bitmapFile is list of icon files.
;maskColor - color in bmp file that will be transparent. Default or 0 - magenta (0xff00ff).
;iconHandles - array that contains icon handles. If used and not 0, bitmapFile and maskColor are ignored. You can destroy icons immediately after calling this function.
if(styles) SetWinStyle hwndTb styles 1
int nBtn=numlines(stringList)
;create image list
int il hi j
str s
if(!defaultIcon) defaultIcon=_dialogicon
if(&iconHandles)
,il=ImageList_Create(16 16 WINAPI.ILC_MASK|WINAPI.ILC_COLOR32 0 iconHandles.len)
,for j 0 iconHandles.len
,,hi=iconHandles[j]
,,if(!hi) hi=defaultIcon
,,ImageList_ReplaceIcon(il -1 hi)
else if(flags&1)
,il=ImageList_Create(16 16 WINAPI.ILC_MASK|WINAPI.ILC_COLOR32 0 nBtn)
,foreach s bitmapFile
,,hi=GetIcon(s)
,,if(!hi) hi=defaultIcon
,,ImageList_ReplaceIcon(il -1 hi)
,,if(hi!=defaultIcon) DestroyIcon hi
else
,if(!maskColor) maskColor=0xFF00FF
,il=ImageList_LoadImage(0 _s.expandpath(bitmapFile) 16 0 maskColor IMAGE_BITMAP LR_LOADFROMFILE)
SendMessage hwndTb WINAPI.TB_SETIMAGELIST 0 il
;create array of TBBUTTON structures
type TBBUTTON iBitmap idCommand !fsState !fsStyle !bReserved[2] dwData iString
ARRAY(TBBUTTON) a.create(nBtn)
int i ii
foreach s stringList
,TBBUTTON& t=a[i]
,if(s.beg("-"))
,,t.fsStyle=WINAPI.TBSTYLE_SEP ;;separator
,,t.iBitmap=val(s+1)
,else
,,t.idCommand=firstBtnId+ii
,,t.iBitmap=ii
,,if(s.len) t.iString=SendMessage(hwndTb WINAPI.TB_ADDSTRINGA 0 s)
,,else t.iString=-1
,,t.fsState=WINAPI.TBSTATE_ENABLED
,,ii+1
,i+1
SendMessage(hwndTb WINAPI.TB_BUTTONSTRUCTSIZE sizeof(TBBUTTON) 0)
SendMessage(hwndTb WINAPI.TB_ADDBUTTONS a.len &a[0])
Function DT_TbOnDestroy
Sample dialog, function dialog_toolbar
\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages
if(!ShowDialog("dialog_toolbar" &dialog_toolbar)) ret
;BEGIN DIALOG
;0 "" 0x90C80A44 0x100 0 0 319 197 "Form"
;1 Button 0x54030001 0x4 120 166 48 14 "OK"
;2 Button 0x54030000 0x4 170 166 48 14 "Cancel"
;3 ToolbarWindow32 0x5400000C 0x0 0 0 294 30 ""
;4 ToolbarWindow32 0x5400000C 0x0 0 30 294 18 ""
;5 ToolbarWindow32 0x5400000C 0x0 0 48 294 18 ""
;END DIALOG
;DIALOG EDITOR: "" 0x2010805 "" ""
ret
;messages
sel message
,case WM_INITDIALOG
,DT_Init(hDlg lParam)
,int styles=WINAPI.TBSTYLE_FLAT
,DT_TbAddButtons id(3 hDlg) 1001 "one[]two[]-[]three[]four" "$qm$\de_ctrl.bmp" styles|WINAPI.CCS_NODIVIDER
,DT_TbAddButtons id(4 hDlg) 1101 "[][]-60[][][]" "$qm$\de_ctrl.bmp" styles
,DT_TbAddButtons id(5 hDlg) 1201 "one[]two[]three" "shell32.dll,1[]shell32.dll,2[]shell32.dll,3" styles|WINAPI.TBSTYLE_LIST 1
,ret 1
,
,case WM_DESTROY
,DT_DeleteData(hDlg)
,DT_TbOnDestroy id(3 hDlg)
,DT_TbOnDestroy id(4 hDlg)
,DT_TbOnDestroy id(5 hDlg)
,
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case 1001 mes "button 1"
,case 1002 mes "button 2"
,case 1003 mes "button 3"
,case IDOK DT_Ok hDlg
,case IDCANCEL DT_Cancel hDlg
ret 1