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 

"New Control": the ProgressMeter

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Zed Gecko



Joined: 23 Sep 2006
Posts: 98

PostPosted: Sun Feb 18, 2007 8:42 pm    Post subject: "New Control": the ProgressMeter Reply with quote

I have made 2 little functions to
create and handle a "ProgressMeter" (there is probably a better name for it).
This ProgressMeter is actually just a bunch of ProgressBars, but it is an easy way to display values that are changing in time like CPU-load or memory-load. This little demo shows the memory-load:

Code:

PM_gui = 8
PM_ControlID = own
PM_widthInSegments = 200
PM_height = 100
PM_color = red
PM_bgcolor = black
PM_xpos = 0
PM_ypos = 0

VarSetCapacity( memorystatus, 100 )

Gui, %PM_gui%:+AlwaysOnTop ; +Owner avoids a taskbar button.
Add_ProgressMeter(PM_gui, PM_ControlID, PM_widthInSegments, PM_height, PM_color, PM_bgcolor, PM_xpos, PM_ypos)
Gui, %PM_gui%:Show, NoActivate, ProgressMeter Demo  ; NoActivate avoids deactivating the currently active window.
SetTimer, ShowMemoryUsage, 250


ShowMemoryUsage:
   DllCall("kernel32.dll\GlobalMemoryStatus", "uint",&memorystatus) ; this code is from the forum, i found it several times but donīt know who made it
   mem := *( &memorystatus + 4 ) ; last byte is enough, mem = 0..100
   Update_ProgressMeter(PM_gui, PM_ControlID, mem)
return
   


;-----------------------------------------------------------------------------------------------------------------

;----------
; Add_ProgressMeter adds a "progress-meter" Control to a Gui.
; It can only be used on a Gui with a number (like Gui, 1: or Gui, 99:)but not on a unnumbered Gui.
; The generated control can disply the fluctuation of value in a range from 0 - 100.
; Usage : Add_ProgressMeter(PM_gui, PM_ControlID, PM_widthInSegments, PM_height, PM_color, PM_bgcolor, PM_xpos, PM_ypos)
; PM_gui =  the number of the Gui
; PM_ControlID = the name of the progress meter control. Use the same name with the "Update_ProgressMeter"-function
; PM_widthInSegments = the width of the control in segments. (Each segment is of 2 pixel width)
; PM_height = the height of the control in pixel
; PM_color = the color of the progress-meter
; PM_bgcolor = the background-color of the progress-meter
; PM_xpos = the X-position of the controls top-left corner
; PM_ypos = the Y-position of the controls top-left corner
; (if the X and Y position are both omited or set to 0, the control uses automatic positioning)
Add_ProgressMeter(PM_gui, PM_ControlID, PM_widthInSegments, PM_height, PM_color, PM_bgcolor, PM_xpos = 0, PM_ypos = 0)
{
   global
   PM_segmentspace = 2 ;this is the visible size of on segment in pixel
   PM_segmentsize := (PM_segmentspace + 1)
   PM_widthInSegments += -1
   %PM_ControlID%_Segments := PM_widthInSegments
   if (PM_xpos = 0 AND PM_ypos = 0)
   {
      Gui, %PM_gui%:Add, Progress, v%PM_ControlID%0 w%PM_segmentsize% h%PM_height% c%PM_color% Background%PM_bgcolor% Vertical,
   }
   else
   {
      Gui, %PM_gui%:Add, Progress, v%PM_ControlID%0 w%PM_segmentsize% h%PM_height% x%PM_xpos% y%PM_ypos% c%PM_color% Background%PM_bgcolor% Vertical,
   }
   
   Loop, %PM_widthInSegments%
   {
      Gui, %PM_gui%:Add, Progress, v%PM_ControlID%%A_Index% w%PM_segmentsize% h%PM_height% xp+%PM_segmentspace% c%PM_color% Background%PM_bgcolor% Vertical,
   }
}
;----------
; Update_ProgressMeter puts new contents in the progress-meter control created by Add_ProgressMeter.
; Usage: Update_ProgressMeter(PM_gui, PM_ControlID, PM_NewContent)
; PM_gui =  the number of the Gui the control is located in.
; PM_ControlID = the name of the progress meter control. Use the name that was used in the "Add_ProgressMeter"-function
; PM_NewContent = the new content of the control. it must be a number between 0 and 100.
; the new content will be displayed in the most-right segment.
Update_ProgressMeter(PM_gui, PM_ControlID, PM_NewContent = 0)
{
   PM_oldSegments := %PM_ControlID%_Segments
   Loop, %PM_oldSegments%
   {
      PM_NewSegment := A_Index - 1
      GuiControlGet, PM_Transfervar, %PM_gui%:, %PM_ControlID%%A_Index%
      GuiControl,%PM_gui%:, %PM_ControlID%%PM_NewSegment%, %PM_Transfervar%
   }
   
   GuiControl,%PM_gui%:, %PM_ControlID%%PM_oldSegments%, %PM_NewContent%
}
;----------

