-
Notifications
You must be signed in to change notification settings - Fork 72
/
SB_SETPROGRESS.ahk
121 lines (103 loc) · 5.01 KB
/
SB_SETPROGRESS.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
; SB_SetProgress
; (w) by DerRaphael / Released under the Terms of EUPL 1.0
; see http://ec.europa.eu/idabc/en/document/7330 for details
SB_SetProgress(Value=0,Seg=1,Ops="") {
; Definition of Constants
Static SB_GETRECT := 0x40a ; (WM_USER:=0x400) + 10
, SB_GETPARTS := 0x406
, SB_PROGRESS ; Container for all used hwndBar:Seg:hProgress
, PBM_SETPOS := 0x402 ; (WM_USER:=0x400) + 2
, PBM_SETRANGE32 := 0x406
, PBM_SETBARCOLOR := 0x409
, PBM_SETBKCOLOR := 0x2001
, dwStyle := 0x50000001 ; forced dwStyle WS_CHILD|WS_VISIBLE|PBS_SMOOTH
; Find the hWnd of the currentGui's StatusbarControl
Gui,+LastFound
ControlGet,hwndBar,hWnd,,msctls_statusbar321
if (!StrLen(hwndBar)) {
rErrorLevel := "FAIL: No StatusBar Control" ; Drop ErrorLevel on Error
} else If (Seg<=0) {
rErrorLevel := "FAIL: Wrong Segment Parameter" ; Drop ErrorLevel on Error
} else if (Seg>0) {
; Segment count
SendMessage, SB_GETPARTS, 0, 0,, ahk_id %hwndBar%
SB_Parts := ErrorLevel - 1
If ((SB_Parts!=0) && (SB_Parts<Seg)) {
rErrorLevel := "FAIL: Wrong Segment Count" ; Drop ErrorLevel on Error
} else {
; Get Segment Dimensions in any case, so that the progress control
; can be readjusted in position if neccessary
if (SB_Parts) {
VarSetCapacity(RECT,16,0) ; RECT = 4*4 Bytes / 4 Byte <=> Int
; Segment Size :: 0-base Index => 1. Element -> #0
SendMessage,SB_GETRECT,Seg-1,&RECT,,ahk_id %hwndBar%
If ErrorLevel
Loop,4
n%A_index% := NumGet(RECT,(a_index-1)*4,"Int")
else
rErrorLevel := "FAIL: Segmentdimensions" ; Drop ErrorLevel on Error
} else { ; We dont have any parts, so use the entire statusbar for our progress
n1 := n2 := 0
ControlGetPos,,,n3,n4,,ahk_id %hwndBar%
} ; if SB_Parts
If (InStr(SB_Progress,":" Seg ":")) {
hWndProg := (RegExMatch(SB_Progress, hwndBar "\:" seg "\:(?P<hWnd>([^,]+|.+))",p)) ? phWnd :
} else {
If (RegExMatch(Ops,"i)-smooth"))
dwStyle ^= 0x1
hWndProg := DllCall("CreateWindowEx","uint",0,"str","msctls_progress32"
,"uint",0,"uint", dwStyle
,"int",0,"int",0,"int",0,"int",0 ; segment-progress :: X/Y/W/H
,"uint",DllCall("GetAncestor","uInt",hwndBar,"uInt",1) ; gui hwnd
,"uint",0,"uint",0,"uint",0)
SB_Progress .= (StrLen(SB_Progress) ? "," : "") hwndBar ":" Seg ":" hWndProg
} ; If InStr Prog <-> Seg
; HTML Colors
Black:=0x000000,Green:=0x008000,Silver:=0xC0C0C0,Lime:=0x00FF00,Gray:=0x808080
Olive:=0x808000,White:=0xFFFFFF,Yellow:=0xFFFF00,Maroon:=0x800000,Navy:=0x000080
Red:=0xFF0000,Blue:=0x0000FF,Fuchsia:=0xFF00FF,Aqua:=0x00FFFF
If (RegExMatch(ops,"i)\bBackground(?P<C>[a-z0-9]+)\b",bg)) {
if ((strlen(bgC)=6)&&(RegExMatch(bgC,"i)([0-9a-f]{6})")))
bgC := "0x" bgC
else if !(RegExMatch(bgC,"i)^0x([0-9a-f]{1,6})"))
bgC := %bgC%
if (bgC+0!="")
SendMessage, PBM_SETBKCOLOR, 0
, ((bgC&255)<<16)+(((bgC>>8)&255)<<8)+(bgC>>16) ; BGR
,, ahk_id %hwndProg%
} ; If RegEx BGC
If (RegExMatch(ops,"i)\bc(?P<C>[a-z0-9]+)\b",fg)) {
if ((strlen(fgC)=6)&&(RegExMatch(fgC,"i)([0-9a-f]{6})")))
fgC := "0x" fgC
else if !(RegExMatch(fgC,"i)^0x([0-9a-f]{1,6})"))
fgC := %fgC%
if (fgC+0!="")
SendMessage, PBM_SETBARCOLOR, 0
, ((fgC&255)<<16)+(((fgC>>8)&255)<<8)+(fgC>>16) ; BGR
,, ahk_id %hwndProg%
} ; If RegEx FGC
If ((RegExMatch(ops,"i)(?P<In>[^ ])?range((?P<Lo>\-?\d+)\-(?P<Hi>\-?\d+))?",r))
&& (rIn!="-") && (rHi>rLo)) { ; Set new LowRange and HighRange
SendMessage,0x406,rLo,rHi,,ahk_id %hWndProg%
} else if ((rIn="-") || (rLo>rHi)) { ; restore defaults on remove or invalid values
SendMessage,0x406,0,100,,ahk_id %hWndProg%
} ; If RegEx Range
If (RegExMatch(ops,"i)\bEnable\b"))
Control, Enable,,, ahk_id %hWndProg%
If (RegExMatch(ops,"i)\bDisable\b"))
Control, Disable,,, ahk_id %hWndProg%
If (RegExMatch(ops,"i)\bHide\b"))
Control, Hide,,, ahk_id %hWndProg%
If (RegExMatch(ops,"i)\bShow\b"))
Control, Show,,, ahk_id %hWndProg%
ControlGetPos,xb,yb,,,,ahk_id %hwndBar%
ControlMove,,xb+n1,yb+n2,n3-n1,n4-n2,ahk_id %hwndProg%
SendMessage,PBM_SETPOS,value,0,,ahk_id %hWndProg%
} ; if Seg greater than count
} ; if Seg greater zero
If (regExMatch(rErrorLevel,"^FAIL")) {
ErrorLevel := rErrorLevel
Return -1
} else
Return hWndProg
}