example
Toolbar
Toolbar73
;/hook QmToolbar_HookCheck
Check1 :out QmToolbar_IsChecked ;;[check c1] * cut.ico
Simple button :out "simple"
;comment
Check2 :out QmToolbar_IsChecked ;;[check c2] * copy.ico
Check, don't save :out QmToolbar_Check(2) * paste.ico
Enable macro :if(QmToolbar_IsChecked) dis- "Macro1111"; else dis+ "Macro1111" ;;[check enableMacro]
Need these functions. Can be used with all toolbars, don't need to edit.
Function
QmToolbar_HookCheck
;/
function# hwnd message wParam lParam
;QM toolbar hook function that manages button checked states.
;In toolbar text finds text [check id] in button code comments, sets checkbox style for these buttons.
;Here id is some alphanumeric text, unique in the toolbar, used to save/restore button states with this name. Example: Label :out 1 ;;[check c1] * icon.ico
;When closing toolbar, saves button checked states in macro resources of the toolbar. When toolbar created or modified, restores button checked states.
;OutWinMsg message wParam lParam
sel message
,case WM_INITDIALOG
,;gInit
,sub.CheckboxesInitOrSave 1 hwnd
,
,case WM_DESTROY
,sub.CheckboxesInitOrSave 0 hwnd
,
,case WM_NOTIFY
,NMHDR* nh=+lParam
,sel nh.code
,,case TBN_DELETINGBUTTON ;;toolbar modified, need to update checkboxes
,,SetTimer hwnd 8216 50 0
,
,case WM_TIMER
,sel wParam
,,case 8216
,,KillTimer hwnd wParam
,,goto gInit
#sub CheckboxesInitOrSave
function !init hwnd
int htb=id(9999 hwnd)
int* p=+GetWindowLong(hwnd 0)
int iid=p[2]
str s1.getmacro(iid)
ARRAY(str) a=s1; int i
for i 1 a.len
,str& s=a[i]
,str cName
,if(findrx(s "[^ ;].+? :.+?;;.*?\[check +(\w+).*?\]" 0 0 cName 1)<0) continue
,;out s; out cName
,TBBUTTONINFOW b.cbSize=sizeof(b); b.dwMask=TBIF_STYLE|TBIF_STATE
,if(SendMessage(htb TB_GETBUTTONINFOW i &b)<0) continue
,int check=_qmfile.SettingGetI(+iid cName); err
,if init
,,b.fsStyle|BTNS_CHECK
,,if(check) b.fsState|TBSTATE_CHECKED
,,SendMessage(htb TB_SETBUTTONINFOW i &b)
,else
,,int icCheckedNow=b.fsState&TBSTATE_CHECKED!=0
,,if(icCheckedNow!=check) _qmfile.SettingAddI(+iid cName icCheckedNow)
Function
QmToolbar_IsChecked
;/
function#
;Gets the checked state of the clicked button of current QM toolbar.
;Returns 1 if checked, 0 if not.
;REMARKS
;Call this from a QM toolbar item code.
;Gets button from mouse position.
int h=id(9999 TriggerWindow)
POINT p; xm p h 1
int i=SendMessage(h TB_HITTEST 0 &p)
if(i<0) ret
ret SendMessage(h TB_ISBUTTONCHECKED i 0)
Function
QmToolbar_Check
;/
function# check ;;check: 0 uncheck, 1 check, 2 toggle
;Checks, unchecks or toggles the check state of the clicked button of current QM toolbar.
;Returns the final state: 1 checked, 0 unchecked.
;REMARKS
;Call this from a QM toolbar item code.
;Gets button from mouse position.
int h=id(9999 TriggerWindow)
POINT p; xm p h 1
int i=SendMessage(h TB_HITTEST 0 &p)
if(i<0) ret
int isChecked=SendMessage(h TB_ISBUTTONCHECKED i 0)
if(check<=1 and isChecked=check) ret check
check=!isChecked
if(!SendMessage(h TB_CHECKBUTTON i check)) ret isChecked
ret check
Function
QmToolbar_GetSavedCheckState
;/
function# $toolbarName $checkId
;Gets the saved checked state of a checkbox-button of a QM toolbar.
;Returns 1 if checked, 0 if not (or not saved).
ret _qmfile.SettingGetI(toolbarName checkId); err
Function
QmToolbar_SetSavedCheckState
;/
function $toolbarName $checkId isChecked
;Sets the saved checked state of a checkbox-button of a QM toolbar.
opt noerrorshere 1
_qmfile.SettingAddI(toolbarName checkId isChecked!=0)