; 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 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([^,]+|.+))",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[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[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[^ ])?range((?P\-?\d+)\-(?P\-?\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 }