I needed a live status update of my network's ping time, so I found I could use the Progress control to fake it.
And to have multiple status bars, I finally took the time to learn to use objects and arrays.
To use it just run Lines_init for each bar, with a new variable as the first paramater:
Code: Select all
Lines_init(variable,gui_width,gui_height,line_width,max_value,"color")
Code: Select all
Lines_Update(variable,new_value)
Skrommel
Code: Select all
;Lines.ahk
; Creates a scrolling bar chart using the Progress control
;
; Syntax:
; Lines_init(variable,gui_width,gui_height,line_width,max_value,"color")
; Lines_Update(variable,new_value)
;
;Skrommel @ 2017
#NoEnv
#SingleInstance,Force
SetBatchLines,-1
SetWinDelay,0
SetControlDelay,0
;Example
Lines_init(bar1,20,20,1,1000,"Blue")
Lines_init(bar2,30,30,2,2000,"Red")
Lines_Init(bar3,40,40,3,3000,"Green")
Gui,Show,,Lines
Loop
{
Random,new_value,1,1000
Lines_Update(bar1,new_value)
Random,new_value,1,2000
Lines_Update(bar2,new_value)
Random,new_value,1,3000
Lines_Update(bar3,new_value)
Sleep,100
}
Lines_Init(ByRef lines="",gui_width=50,gui_height=20,width=1,max=1000,color="Blue")
{
lines:={}
lines.counter:=0
lines.gui_width:=gui_width
lines.gui_height:=gui_height
lines.width:=width
lines.height:=Object()
lines.ctrl:=Object()
lines.max:=max
lines.color:=color
Loop,% gui_width
{
Gui,Add,Progress,% "XP+" width+1 " W" width+2 " H" lines.gui_height " C" lines.color " HWNDhwnd Vertical Range0-" lines.gui_height,% A_Index*lines.gui_height/lines.gui_width
lines.ctrl[A_Index]:=hwnd
}
}
Lines_Update(ByRef lines,new_value)
{
lines.counter+=1
If (lines.counter>lines.gui_width)
lines.counter:=1
height:=Ceil(new_value*lines.gui_height/lines.max)+1 ;+1 to always show a line
If (height>lines.gui_height)
height:=lines.gui_height ;cutoff for large values
If (lines.counter=1)
height:=0 ;creates a visible gap
lines.height[lines.gui_width]:=height
Loop,% lines.gui_width
{
GuiControl,,% lines.ctrl[A_Index],% lines.height[A_Index]
lines.height[A_Index]:=lines.height[A_Index+1]
}
Return
}
GuiClose:
ExitApp