Back to top
View user's profile Send private message
Veovis



Joined: 13 Feb 2006
Posts: 390
Location: Utah

PostPosted: Sun Feb 18, 2007 10:09 pm    Post subject: Reply with quote

ooooohhhhhhh! aaaaaaAAAaaahhh!

I love you! I was just thinking the other day. You know how cool it would be if ahk had some kind of graph for cpu or ram. This is sweet! How do you find out about how to do this?
_________________

"Power can be given overnight, but responsibility must be taught. Long years go into its making."
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Veovis



Joined: 13 Feb 2006
Posts: 390
Location: Utah

PostPosted: Sun Feb 18, 2007 10:28 pm    Post subject: Reply with quote

Ahhh, i actually read the code. That is such a good idea! I thought you had done some MSDN diving or somthing. That is really cool! I modified it and made one that does processor too

Code:

PM_gui = 8
PM_ControlID = ram
PM_ControlID2 = proc
PM_widthInSegments = 200
PM_height = 100
PM_color = red
PM_bgcolor = black
PM_xpos = 10
PM_ypos = 10

VarSetCapacity( memorystatus, 100 )
   varsetcapacity(idleticks,18)

Gui, %PM_gui%:+AlwaysOnTop ; +Owner avoids a taskbar button.
Add_ProgressMeter(PM_gui, PM_ControlID, PM_widthInSegments, PM_height, PM_color, PM_bgcolor, PM_xpos, PM_ypos)
Add_ProgressMeter(PM_gui, PM_ControlID2,PM_widthInSegments, PM_height, "red", "green", 10, 120)

Gui, %PM_gui%:Show, NoActivate, ProgressMeter Demo  ; NoActivate avoids deactivating the currently active window.
SetTimer, ShowMemoryUsage, 500
return

ShowMemoryUsage:
   DllCall("kernel32.dll\GlobalMemoryStatus", "uint",&memorystatus) ; this code is from the forum, i found it several times but donīt know who made it
   mem := *( &memorystatus + 4 ) ; last byte is enough, mem = 0..100
   Update_ProgressMeter(PM_gui, PM_ControlID, mem)

   IdleTime0 = %IdleTime%  ; Save previous values
   Tick0 = %Tick%
   DllCall("kernel32.dll\GetSystemTimes", "uint",&IdleTicks, "uint",0, "uint",0)
   IdleTime := *(&IdleTicks)
   Loop 7                  ; Ticks when Windows was idle
      IdleTime += *( &IdleTicks + A_Index ) << ( 8 * A_Index )
   Tick := A_TickCount     ; #Ticks all together
   load := 100 - 0.01*(IdleTime - IdleTime0)/(Tick - Tick0)
   Update_ProgressMeter(PM_GUI, PM_ControlID2, load)

return
   


;-----------------------------------------------------------------------------------------------------------------

