AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Progress on statusbar

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
tuna



Joined: 03 Oct 2007
Posts: 47
Location: Bristol, England

PostPosted: Sun Dec 02, 2007 12:02 pm    Post subject: Progress on statusbar Reply with quote

Is it possible to have a progress bar on a status bar (i.e. like IE) - it seems you cannot position any control over a statusbar and I really dont want to create another window for a faux effect.

Any suggestions anyone?

Many thanks
Back to top
View user's profile Send private message
dmatch



Joined: 15 Oct 2007
Posts: 113

PostPosted: Sun Dec 02, 2007 4:53 pm    Post subject: 2 Ways Reply with quote

I have found 2 ways to use the StatusBar as a progress bar. They may or may not be to your liking.

If you want a multipart StatusBar with readable text in 1 part then the following sort of looks like a progress bar using the | character:
Code:
Gui, Font, s10 w700
Gui, Add, text, vTest x10 y10 w400 h200, This is a test.
Gui, Add, StatusBar
SB_SetParts(100)
Status:=" "
SB_SetText("Processing:",1)
Gui, Show
Loop, 50
{
   sleep, 500
   Status:=Status . "|"
   SB_SetText(Status, 2)
}
ExitApp

If you don't want to write any readable text and use a single part StatusBar then you could try using the Webdings font as follows:
Code:
Gui, Add, text, vTest x10 y10 w400 h200, This is a test.
Gui, Font, s10 w700, Webdings
Gui, Add, StatusBar
Gui, Show
Loop, 30
{
   sleep, 500
   Status:=Status . "g"
   SB_SetText(Status)
}
ExitApp

Apparently, whatever font is chosen when the StatusBar is first used can not be changed. So if you wanted to write normal text in 1 part and use Webdings in the second part of the StatusBar (for progress) it won't work right and you would get either unreadable text and a progress bar or readable text and g's for your progress bar.

Anyway, maybe you will find one of the two methods to be useful.

You might could get what you want by using DOS characters. There are some graphics characters that DOS programs used to use for progress bars (chars 176-178), but I don't know if or how one could get AHK to use DOS characters.

There might also be a way to use icons in a multipart StatusBar and add a rectangular icon into sequential StatusBar subparts to indicate progress but I haven't tried that.

Hope this helps,

dmatch
Back to top
View user's profile Send private message
tuna



Joined: 03 Oct 2007
Posts: 47
Location: Bristol, England

PostPosted: Mon Dec 03, 2007 9:08 pm    Post subject: Reply with quote

Cheers, but I guess thats another one for the wish list...
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 6847
Location: Pacific Northwest, US

PostPosted: Mon Dec 03, 2007 9:10 pm    Post subject: Reply with quote

dmatch's first one seems usable.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
dmatch



Joined: 15 Oct 2007
Posts: 113

PostPosted: Wed Dec 05, 2007 11:00 pm    Post subject: Re: Progress on statusbar Reply with quote

tuna wrote:
Is it possible to have a progress bar on a status bar


After further consideration I can now answer YES. It actually can be put there with some small effort.

Try this:
Code:

Gui, +resize
Gui, Font, s16
Gui, Add, Text, w350, This is just something in the Gui to look at
and take up some space
, so a Gui with automatic height will have a little more to work with.
Gui, Add, Button, gDemo Default, &Demo
Gui, Add, Text, ,`n ;Keeps button from drawing over statusbar

;Must show Gui before adding ProgressOnStatusBar
Gui, show, x10 y10 w400, ProgressOnStatusBar Demo1
;Add the ProgressOnStatusBar. Range 1-1000 with Red color.
;Status text is 120 pixels wide and says Ready1:
ProgressOnStatusBar(1, 1, 1000, "Red", "Ready1:", 120)

Gui, 2:+resize
Gui, 2:Add, Text, w450, This is just something in the Gui to look at
and take up some space
and so a Gui with automatic height will have a little more to work with.
Gui, 2:Add, Button, gDemo2 Default, &Demo
Gui, 2:Add, Text, ,`n ;Keeps button from drawing over statusbar

;Must show Gui before adding ProgressOnStatusBar
Gui, 2:show, x200 y100 w450, ProgressOnStatusBar Demo2
;Add a ProgressOnStatusBar to Gui 2. Range 1-1000 with default color.
;Status text will be default (80) pixels wide and is default text.
ProgressOnStatusBar(2, 1, 1000)

