Joined: November 23rd, 2007, 10:23 am Posts: 841 Location: ~/.
|
Here is a full synopsis:
Help on SB_SetProgress wrote: SB_SetProgress ___________________________________________________________________
Creates and controls a progressbar placed atop the last known AHK Gui's Statusbar control.
SB_SetProgress([param1 [, segment [, options]]]) Parameters wrote: Param1 Needs to be a number in the given range of the progressbar, its bar's position is changed to that value. The default range can be changed with the method described below. By default it is from 0 to 100.
Segment Specify the segment you wish to attach the Progressbar to. If you want only to change it's appearance with the options, and no segments are defined, use 1 which is also the default value.
Options A string of zero or more options from the list further below. ___________________________________________________________________
Usable Options
+/-Smooth: Displays a length of segments rather than a smooth continuous bar. Specifying -Smooth is also one of the requirements to show a themed progress bar on Windows XP or later. The other requirement is that the bar not have any custom colors; that is, that the C and Background options be omitted. Windows 95 and NT4 require Internet Explorer 3.0 or later to support this option.
+/-Range: Sets the range to be something other than 0 to 100. After the word Range, specify the minimum, a dash, and maximum. For example, Range0-1000 would allow a numbers between 0 and 1000; Range-50-50 would allow numbers between -50 and 50; and Range-10--5 would allow numbers between -10 and -5. On Windows 95 and NT4, negative ranges and ranges beyond 65535 will not behave correctly unless Internet Explorer 3.0 or later is installed. Using -Range (minus range) will reset the range to standard defaults.
Cn: Changes the bar's color. Specify for n one of the 16 primary HTML color names or a 6-digit RGB color value. Examples: cRed, cFFFF33, cDefault. If the C option is never used (or cDefault is specified), the system's default bar color will be used.
BackgroundN: Changes the bar's background color. Specify for n one of the 16 primary HTML color names or a 6-digit RGB color value. Examples: BackgroundGreen, BackgroundFFFF33, BackgroundDefault. If the Background option is never used (or BackgroundDefault is specified), the background color will be that of the window or tab control behind it.
Enable: Enables a control if it was previously disabled. On by default.
Disable: Disables or "grays out" a control.
Show: Shows a control if it was previously hidden.
Hide: Hides the progressbar control.
___________________________________________________________________
ErrorLevel
In case an error happens, The ErrorLevel will contain informations about what went wrong. All Descriptions start with the word "FAIL:" written in caps. Possible contents and a brief explanation:
No StatusBar Control Obvious.
Wrong Segment Parameter Will be set when Segment parameter is smaller or equal zero.
Wrong Segment Count Will be set when higher Segment number is given than actual segements exist. Exception: When operating with just a standard statusbarcontrol and no segments at all, a given Segment parameter can be used to have more than just one Progressbar of which only the latest according to its z-Order will be displayed.
Segmentdimensions The function was unable to determine given Segment's dimensions (x/y of upper left corner and x/y of lower right corner)
On success the ErrorLevel will contain 1
___________________________________________________________________
Returnvalue
When an Error of the pervious described occurs, the returnvalue will be set to -1. On success to the progressbar's WindowHandle (hWnd). ___________________________________________________________________
Performance
Allthough it works, it is better not to supply options directly at a loop which will permanently update the statusbar. This may result in flickering of the progressbar due to parsing all comments on each run. Better is to use Seperate commands, and have just passed Param1 and Segemt to update the progressbar. See the example below how to use this properly.
___________________________________________________________________
Remarks
Currently the so called marqueestyle (that is no given size, but a contantly moving part of the bar) is not functional. The -Smooth/+Smooth parameter will only be evaluated upon Progressbar creation and cannot be changed from within the function lateron.
Using the PBM_DELTAPOS message to increment the Bar by a given step and not by an absolute number is not implemented yet. So something comparable to
Code: GuiControl,, MyProgress, +20 ; Increase the current position by 20. won't work at the moment.
To get the current's Progressbar value (if ever needed) a SendMessage must be used like this:
Code: hwnd := SB_SetProgress(50,3,"BackgroundYellow cBlue") ; This is the way to obtain the handle to the control SendMessage, PBM_GETPOS:=0x408, wParam:=0, lParam:=0,,ahk_id %hWnd% ; wParam, and lParam needs to be zero in this case MsgBox %ErrorLevel% ; The ErrorLevel contains the current position ___________________________________________________________________
Related
StatusBar, Progress, Styles
___________________________________________________________________
Resources
Progress Bar Control Reference > Messages http://msdn.microsoft.com/en-us/library/cc656531(VS.85).aspx
[ahksushi] Statusbar with Progressbar and animated Icon http://www.autohotkey.com/forum/viewtopic.php?t=37674
[Solved] How to send an array with SendMessage http://www.autohotkey.com/forum/topic6017.html
[tutorial] Creating windows without GUI commands http://www.autohotkey.com/forum/viewtopic.php?t=22904
___________________________________________________________________
Examples
Code: SB_SetProgress(10) ; will create a progress onto entire statusbar showing 10% bar
A little working example:
Code: Gui,add,text,w280 center,Some text for the gui! Gui,add,statusbar Gui,show,w300,Statusbar with Progress
SB_SetParts(20,200,100) ; Make 3 different parts SB_SetText("demotext",2) ; Set a text segment 2 SB_SetIcon(A_AhkPath,1,1) ; Set an Icon to 1st segment ; create a 50% progressbar with yellow background and blue bar hwnd := SB_SetProgress(50,3,"BackgroundYellow cBlue") return
This example shows advanced features of the SB_SetProgress function
Code: ; ahk-Sushi: Anime Icon + Progressbar in Statusbar ; (w) Nov 2008 by DerRaphael(at)oleco.net ; modified for SB_SetProgress demonstration
gui,add,text,w180 center y10,Demo anime Icon`n+ Progressbar in StatusbarControl gui,add,button,x+10 yp-3 w90 gRestart vBtn1 default, Restart! Gui,add,statusbar, hwndhwndBar gui,show,w300,[ahksushi] Statusbar Demo
SB_SetParts(20,200,100) SB_SetText("demotext",2) hIS := SB_SetIcon(A_AhkPath,1,1) hwnd := SB_SetProgress(50,3,"BackgroundGreen cLime") Gosub, Prep_Animation
Restart: SB_SetProgress(0,3,"show") GuiControl,Disable,Btn1 Gui,+LastFound ControlFocus pp := 0 SetTimer,ProgressAnimation,50 return
ProgressAnimation: SB_SetProgress(++pp,3) R := mod(pp,8)//2+1 SendMessage, 0x40F, 0, hI%R%,, ahk_id %hwndBar% ; SB_SETICON := (WM_USER:=0x400) + 15 - icon animation! if (pp=100) { SendMessage, 0x40F, 0, hIS,, ahk_id %hwndBar% ; StandardIcon hIS SB_SetText("`tEat mo' sushi!",2,0) ; update Text SetTimer,ProgressAnimation,Off ; Timer OFF GuiControl,Enable,Btn1 SB_SetText("`tDone!",3,0) ; update Text SB_SetProgress(0,3,"hide") ; hide the progress } else ; update Text SB_SetText("`tLala lala la: " pp " %",2,0) Return
Prep_Animation: ; Prepare Animation - Load 4 Icons and make their handle available hInst := DllCall("GetModuleHandle", "str", "shell32.dll") Loop,4 hI%A_index% := DllCall("LoadImage", "Uint", hInst, "Uint", 3+A_index, "Uint", 1 , "int", 16, "int", 16, "Uint", 0x8000) Return
GuiEscape: GuiClose: exitapp
The code for the function - include this either in every script u decide to use it, or put it directly into your StdLib (e.g. Path\To\Ahk.exe\lib\SB.ahk) with the desired filename SB.ahkCode: ; 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
}
_________________
All scripts, unless otherwise noted, are hereby released under CC-BY
Last edited by derRaphael on September 20th, 2009, 1:45 pm, edited 2 times in total.
|
|