Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dealing with repeating code
#4
Function MultiControlAction
Code:
Copy      Help
;/
function hDlg $idList *action [_on] ;;action: MCA_Show, MCA_Enable, MCA_Check, MCA_NoTheme

;Performs an action on multiple dialog controls specified as a list of ids.

;hDlg - dialog handle.
;idList - list of control ids. Separate ids using space. Use hyphen to specify range of ids. Use -id to reverse action for some controls.
;action - a function that performs an action. Beside the predefined functions you can create your own functions. See MCA_Show code.
;_on - if 1, turns the property on (eg shows), if 0 - off (eg hides). Ignored with MCA_NoTheme.

;EXAMPLE
;MultiControlAction hDlg "3 5-7 -11" MCA_Enable 0


int i v h on
ARRAY(POINT) a; POINT& p
rep
,if(idList[i]='-') i+1; on=!_on; else on=_on!0
,v=val(idList+i); h=id(v hDlg); if(h) &p=a[]; p.x=h; p.y=on
,i=findcs(idList " -" i)+1; if(i=0) break
,if(idList[i-1]='-')
,,for(v v+1 val(idList+i)+1) h=id(v hDlg); if(h) &p=a[]; p.x=h; p.y=on
,,i=findc(idList 32 i)+1; if(i=0) break

call action &a

Function MCA_Show
Code:
Copy      Help
;/
function* [ARRAY(POINT)&a]

if(!&a) ret &MCA_Show
int i
for(i 0 a.len) ShowWindow a[i].x iif(a[i].y SW_SHOW SW_HIDE)

Function MCA_Enable
Code:
Copy      Help
;/
function* [ARRAY(POINT)&a]

if(!&a) ret &MCA_Enable
int i
for(i 0 a.len) EnableWindow a[i].x a[i].y

Function MCA_Check
Code:
Copy      Help
;/
function* [ARRAY(POINT)&a]

if(!&a) ret &MCA_Check
int i
for(i 0 a.len) SendMessage a[i].x BM_SETCHECK a[i].y 0

Function MCA_NoTheme
Code:
Copy      Help
;/
function* [ARRAY(POINT)&a]

if(!&a) ret &MCA_NoTheme
dll- uxtheme #SetWindowTheme hwnd @*pszSubAppName @*pszSubIdList
if(_winver<0x501) ret

int i
for(i 0 a.len) SetWindowTheme a[i].x L"" L""


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)