;----------
; Add_ProgressMeter adds a "progress-meter" Control to a Gui.
; It can only be used on a Gui with a number (like Gui, 1: or Gui, 99:)but not on a unnumbered Gui.
; The generated control can disply the fluctuation of value in a range from 0 - 100.
; Usage : Add_ProgressMeter(PM_gui, PM_ControlID, PM_widthInSegments, PM_height, PM_color, PM_bgcolor, PM_xpos, PM_ypos)
; PM_gui =  the number of the Gui
; PM_ControlID = the name of the progress meter control. Use the same name with the "Update_ProgressMeter"-function
; PM_widthInSegments = the width of the control in segments. (Each segment is of 2 pixel width)
; PM_height = the height of the control in pixel
; PM_color = the color of the progress-meter
; PM_bgcolor = the background-color of the progress-meter
; PM_xpos = the X-position of the controls top-left corner
; PM_ypos = the Y-position of the controls top-left corner
; (if the X and Y position are both omited or set to 0, the control uses automatic positioning)
Add_ProgressMeter(PM_gui, PM_ControlID, PM_widthInSegments, PM_height, PM_color, PM_bgcolor, PM_xpos = 0, PM_ypos = 0)
{
   global
   PM_segmentspace = 2 ;this is the visible size of on segment in pixel
   PM_segmentsize := (PM_segmentspace + 1)
   PM_widthInSegments += -1
   %PM_ControlID%_Segments := PM_widthInSegments
   if (PM_xpos = 0 AND PM_ypos = 0)
   {
      Gui, %PM_gui%:Add, Progress, v%PM_ControlID%0 w%PM_segmentsize% h%PM_height% c%PM_color% Background%PM_bgcolor% Vertical,
   }
   else
   {
      Gui, %PM_gui%:Add, Progress, v%PM_ControlID%0 w%PM_segmentsize% h%PM_height% x%PM_xpos% y%PM_ypos% c%PM_color% Background%PM_bgcolor% Vertical,
   }
   
   Loop, %PM_widthInSegments%
   {
      Gui, %PM_gui%:Add, Progress, v%PM_ControlID%%A_Index% w%PM_segmentsize% h%PM_height% xp+%PM_segmentspace% c%PM_color% Background%PM_bgcolor% Vertical,
   }
}
;----------
; Update_ProgressMeter puts new contents in the progress-meter control created by Add_ProgressMeter.
; Usage: Update_ProgressMeter(PM_gui, PM_ControlID, PM_NewContent)
; PM_gui =  the number of the Gui the control is located in.
; PM_ControlID = the name of the progress meter control. Use the name that was used in the "Add_ProgressMeter"-function
; PM_NewContent = the new content of the control. it must be a number between 0 and 100.
; the new content will be displayed in the most-right segment.
Update_ProgressMeter(PM_gui, PM_ControlID, PM_NewContent = 0)
{
   PM_oldSegments := %PM_ControlID%_Segments
   Loop, %PM_oldSegments%
   {
      PM_NewSegment := A_Index - 1
      GuiControlGet, PM_Transfervar, %PM_gui%:, %PM_ControlID%%A_Index%
      GuiControl,%PM_gui%:, %PM_ControlID%%PM_NewSegment%, %PM_Transfervar%
   }
   
   GuiControl,%PM_gui%:, %PM_ControlID%%PM_oldSegments%, %PM_NewContent%
}
;----------


_________________

"Power can be given overnight, but responsibility must be taught. Long years go into its making."
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Laszlo



Joined: 14 Feb 2005
Posts: 4016
Location: Pittsburgh

PostPosted: Sun Feb 18, 2007 10:57 pm    Post subject: Reply with quote

Veovis wrote:
That is such a good idea!
Indeed! Thanks for sharing it!
Back to top
View user's profile Send private message
Jero3n



Joined: 19 Jan 2007
Posts: 151

PostPosted: Mon Feb 19, 2007 12:33 pm    Post subject: Reply with quote

Looks very nice!
Back to top
View user's profile Send private message
majkinetor



Joined: 24 May 2006
Posts: 3626
Location: Belgrade

PostPosted: Mon Feb 19, 2007 1:35 pm    Post subject: Reply with quote

screenshot ?
_________________
Back to top
View user's profile Send private message MSN Messenger
Zed Gecko



Joined: 23 Sep 2006
Posts: 98

PostPosted: Mon Feb 19, 2007 4:34 pm    Post subject: Reply with quote

Thanks for the cheering Wink
I was just playing around with the progress bars,
so iīm glad itīs usefull to someone.

And here is a screenshot:
Back to top
View user's profile Send private message
Zed Gecko



Joined: 23 Sep 2006
Posts: 98

PostPosted: Mon Feb 19, 2007 7:20 pm    Post subject: Reply with quote

and thanks to this post:
http://www.autohotkey.com/forum/viewtopic.php?t=8906
i made veovis example into a little Widget:

Code:

#SingleInstance force

PM_gui = 8
PM_ControlID = ram
PM_ControlID2 = proc
PM_widthInSegments = 60

VarSetCapacity( memorystatus, 100 )
VarSetCapacity(idleticks,18)

Gui, %PM_gui%: +ToolWindow ; +Owner avoids a taskbar button.
; Gui, 8:Color, black
Gui, 8:font, s8,
Gui, 8:Add, Text, x2 y4, CPU-load
Add_ProgressMeter(PM_gui, PM_ControlID2, PM_widthInSegments, 60, "red", "green", 2, 19)
Gui, 8:Add, Text, x2 y84, Memory-load
Add_ProgressMeter(PM_gui, PM_ControlID, PM_widthInSegments, 40, "red", "black", 2, 99)
Set_Parent_by_class("Progman", 8)
FormatTime, TimeString,, time
   Gui, %PM_gui%:Show, NoActivate W126 H141, %TimeString% ; NoActivate avoids deactivating the currently active window.

SetTimer, ShowMemoryUsage, 1000
return