return

;More than 1 window may have a ProgressOnStatusBar
;as shown in the demos below
Demo:
{
   ProgressOnStatusBar(1, 1, 1000, "", "Ready1:", 120)
   Loop, 100
   {
      Sleep, 20
      ProgressOnStatusBar(1,A_Index*10) ;Change bar value
      if(Mod(A_Index,50)=0) ;show that we can change status text
         ProgressOnStatusBar(1, "Please Wait1:")
   }
   ProgressOnStatusBar(1,"Off", "Ready1:")
   return
}

Demo2:
{
   ProgressOnStatusBar(2, 1, 1000)
   Loop, 100
   {
      temp=LoopCount=%A_Index%
      ProgressOnStatusBar(2,A_Index*10, temp)
      sleep, 20
      if(Mod(A_Index,50)=0) ;show that we can change status text
         ProgressOnStatusBar(2, "Please Wait2:")
   }
   ProgressOnStatusBar(2,"Off", "Ready2:")
   GoSub Demo3
   return
}

Demo3: ;Reuse the Demo2 statusbar again but change some stuff
{
   ;Add extra status bar parts
   ProgressOnStatusBar(2, 1, 1000, 0x0000ff, "Proceesing - C:\AFolder\AFile.txt", 150, 80, 80)
   SB_SetText("SBXtra1",3) ;Can use extra status bar parts
   SB_SetText("SBxtra2",4)
   Loop, 100
   {
      ProgressOnStatusBar(2,A_Index*10)
      sleep, 50
      if(Mod(A_Index,50)=0){ ;show that we can change some stuff
         ProgressOnStatusBar(2, "Please Wait2:")
      }
   }
   ProgressOnStatusBar(2,"Off", "Ready3:")
   return

}

GuiClose:
2GuiClose:
ExitApp

Using this function:
Code:

;******************* ProgressOnStatusBar ******************
ProgressOnStatusBar(GuiNum    ; Gui number for bar
, PSBControl1             ; Minimum Range,
                     ; Progress value, or "Off"
, PSBControl2=""         ; Maximum Range or
                     ; status text when "Off" above
, PColor=""                ; Color of progress bar
, StatusText="Ready:"       ; Starting status text
, StatusTextWidth=80      ; Status text width (pixels)
, SBPartExtra1=0         ; Extra status bar part widths
, SBPartExtra2=0)         ; Max of 2.
{

/**********************************************************
A function to add and use a status bar as a progress bar.

The ProgressOnStatusBar will be added to the Gui Window
number as passed to GuiNum and will consist of 2 or more
parts.

The leftmost part will contain status text as passed to
StatusText with a width as passed to StatusTextWidth.
The next part to the right will contain the
progress bar followed by any extra status bar parts.
You may choose the progress bars color by passing a RGB
color or AHK recognized color name to PColor.

First create the ProgressOnStatusBar by passing Range
numbers to both PSBControl1 and PSBControl2 and passing
other variables as appropriate. Thereafter, if PSBControl1
is the string "Off" the progress bar is hidden and
any string in PSBControl2 will be used as status text.
If PSBControl1 is any string (not number) other than
"Off" it is used to update the status text only.

If PSBControl1 is a number and PSBControl2
is a string or not passed, PSBControl1 will be used
to set the progress bar value and, if there is a string
in PSBControl2, it will be used to set the status text.

The function PSB_WM_SIZE (included) is used internally
to move the Progress Bar as the Gui window is resized.

This function changes the default Gui to the value
passed to GuiNum.

Globals variables that the function creates:

A_SBn      StatusBar variable       
A_PSBn      ProgressBar variable     
A_PrognX   X pos of progress bar   
A_PrognY   Y pos of progress bar   
A_PrognW   Width of status bar   
A_PrognH   Height of status bar   

Where n=1,2,3 ... etc.(Gui number)
   
Date: 12/04/2007
Version: 1.0
Author: dmatch @ AutoHotKey.com forum
***************************************************************
*/

   ;Declaration of local vars makes everything else global
   Local NewGui, ProgX, ProgY, ProgW, ProgH, SBID, ColorIs
   Static HaveOnMessage ;switch for use with OnMessage
   
   Gui, %GuiNum%:Default ;Make sure we have the right Gui
   
   if PSBControl1 is Number
   {
      if PSBControl2 is Number ;change or add progress bar
      {
         if(GuiNum is not integer) ; oops
            return
         NewGui:=false ;Assume this gui used before
         ;See if Gui already has a ProgressStatusBar
         GuiControl, Hide, A_PSB%GuiNum%
         if errorLevel ;Indicates Progress Bar does not exist
            NewGui:=true
         Else{
            GuiControl, Show, A_PSB%GuiNum%
         }
         if(NewGui){ ;Add a new status bar
            Gui, %GuiNum%:Add, StatusBar, vA_SB%GuiNum%
         }
         SBID=A_SB%GuiNum%
         ;Get status bar stats
         GuiControlGet, A_Prog%GuiNum% , %GuiNum%:Pos, %SBID%
         ProgX:=StatusTextWidth+2 ;x position for bar
         A_Prog%GuiNum%X:=ProgX
         ProgH:=A_Prog%GuiNum%H-2 ;height of bar
         ProgY:=A_Prog%GuiNum%Y + 2 ;y position for bar
         ProgW:=A_Prog%GuiNum%W-ProgX-1 ;Max width of bar
         ;Add extra status bar parts if required
         if(SBPartExtra1)
            ProgW-=SBPartExtra1
         if(SBPartExtra2)
            ProgW-=SBPartExtra2
         if(SBPartExtra1 and !SBPartExtra2)
            SB_SetParts(StatusTextWidth, ProgW)
         else if(SBPartExtra1 and SBPartExtra2)
            SB_SetParts(StatusTextWidth, ProgW, SBPartExtra1)
         Else
            SB_SetParts(StatusTextWidth)
         ColorIs:=""
         if(PColor) ;Have a color for the progress bar
            ColorIs=c%PColor%
         if(NewGui){ ;Add a new progress bar
            Gui, %GuiNum%:Add, Progress, Range%PSBControl1%-%PSBControl2% B x%ProgX% y%ProgY% w%ProgW% h%ProgH% vA_PSB%GuiNum% %ColorIs%
            if !HaveOnMessage ;redirect WM_SIZE messages
               OnMessage(0x05, "PSB_WM_SIZE")
            HaveOnMessage:=true
         }
         Else{ ;Use old progress bar
            if(SBPartExtra1)
               ProgW:=ProgW-2
            GuiControl, Move, A_PSB%GuiNum%, x%ProgX% y%ProgY% w%ProgW% h%ProgH%
         }
         SB_SetText(StatusText,1) ;Display inital status text
      }
      Else{
         if(PSBControl2 <> "") ;Update status text
            SB_SetText(PSBControl2, 1)
         ;Set Value for progress bar
         GuiControl,,A_PSB%GuiNum%, %PSBControl1%
      }
   }
   Else{
      if(PSBControl1="Off") ;Hide the progress bar
      {
         GuiControl, Hide, A_PSB%GuiNum%
         SB_SetText(PSBControl2,1) ;Update status text      
      }
      Else{ ;Not a number and not "Off" so update status text
         SB_SetText(PSBControl1,1)
      }
   }
   return
}
PSB_WM_SIZE(wparam, lparam) ;Handles resize of Gui windows
{
   Local WinH, ProgY
   WinH:=lParam >> 16
   ProgY:=WinH-A_Prog%A_Gui%H+2
   ;Update vertical position of progress bar
   GuiControl, Move, A_PSB%A_Gui%, y%ProgY%
   return
}


This is *really* a progress bar overlaid on a status bar. When the Gui window is resizeable the progress bar needs to be moved when WM_SIZE message is received, but a small OnMessage function was all that was needed to accomadate that.

One limitation is that the status bar created can only handle a max of 4 status bar parts...1 for status text, 1 for the progress bar and 2 optional extra parts (in that order left to right).

If any find this useful I could put it in the Scripts and Tips section of the forum. If it is deemed worthy of that home.

Cheers!

dmatch
Back to top
View user's profile Send private message
Seb
Guest





PostPosted: Wed Jul 30, 2008 7:25 am    Post subject: Re: Progress on statusbar Reply with quote

This is exactly what i was looking for, and more.

Thanks a bunch.
Back to top
dmatch



Joined: 15 Oct 2007
Posts: 113

PostPosted: Wed Jul 30, 2008 2:41 pm    Post subject: Reply with quote

Glad it could be of use.

dmatch
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group