Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[stdlib] SB_SetProgress


  • Please log in to reply
13 replies to this topic
derRaphael
  • Members
  • 872 posts
  • Last active: Mar 19 2013 04:42 PM
  • Joined: 23 Nov 2007
Here is a full synopsis:

SB_SetProgress
___________________________________________________________________

Creates and controls a progressbar placed atop the last known AHK Gui's Statusbar control.

SB_SetProgress([param1 [, segment [, options]]])

Parameters":1l5h9s42">

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
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:
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.microsof...531(VS.85).aspx

[ahksushi] Statusbar with Progressbar and animated Icon
<!-- m -->http://www.autohotke...pic.php?t=37674<!-- m -->

[Solved] How to send an array with SendMessage
<!-- m -->http://www.autohotke.../topic6017.html<!-- m -->

[tutorial] Creating windows without GUI commands
<!-- m -->http://www.autohotke...pic.php?t=22904<!-- m -->

___________________________________________________________________

Examples

SB_SetProgress(10) ; will create a progress onto entire statusbar showing 10% bar

A little working example:

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

; 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.ahk

; 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

derRaphael
  • Members
  • 872 posts
  • Last active: Mar 19 2013 04:42 PM
  • Joined: 23 Nov 2007
-reserved-

jballi
  • Members
  • 1029 posts
  • Last active:
  • Joined: 01 Oct 2005
I haven't figured out where I'm gonna use it yet but it's way cool. Thanks for sharing. 8)

Z_Gecko
  • Guests
  • Last active:
  • Joined: --
seems like the RegEx for the range is case-sensitive by accident,
( http://www.autohotke...topic45296.html )
the SB_SetProgress-function should probably be:
; 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,"[color=red]i)[/color](?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

}


derRaphael
  • Members
  • 872 posts
  • Last active: Mar 19 2013 04:42 PM
  • Joined: 23 Nov 2007
thx z_gecko,

i just updated the main script :)

greets
dR

All scripts, unless otherwise noted, are hereby released under CC-BY

Delusion
  • Members
  • 272 posts
  • Last active: Jul 13 2014 09:04 PM
  • Joined: 16 Jul 2008
i dont know if im missing something here but this is supposed to work on other guis than the first too right?

i tried this but it wont show up
Gui 3: Default
  SB_SetParts(80,200), SB_SetProgress(10,2)

if i remove Gui 3: Default it shows up just fine in the statusbar on my 1st gui
QuickSubs | Popcorn Movie Catalog
All my scripts are just in AutoHotkey v1.0.48.05

derRaphael
  • Members
  • 872 posts
  • Last active: Mar 19 2013 04:42 PM
  • Joined: 23 Nov 2007
this actually just works fine, with the code from above;

Gui,Add,Button, gGoGui3, Go GUI 3!
Gui,Show, h50 w200, Demo Gui 1
Return


GoGui3:
	Gui,3:Default
	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

3GuiClose:
3GuiEscape:
GuiClose:
GuiEscape:
	ExitApp

greets
dR

All scripts, unless otherwise noted, are hereby released under CC-BY

Delusion
  • Members
  • 272 posts
  • Last active: Jul 13 2014 09:04 PM
  • Joined: 16 Jul 2008
looks like it had something to do with gui, show

i used to have gui, shot afer sb_setprogress and for some reason when i moved it before it it worked

thanks anyway for your quick reply
QuickSubs | Popcorn Movie Catalog
All my scripts are just in AutoHotkey v1.0.48.05

  • Guests
  • Last active:
  • Joined: --
hello!
i got a little problem with your awesome function :D
its propably something simple but i cant figure it out

i have sb_setprogress on my gui n6 ( i dont know if this matters)
the progress bar shows up just fine but when i exit the gui with gui, destroy and then start gui n6 up again it doesnt show up anymore
i have tried to use the "show" option but that doesnt seem to work either

keep up the great work i really love this!

Gauss
  • Members
  • 203 posts
  • Last active: Jan 27 2012 12:49 PM
  • Joined: 10 Sep 2009
Options like color are not working on windows 7

itjustwerks
  • Members
  • 7 posts
  • Last active: Nov 13 2015 05:19 AM
  • Joined: 18 Dec 2009

hello!
i got a little problem with your awesome function :D
its propably something simple but i cant figure it out

i have sb_setprogress on my gui n6 ( i dont know if this matters)
the progress bar shows up just fine but when i exit the gui with gui, destroy and then start gui n6 up again it doesnt show up anymore
i have tried to use the "show" option but that doesnt seem to work either

keep up the great work i really love this!


I'm having this same issue...any resolution? Here's a test script. The Return Value is blank after re-creating the GUI, while the ErrorLevel is always 0. Please help!

#Include bin\SB_SetProgress.ahk

ShowGui:
Gui, 55:Add, Text, w70 h20 , This is a test.
Gui, 55:Add, Button, x+10 y+-20 w105 h20 gReloadGui, Click to reload Gui.
Gui, 55:Add, StatusBar
Gui, 55:Show, w200 h60, Testing Progress Bar

Gui, 55:Default
SB_SetParts(100,100)
SB_SetText("Testing...",1)
hwnd := SB_SetProgress(10,2,"show")
MsgBox, Return Value = %hwnd%`nErrorLevel = %ErrorLevel%
Return

ReloadGui:
Gui, 55:Destroy
GoTo, ShowGui
Return

55GuiClose:
ExitApp


itjustwerks
  • Members
  • 7 posts
  • Last active: Nov 13 2015 05:19 AM
  • Joined: 18 Dec 2009
The issue has to do with the "SB_PROGRESS" variable. I guess it stores a list of "hwndBar:Seg:hProgress" strings to avoid recreating a progress bar in the same StatusBar segment. However, once a GUI has been destroyed and rebuilt, the progress control doesn't exist in that numbered segment yet to be updated. The following code change resolves this issue:

Change line 48

If (InStr(SB_Progress, ":" Seg ":")) {

to

If (InStr(SB_Progress, [color=red]hwndBar[/color] ":" Seg ":")) {

This takes into consideration the unique ID of the window, as well as the segment number. For a new window (recreated GUI), the progress bar will first be created before being updated.

Hope this helps someone out.

segalion
  • Members
  • 50 posts
  • Last active: Oct 16 2014 09:20 AM
  • Joined: 02 Feb 2011
Ive tested sucessfully this func, but seems it take more than 16 milliseconds to work.

Please can be possible to speedup this progress? Maybe regex is very CPU hard...

BGM
  • Members
  • 199 posts
  • Last active: Jun 05 2015 06:26 PM
  • Joined: 12 Jan 2011

Hello!  This is really awesome!  I am creating a list-searcher, and this is perfect.

 

My only complaint is that when I resize the window (I added "gui, new, +resize" to the top of the basic example), it doesn't move with the statusbar.  You can see what happens when I resize the window.  Weird.  It leaves the statusbar in its original place in the window where it was before the window was resized, but it also creates a mini-version of it and draws it in the statusbar where it should appear.

 

x7a3.png

gui, new, +resize
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)

return

This seems to work (make sure not to enquote the hwnd):

guisize:
    anchor(hwnd, "y", "r")
return

Autohotkey 1.1.11.01 on Windows 7 Pro x64


(AutoHotkey 1.1.15.00 on Windows 7 Pro x64)