ShowMemoryUsage:
   DllCall("kernel32.dll\GlobalMemoryStatus", "uint",&memorystatus) ; this code is from the forum, i found it several times but donīt know who made it
   mem := *( &memorystatus + 4 ) ; last byte is enough, mem = 0..100
   Update_ProgressMeter(PM_gui, PM_ControlID, mem)
   IdleTime0 = %IdleTime%  ; Save previous values
   Tick0 = %Tick%
   DllCall("kernel32.dll\GetSystemTimes", "uint",&IdleTicks, "uint",0, "uint",0)
   IdleTime := *(&IdleTicks)
   Loop 7                  ; Ticks when Windows was idle
      IdleTime += *( &IdleTicks + A_Index ) << ( 8 * A_Index )
   Tick := A_TickCount     ; #Ticks all together
   load := 100 - 0.01*(IdleTime - IdleTime0)/(Tick - Tick0)
   Update_ProgressMeter(PM_GUI, PM_ControlID2, load)
   FormatTime, TimeString,, time
   Gui, %PM_gui%:Show, NoActivate W126 H141, %TimeString%
return
   

Set_Parent_by_class(Window_Class, Gui_Number) ; class e.g. Shell_TrayWnd, gui number is e.g. 99
{
  Parent_Handle := DllCall( "FindWindowEx", "uint",0, "uint",0, "str", Window_Class, "uint",0)
  Gui, %Gui_Number%: +LastFound
  Return DllCall( "SetParent", "uint", WinExist(), "uint", Parent_Handle )
}

8GuiClose:
ExitApp

;-----------------------------------------------------------------------------------------------------------------

;----------
; Add_ProgressMeter adds a "progress-meter" Control to a Gui.
; It can only be used on a Gui with a number (like Gui, 1: or Gui, 99:)but not on a unnumbered Gui.
; The generated control can disply the fluctuation of value in a range from 0 - 100.
; Usage : Add_ProgressMeter(PM_gui, PM_ControlID, PM_widthInSegments, PM_height, PM_color, PM_bgcolor, PM_xpos, PM_ypos)
; PM_gui =  the number of the Gui
; PM_ControlID = the name of the progress meter control. Use the same name with the "Update_ProgressMeter"-function
; PM_widthInSegments = the width of the control in segments. (Each segment is of 2 pixel width)
; PM_height = the height of the control in pixel
; PM_color = the color of the progress-meter
; PM_bgcolor = the background-color of the progress-meter
; PM_xpos = the X-position of the controls top-left corner
; PM_ypos = the Y-position of the controls top-left corner
; (if the X and Y position are both omited or set to 0, the control uses automatic positioning)
Add_ProgressMeter(PM_gui, PM_ControlID, PM_widthInSegments, PM_height, PM_color, PM_bgcolor, PM_xpos = 0, PM_ypos = 0)
{
   global
   PM_segmentspace = 2 ;this is the visible size of on segment in pixel
   PM_segmentsize := (PM_segmentspace + 1)
   PM_widthInSegments += -1
   %PM_ControlID%_Segments := PM_widthInSegments
   if (PM_xpos = 0 AND PM_ypos = 0)
   {
      Gui, %PM_gui%:Add, Progress, v%PM_ControlID%0 w%PM_segmentsize% h%PM_height% c%PM_color% Background%PM_bgcolor% Vertical,
   }
   else
   {
      Gui, %PM_gui%:Add, Progress, v%PM_ControlID%0 w%PM_segmentsize% h%PM_height% x%PM_xpos% y%PM_ypos% c%PM_color% Background%PM_bgcolor% Vertical,
   }
   
   Loop, %PM_widthInSegments%
   {
      Gui, %PM_gui%:Add, Progress, v%PM_ControlID%%A_Index% w%PM_segmentsize% h%PM_height% xp+%PM_segmentspace% c%PM_color% Background%PM_bgcolor% Vertical,
   }
}
;----------
; Update_ProgressMeter puts new contents in the progress-meter control created by Add_ProgressMeter.
; Usage: Update_ProgressMeter(PM_gui, PM_ControlID, PM_NewContent)
; PM_gui =  the number of the Gui the control is located in.
; PM_ControlID = the name of the progress meter control. Use the name that was used in the "Add_ProgressMeter"-function
; PM_NewContent = the new content of the control. it must be a number between 0 and 100.
; the new content will be displayed in the most-right segment.
Update_ProgressMeter(PM_gui, PM_ControlID, PM_NewContent = 0)
{
   PM_oldSegments := %PM_ControlID%_Segments
   Loop, %PM_oldSegments%
   {
      PM_NewSegment := A_Index - 1
      GuiControlGet, PM_Transfervar, %PM_gui%:, %PM_ControlID%%A_Index%
      GuiControl,%PM_gui%:, %PM_ControlID%%PM_NewSegment%, %PM_Transfervar%
   }
   
   GuiControl,%PM_gui%:, %PM_ControlID%%PM_oldSegments%, %PM_NewContent%
}
;----------

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions 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