crashdemons Posted September 10, 2008 Share Posted September 10, 2008 (edited) I made this just for fun - just a simple little program.Not technically a toolbar, but it's a bar-like GUI with tools.It lists all of your drives excluding A: and B: (if a drive is added, it will be added to the GUI, if one is removed, the GUI is updated to reflect that as well.)-you can click the icon/label for each drive to open/close/remove that drive if applicable.On hover over the drive icon or drive letter:-Statistics on each drive (Capacity, Free, Used, Name, Type, etc.)On the portion that opens downward:color-coded graphical references of resources on each drive is listedNote: only the CPU meter moves "smoothly" but they all update at the same rate.Special Colors:-Gray - Error retrieving/Invalid values OR no media in driveStatistical Colors:-Yellow/Red - Used Resources-Green/Blue - Free Resourcesthe meter colors change based on the ratio of used:free in the meter(more yellow/green as free becomes greater more red/blue as used becomes greater)I feel this color-scheme is useful in getting attention when it is necessary.Dockable GUI:-Drag the GUI to the edge of the screen or to the top of the TaskBar to dock it.-beside the graphs on the left there is a 'D' button to toggle docking.UPDATES:Version 9: Various changes/additions (see post); Program now uses GDI+ instead of a Graphic controlVersion 8: Fixed an error in the window-docking code that crashed when Explorer/etc closes.Version 7: Added GUI Docking and Drive "DefaultIcon" setting supportVersion 6: PostedSource (v9):expandcollapse popup#NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_Language=1033 #AutoIt3Wrapper_Run_AU3Check=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** Global $Ver=9 Global $Dock_Distance=40 Global $Docking=True #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <ButtonConstants.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <GDIPlus.au3> Opt("GUIOnEventMode", 1) Global Const $WS_EX_COMPOSITED = 0x2000000 Global $IDLETIME, $KERNELTIME, $USERTIME Global $StartIdle, $StartKernel, $StartUser Global $EndIdle, $EndKernel, $EndUser $IDLETIME = DllStructCreate("dword;dword") $KERNELTIME = DllStructCreate("dword;dword") $USERTIME = DllStructCreate("dword;dword") Global $ShellDll = @SystemDir&"\shell32.dll" Global $Padding = 0 Global $Spacing = 1 Global $X = 0 + $Padding Global $Y = 0 + $Padding Global $W = 0 Global $H = 0 Global $Drives = DriveGetDrive("ALL") Global $Opening = False Global $GUIReady = False Global $HideGraphs = False; Global $CPUID Global $CPULA #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Drive Toolbar v"&$Ver, 633, 454, 193, 115, $WS_CAPTION + $WS_SYSMENU, BitOr($WS_EX_TOOLWINDOW,$WS_EX_TOPMOST));$WS_EX_COMPOSITED GUISetBkColor(0x000000) GUISetOnEvent(-3, 'Ext') Global $XI = $X + 20 Global $YI = $Y $H = $Y + $Padding + 35 + 32 Global $DDrives[1] $HideIt_Ctrl = GUICtrlCreateButton("/\", 0, 0, 20, 20) GUICtrlSetResizing(-1, 802) GUICtrlSetOnEvent(-1, '_hide_graphs') GUICtrlSetTip(-1,'Toggle Showing Graphs') $DockIt_Ctrl = GUICtrlCreateButton("D", 0, 20, 20, 20) GUICtrlSetColor(-1,0x007F00) GUICtrlSetResizing(-1, 802) GUICtrlSetOnEvent(-1,'_dock_check_toggle') GUICtrlSetTip(-1,'Toggle Docking Mode') $Graphic_Label=GUICtrlCreateLabel('GDI+ Object',20,20,633-20,454-20) GUICtrlSetResizing(-1, 2+32 + 4+64) GUICtrlSetBkColor(-1,0x000000) GUICtrlSetColor(-1,0x00FF00) GUICtrlSetTip(-1,'Resource Allocation Graph'&@CRLF&'(Hover over a drive letter or icon for information)') GUISetState(@SW_HIDE) #EndRegion ### END Koda GUI section ### _GDIPlus_Startup() _doublebuff_create($Form1,$Graphic_Label) Global $X_o = $X Global $XI_o = $XI Global $Y_o = $Y Global $YI_o = $YI Global $W_o = $W Global $H_o = $H _add_cpu() _update_drives() WinMove($Form1, '', 193, 115, $W, $H) _doublebuff_resize() $GUIReady = True $wgcs=WinGetClientSize($Form1) $WDiff=$W-$wgcs[0] $HDiff=$H-$wgcs[1] $wgcs=0 GUISetState(@SW_SHOW) _update_all(False) While 1 Global $_UpdateTimer Global $_UpdateTimer2 _dock_check_timed() If $Opening = False And TimerDiff($_UpdateTimer) > 1000 Then _update_all() _RedMem() $_UpdateTimer = TimerInit() EndIf _dock_check_timed() If $Opening = False And TimerDiff($_UpdateTimer2) > 2000 Then _update_drives() $_UpdateTimer2 = TimerInit() EndIf _dock_check_timed() Sleep(300) WEnd Func _dock_check_toggle() Switch $Docking Case True $Docking=False GUICtrlSetColor($DockIt_Ctrl,0xDD0000) Case False $Docking=True GUICtrlSetColor($DockIt_Ctrl,0x007F00) EndSwitch EndFunc Func _dock_check_timed() Global $Docking If $Docking=False Then Return 0 Global $_DockTimer,$GUIReady If $GUIReady And TimerDiff($_DockTimer)>250 Then _dock_check($Form1,$Dock_Distance) $_DockTimer=TimerInit() EndIf EndFunc Func _dock_check($hWnd,$D) Local $Coord,$tm,$Start,$X2,$Y2,$DockIt,$CR,$CB,$CS $Coord=WinGetPos($hWnd) If @error Then Dim $Coord[4]=[0,0,0,0] $tm=Opt('wintitlematchmode') Opt('wintitlematchmode', 4) $Start=WinGetPos('classname=Shell_TrayWnd') If @error Then Dim $Start[4]=[0,0,0,0] Opt('wintitlematchmode', $tm) $X2=$Coord[2]+$Coord[0]-1 $Y2=$Coord[3]+$Coord[1]-1 $DockIt=False If $Coord[0]<$D And $Coord[0]<>0 Then ConsoleWrite("Dock Left "&$Coord[0]&@CRLF) $DockIt=True $Coord[0]=0 EndIf If $Coord[1]<$D And $Coord[1]<>0 Then ConsoleWrite("Dock Top "&$Coord[1]&@CRLF) $DockIt=True $Coord[1]=0 EndIf $CR=Abs((@DesktopWidth-1)-$X2) $CB=Abs((@DesktopHeight-1)-$Y2) $CS=Abs($Start[1]-$Y2)-1 If ($CR<$D And $CR<>0) Or $X2>(@DesktopWidth-1) Then ConsoleWrite("Dock Right "&$CR&@CRLF) $DockIt=True $Coord[0]=@DesktopWidth-$Coord[2] EndIf If $CS<$D And $CS<>0 Then ConsoleWrite("Dock Start "&$CS&@CRLF) $DockIt=True $Coord[1]=($Start[1])-$Coord[3] EndIf If $D>20 Then $D=20 If ($CB<$D And $CB<>0) Or $Y2>(@DesktopHeight-1) Then ConsoleWrite("Dock Bottom "&$CB&@CRLF) $DockIt=True $Coord[1]=@DesktopHeight-$Coord[3] EndIf If $DockIt Then WinMove($hWnd,'',$Coord[0],$Coord[1]) EndFunc Func _Rem_Drive() _resize_begin() Global $Opening = True Global $DDrives Local $ControlData $X = UBound($DDrives) - 1 For $ii = 1 To $X GUICtrlDelete($DDrives[$ii]) $ControlData = Eval("DRIVE_DATA_" & $DDrives[$ii]) If IsArray($ControlData) Then GUICtrlDelete($ControlData[2]) GUICtrlDelete($ControlData[3]) Assign("DRIVE_DATA_" & $DDrives[$ii], False, 2) EndIf Next Local $tmp[1] $DDrives = $tmp Global $X = $X_o Global $XI = $XI_o+50 Global $Y = $Y_o Global $YI = $YI_o Global $W = $W_o Global $H = $H_o Global $GUIReady = False _update_drives() $GUIReady = True Local $tmp_H=$H If $HideGraphs Then $tmp_H =20+$HDiff WinMove($Form1, '', Default, Default, $W, $tmp_H) _resize_end() $Opening = False EndFunc ;==>_Rem_Drive Func _hide_graphs() Global $W, $H, $HideGraphs GUICtrlSetState($HideIt_Ctrl, 128) _resize_begin() Local $tmp=$H Switch $HideGraphs Case True GUICtrlSetData($HideIt_Ctrl, '/\') $HideGraphs = False Case False $tmp = 20+$HDiff GUICtrlSetData($HideIt_Ctrl, '\/') $HideGraphs = True EndSwitch WinMove($Form1, '', Default, Default, $W, $tmp) _resize_end() GUICtrlSetState($HideIt_Ctrl, 64) EndFunc ;==>_hide_graphs Func _update_drives() Local $Control, $ControlData $tmp = DriveGetDrive("ALL") If @error Then Return 0 For $i = 1 To $tmp[0] $X = UBound($DDrives) - 1 $found = False $dr = StringUpper($tmp[$i]) Switch $dr Case 'A:', 'B:' ContinueLoop EndSwitch For $ii = 1 To $X $ControlData = Eval("DRIVE_DATA_" & $DDrives[$ii]) If IsArray($ControlData) Then If $dr = $ControlData[0] Then $found = True ExitLoop EndIf EndIf Next If $found = False Then _add_drive($tmp[$i]) Next EndFunc ;==>_update_drives Func _add_cpu() Local $Control, $ControlData _resize_begin() Global $DDrives, $ShellDll, $W, $H, $X, $Y, $XI, $YI, $HideGraphs Global $CPUData[6]=[0,0,0,0,0,0] $CPUID = GUICtrlCreateButton('', $XI, $YI, 20, 20, $BS_ICON) GUICtrlSetImage(-1, $ShellDll, -16, 0) GUICtrlSetResizing(-1, 802) GUICtrlSetOnEvent(-1,"_update_cpu") $CPULA = GUICtrlCreateLabel('CPU', $XI + 20, $YI, 30, 20, $SS_CENTER) GUICtrlSetOnEvent(-1,"_update_cpu") GUICtrlSetColor(-1, 0x00DD00) GUICtrlSetBkColor(-1, 0x000000) GUICtrlSetResizing(-1, 802) GUICtrlSetResizing(-1, 802) $W = $XI + 50 + $Padding + 5 $XI += 50 + $Spacing If $GUIReady Then $wgp = WinGetPos($Form1) Local $tmp_H=$H If $HideGraphs Then $tmp_H =20+$HDiff WinMove($Form1, '', Default, Default, $W, $tmp_H) EndIf _resize_end() EndFunc ;==>_add_cpu Func _add_drive($Drive) _resize_begin() Local $Control, $ControlData Global $DDrives, $ShellDll, $W, $H, $X, $Y, $XI, $YI, $HideGraphs Local $ControlData[13] $Control = GUICtrlCreateButton('', $XI, $YI, 20, 20, $BS_ICON) _ArrayAdd($DDrives, $Control) $ControlData[0] = StringUpper($Drive) $ControlData[1] = 1 Local $Status = DriveStatus($ControlData[0] & '\') $type = DriveGetType($ControlData[0] & '\') If $Status = 'INVALID' Then Return 0 ;ConsoleWrite($ControlData[0]&' - '&$Drive&' - '&DriveStatus($ControlData[0] & '\')&' - '&DriveStatus($Drive&'\')&@CRLF) $IconData=DriveGetIcon($ControlData[0],$type,$Status) GUICtrlSetImage(-1, $IconData[0], $IconData[1], 0) GUICtrlSetResizing(-1, 802) GUICtrlSetOnEvent(-1, "_drive_evn") $ControlData[2] = GUICtrlCreateLabel($ControlData[0], $XI + 20, $YI, 30, 20, $SS_CENTER) GUICtrlSetOnEvent(-1, "_drive_evnx") GUICtrlSetColor(-1, 0x00DD00) GUICtrlSetBkColor(-1, 0x000000) GUICtrlSetResizing(-1, 802) $ControlData[3] = 0 ;deprecated element (used for the Graphics Control previous - unused when GDI+ replaced this) $ControlData[4] = '-1' $ControlData[5] = $XI $ControlData[6] = $YI + 20 Assign("DRIVE_DATA_" & $Control, $ControlData, 2) $W = $XI + 50 + $Padding + 5 $XI += 50 + $Spacing If $GUIReady Then Local $tmp_H=$H If $HideGraphs Then $tmp_H =20+$HDiff WinMove($Form1, '', Default, Default, $W, $tmp_H) EndIf $ControlData[7]=0 $ControlData[8]=0 $ControlData[9]=0 $ControlData[10]=0 $ControlData[11]=0 $ControlData[12]=0 _resize_end() EndFunc ;==>_add_drive Func _update_all($auto = True) If Not $HideGraphs Then _doublebuff_buffer_clear() _draw_cpu() EndIf $X = UBound($DDrives) - 1 For $i = 1 To $X _update_drive($DDrives[$i], $auto) Next _update_cpu() If Not $HideGraphs Then _doublebuff_buffer_draw() EndFunc ;==>_update_all Func _drive_evn($override = 0) Local $Control, $ControlData Global $Opening = True $Control = @GUI_CtrlId If IsDeclared('override') Then If $override > 0 Then $Control = $override EndIf GUICtrlSetState($Control, 128) $ControlData = Eval("DRIVE_DATA_" & $Control) If IsArray($ControlData) Then _ChangeClosed($ControlData) Assign("DRIVE_DATA_" & $Control, $ControlData, 2) EndIf GUICtrlSetState($Control, 64) $Opening = False EndFunc ;==>_drive_evn Func _drive_evnx() _drive_evn(@GUI_CtrlId - 1) EndFunc ;==>_drive_evnx Func _ChangeClosed(ByRef $ControlData) Local $Control GUICtrlSetData($ControlData[2], $ControlData[0] & ' ...') GUICtrlSetColor($ControlData[2], 0xFF7F00) If $ControlData[1] > 0 Then If StringLower(DriveGetType($ControlData[0]&'\'))='removable' Then $Action=0 Run("rundll32.exe shell32.dll,Control_RunDLL hotplug.dll", @SystemDir) Else $Action = CDTray($ControlData[0], "open") EndIf Else $Action = CDTray($ControlData[0], "close") EndIf If $Action Then If $ControlData[1] > 0 Then $ControlData[1] = 0 Else $ControlData[1] = 1 EndIf EndIf If $ControlData[1] > 0 Then GUICtrlSetData($ControlData[2], $ControlData[0]) GUICtrlSetColor($ControlData[2], 0x00DD00) Else GUICtrlSetData($ControlData[2], $ControlData[0] & ' ->') GUICtrlSetColor($ControlData[2], 0xDD0000) EndIf EndFunc ;==>_ChangeClosed Func _TimerProc() Global $EndIdle,$EndKernel,$EndUser,$StartIdle, $StartKernel, $StartUser _GetSysTime($EndIdle, $EndKernel, $EndUser) _CPUCalc() _GetSysTime($StartIdle, $StartKernel, $StartUser) EndFunc Func _CPUCalc() Local $iSystemTime, $iTotal, $iCalcIdle, $iCalcKernel, $iCalcUser Global $EndIdle,$EndKernel,$EndUser,$StartIdle, $StartKernel, $StartUser $iCalcIdle = ($EndIdle - $StartIdle) $iCalcKernel = ($EndKernel - $StartKernel) $iCalcUser = ($EndUser - $StartUser) $iSystemTime = ($iCalcKernel + $iCalcUser) $iTotal = Int(($iSystemTime - $iCalcIdle) * (100 / $iSystemTime)) If $iTotal<0 Or $iTotal>100 Then $Datax='BEEEEEP! - there was an error!'&@CRLF&@CRLF& _ 'StartIdle: '&$StartIdle&@CRLF& _ 'EndIdle: '&$EndIdle&@CRLF& _ 'StartKernel: '&$StartKernel&@CRLF& _ 'EndKernel: '&$EndKernel&@CRLF& _ 'StartUser: '&$StartUser&@CRLF& _ 'EndUser: '&$EndUser&@CRLF&@CRLF $Datax&='iCalcIdle: '&$iCalcIdle&@CRLF& _ 'iCalcKernel: '&$iCalcKernel&@CRLF& _ 'iCalcUser: '&$iCalcUser&@CRLF& _ 'iSystemTime: '&$iSystemTime&@CRLF& _ 'iTotal: '&$iTotal ConsoleWrite($Datax&@CRLF) Return 0 EndIf Global $NewCPU=$iTotal EndFunc ;==>_CPUCalc Func _update_cpu() Global $NewCPU,$LastCPU,$CPUData _TimerProc() If $NewCPU <> $LastCPU Then Local $Text='CPU Usage: ' & $NewCPU & '%' GUICtrlSetTip($CPUID, $Text) GUICtrlSetTip($CPULA, $Text) If $GUIReady And $HideGraphs = False Then Local $Dist=$NewCPU-$LastCPU Local $Dire=$Dist/Abs($Dist) Local $Delt=Round($Dist/5) If $Delt<1 And $Delt>0 Then $Delt=1*$Dire If $Delt<>0 Then For $Percent=$LastCPU To $NewCPU Step $Delt _UsagePie_GetInfo($Percent, 180, 180, $CPUData, 0) _draw_cpu() _doublebuff_buffer_draw() Sleep(100) Next EndIf _UsagePie_GetInfo($NewCPU, 180, 180, $CPUData, 0) _draw_cpu() _doublebuff_buffer_draw() EndIf $LastCPU=$NewCPU EndIf EndFunc ;==>_update_cpu Func _draw_cpu() If $HideGraphs Or (Not $GUIReady) Then Return _UsagePie_DrawBox($_DoubleBuff_gri,0,0,50) _UsagePie_DrawInfo($_DoubleBuff_gri, $CPUData, 0, 0, 0,50) EndFunc Func _GetSysTime(ByRef $sIdle, ByRef $sKernel, ByRef $sUser) Global $IDLETIME,$KERNELTIME,$USERTIME DllCall("kernel32.dll", "int", "GetSystemTimes", "ptr", DllStructGetPtr($IDLETIME), _ "ptr", DllStructGetPtr($KERNELTIME), _ "ptr", DllStructGetPtr($USERTIME)) $sIdle = DllStructGetData($IDLETIME, 1) $sKernel = DllStructGetData($KERNELTIME, 1) $sUser = DllStructGetData($USERTIME, 1) EndFunc ;==>_GetSysTime Func _update_drive($Control, $auto = False) Local $ControlData $ControlData = Eval("DRIVE_DATA_" & $Control) If IsArray($ControlData) = 0 Then Return 0 Switch $ControlData[0] Case 'A:', 'B:' Return 0 EndSwitch Local $DrivePath=$ControlData[0] & '\' $Status = StringUpper(DriveStatus($DrivePath)) $Total = 0 $Free = 0 $pr = 0 $GraphData = '' Switch $Status Case "NOTREADY", "UNKNOWN" $pr=-1 Case "INVALID" Return _Rem_Drive() $pr=-1 Case "READY" $Total = DriveSpaceTotal($DrivePath) $Free = DriveSpaceFree($DrivePath) $pr = Round(($Free/$Total)*100) Case Else ConsoleWrite("Unknown Drive Status: " & $Status & " (" & $ControlData[0] & ")" & @CRLF) $pr=-1 EndSwitch $GraphData = $Status & '|' &$Free&'|'&$Total&'|'&$pr If $ControlData[4] <> $GraphData Then $ControlData[4] = $GraphData If (Not $auto) OR ($HideGraphs = False) Then _UsagePie_GetInfo(100-$pr, 180, 180, $ControlData,7) EndIf $IconData=DriveGetIcon($ControlData[0],DriveGetType($DrivePath),$Status) GUICtrlSetImage($Control, $IconData[0], $IconData[1], 0) _tipx($Control, $ControlData, $Status, $Total, $Free, $pr) EndIf _UsagePie_DrawInfo($_DoubleBuff_gri,$ControlData, 7,$ControlData[5]-20,$ControlData[6]-20,50) Assign("DRIVE_DATA_" & $Control, $ControlData, 2) EndFunc ;==>_update_drive Func _tipx($Control, ByRef $ControlData, $state, $Total, $Free, $pr) If $pr<0 Then $pr=0 Local $DrivePath=$ControlData[0] & '\' Local $label=DriveGetLabel($DrivePath) Local $fs=DriveGetFileSystem($DrivePath) If StringRegExp($fs,'^[0-9]$') Then $fs='RAW' Local $serial=DriveGetSerial($DrivePath) If @error Then $serial='' Local $brk='------------------------------------------' Local $data='Drive ' & $DrivePath & ' Statistics' & @CRLF&@CRLF If StringLen($label )>0 Then $data&='Label: '&@TAB&$label&@CRLF $data&='State: '&@TAB&$state & @CRLF & $brk&@CRLF If StringLen($fs )>0 Then $data&='File System: '&@TAB&$fs&@CRLF If StringLen($serial)>0 Then $data&='Serial Number: '&@TAB&$serial&@CRLF&$brk& @CRLF $data&='Capacity: ' &@TAB& FileSizeDisplay($Total, 2, False, 3, "IEC", "IEC") & @CRLF & _ 'Free Space: '&@TAB & FileSizeDisplay($Free, 2, False, 3, "IEC", "IEC") & ' (' & $pr & '%)' & @CRLF & _ 'Used Space: '&@TAB & FileSizeDisplay($Total - $Free, 2, False, 3, "IEC", "IEC") & ' (' & (100 - $pr) & '%)' GUICtrlSetTip($Control, $data) GUICtrlSetTip($ControlData[2], $data) EndFunc ;==>_tipx Func FileSizeUnits($iBytes, $iu, $longname = True, $USet = "SI") ; This function determines the unit-names and pluralty for FileSizeDisplay() ; given the byte value, Unit #, long/short setting, and Unit Set ;Dim $USet, $longname Local $UnitSet = '' Local $sUnits = '' ;$iBytes=Int($iBytes) If $longname And $USet = "SI" Then $UnitSet = "Byte|Kilobyte|Megabyte|Gigabyte|Terabyte|Petabyte|Exabyte|Zettabyte|Yottabyte" If $longname And $USet = "IEC" Then $UnitSet = "Byte|Kibibyte|Mebibyte|Gibibyte|Tebibyte|Pebibyte|Exbibyte|Zebibyte|Yobibyte" If $longname = False And $USet = "SI" Then $UnitSet = "B|KB|MB|GB|TB|PB|EB|ZB|YB" If $longname = False And $USet = "IEC" Then $UnitSet = "B|KiB|MiB|GiB|TiB|PiB|EiB|ZiB|YiB" $UnitSet = StringSplit($UnitSet, "|") If $iu > ($UnitSet[0]) Then Return '' $sUnits = $UnitSet[$iu] If $longname And $iBytes <> 1 Then $sUnits &= 's' Return $sUnits EndFunc ;==>FileSizeUnits Func FileSizeDisplay($iBytes, $Round = 2, $longname = True, $Start = 1, $USet = "IEC", $iBase = "IEC", $forceUnits = -1) #cs This function displays a converts (?)byte value as you would have it seen in your program - It adds unit notations and normalizes the number ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Input Values iBytes = Number of (?)bytes to be converted/normalized Round = Number of decimal places to allow, set to -1 to allow all longname = Show unit names (True) or abbreviations (False) Start = Units of inputted iBytes value 1 - Bytes 2 - KiloB / KibiB 3 - MegaB / MebiB 4 - GigaB / GibiB 5 - TeraB / TebiB ... 9 - YottaB / YobiB USet = Unit Name Set - can be SI or IEC SI (decimal): byte, kilobyte... This is default because it is used the most - used oftenly (and incorrectly) with a base of 10 (iBase 1000) but in general, it can be either 10 or 16 IEC (binary): byte, kebibyte... These units were created to distinguish against the changeable value of SI units. - used always with a base of 16 (iBase 1024) - although this function will not force it. iBase = Unit Base Value - determines what value of bytes equals a kilobyte, etc. 1024 is the correct value Alternatively, you can use several strings as defaults: SI - 1000 IEC - 1024 This is default because it correctly portrays data size decimal - 1000 binary - 1024 forceUnits = Determines the forced units of the output, set to -1 or 0 to disable -refer to Start values- #ce ;Dim $Round, $longname, $USet, $iBase, $Start, $forceUnits Switch $iBase Case "SI" $iBase = 1000 Case "IEC" $iBase = 1024 Case "decimal" $iBase = 1000 Case "binary" $iBase = 1024 EndSwitch While $iBytes < 1 And $Start > 1 $iBytes *= $iBase $Start -= 1 WEnd Local $tmp, $sUnits Local $iu = $Start Local $riBytes = $iBytes Local $iud = 0 Switch $USet Case "decimal" $USet = "SI" Case "binary" $USet = "IEC" EndSwitch If $Round > -1 Then $riBytes = Round($iBytes, $Round) Else $riBytes = $iBytes EndIf $sUnits = FileSizeUnits($riBytes, $iu, $longname, $USet) If $forceUnits >= 1 Then $iud = Abs($Start - $forceUnits) Select Case $Start > $forceUnits $iBytes *= $iBase ^ $iud Case $Start < $forceUnits $iBytes /= $iBase ^ $iud Case $Start = $forceUnits Return $riBytes & ' ' & $sUnits EndSelect If $Round > -1 Then $riBytes = Round($iBytes, $Round) Else $riBytes = $iBytes EndIf $sUnits = FileSizeUnits($riBytes, $forceUnits, $longname, $USet) Return $riBytes & ' ' & $sUnits EndIf While $iBytes >= $iBase $iu += 1 $iBytes /= $iBase $tmp = $sUnits If $Round > -1 Then $riBytes = Round($iBytes, $Round) Else $riBytes = $iBytes EndIf $sUnits = FileSizeUnits($riBytes, $iu, $longname, $USet) If $sUnits = '' Then $iBytes *= $iBase $iu -= 1 If $Round > -1 Then $riBytes = Round($iBytes, $Round) Else $riBytes = $iBytes EndIf $sUnits = $tmp ExitLoop EndIf WEnd Return $riBytes & ' ' & $sUnits EndFunc ;==>FileSizeDisplay Func DriveGetIcon($Drive,$Type,$Status='READY') Local $sIconData='' Local $aIconData[2]=['',0] Local $fIcon=False Local $DrivePath=$Drive&'\' If StringLower($Status)='ready' Then Local $IconFile=IniRead($DrivePath&'AUTORUN.INF','autorun','icon','') If StringLen($IconFile)>0 Then $sIconData=$IconFile $fIcon=True EndIf EndIf If Not $fIcon Then $Reg_KeyName_DefaultIcon="HKCU\Applications\Explorer.exe\Drives\DriveIcons\"&StringLeft($Drive,1)&"\DefaultIcon" $Reg_DriveIcon=RegRead($Reg_KeyName_DefaultIcon,"") If @error=0 Then $sIconData=$Reg_DriveIcon $fIcon=True EndIf EndIf If Not $fIcon Then Local $iIconIdx Switch StringLower($Type) Case "removable" $iIconIdx = -8 Case "cdrom" $iIconIdx = -12 Case "fixed" $iIconIdx = -9 Case "ramdisk" $iIconIdx = -13 Case "network" $iIconIdx = -10 Case Else $iIconIdx = 0 ConsoleWrite("Unknown DriveType: " & $Type & " (" & $Drive & ")" & @CRLF) EndSwitch Switch StringUpper($Drive) Case 'A:', 'B:' $iIconIdx = -7 EndSwitch $sIconData=$ShellDll&','&$iIconIdx $fIcon=True EndIf If $fIcon Then $sIconData=StringSplit($sIconData&',0',',') $aIconData[0]=$sIconData[1] $aIconData[1]=$sIconData[2] $sIconData=0 If StringInStr($aIconData[0],':')=0 Then Local $fc=StringLeft($aIconData[0],1) If $fc='/' Or $fc='\' Then $aIconData[0]=StringTrimLeft($aIconData[0],1) $aIconData[0]=$DrivePath&$aIconData[0] EndIf $aIconData[1]=StringStripWS ($aIconData[1],8) ;ConsoleWrite('~DriveIcon: '&$aIconData[0]&'|'&$aIconData[1]&@CRLF) EndIf Return $aIconData EndFunc Func _resize_begin() Global $_UpdateTimer=0 EndFunc Func _resize_end() _doublebuff_resize() _doublebuff_buffer_clear() _update_all(False) EndFunc Func Ext() Exit EndFunc Func _UsagePie_GetInfo($iUsedPercent, $iStartAngle, $iMaxSweepAngle, ByRef $aInfo, $iStart=0) If $aInfo[$iStart+2]<>0 Then _GDIPlus_BrushDispose($aInfo[$iStart+2]) If $aInfo[$iStart+5]<>0 Then _GDIPlus_BrushDispose($aInfo[$iStart+5]) Local $iUsedColor,$iFreeColor Local $iAlphaSolid=0xFF000000 Switch $iUsedPercent Case 0 To 100 $iUsedPercent/=100 Local $grb,$blu $grn=Int((1-$iUsedPercent)*255) $blu=Int($iUsedPercent*255) $iUsedColor=0xFFFF0000+($grn*0x100) $iFreeColor=0xFF000000+($grn*0x100)+$blu Case Else $iUsedPercent=1 $iUsedColor=0xFF7F7F7F EndSwitch $aInfo[$iStart]=$iStartAngle $aInfo[$iStart+1]=Round($iMaxSweepAngle*$iUsedPercent) If $aInfo[$iStart+1]>0 Then $aInfo[$iStart+2]=_GDIPlus_BrushCreateSolid($iUsedColor) EndIf $aInfo[$iStart+3]=$iStartAngle+$aInfo[$iStart+1] $aInfo[$iStart+4]=$iMaxSweepAngle-$aInfo[$iStart+1] If $aInfo[$iStart+4]>0 Then $aInfo[$iStart+5]=_GDIPlus_BrushCreateSolid($iFreeColor) EndIf ;ConsoleWrite('-> Get Info'&@CRLF) EndFunc Func _UsagePie_DrawBox($Graphics, $x, $y, $w, $h=Default,$hBrush=0) ; this is only so we can redraw the chart area without clearing the entire graphic if $h=Default Then $h=$w _GDIPlus_GraphicsFillRect($Graphics,$x,$y,$w,$h,$hBrush) ;ConsoleWrite('-> Draw box'&@CRLF) EndFunc Func _UsagePie_DrawInfo($Graphics, ByRef $aInfo, $iStart=0, $x=0, $y=0, $w=50, $h=Default) if $h=Default Then $h=$w If $aInfo[$iStart+1]>0 Then _GDIPlus_GraphicsFillPie($Graphics,$x,$y,$w,$h,$aInfo[$iStart ], $aInfo[$iStart+1],$aInfo[$iStart+2]) If $aInfo[$iStart+4]>0 Then _GDIPlus_GraphicsFillPie($Graphics,$x,$y,$w,$h,$aInfo[$iStart+3], $aInfo[$iStart+4],$aInfo[$iStart+5]) ;ConsoleWrite('-> Draw info '&$x&','&$y&@CRLF) EndFunc Func _doublebuff_create($hWnd,$iControl) Global $_DoubleBuff_hWnd, $_DoubleBuff_gro, $_DoubleBuff_grb, $_DoubleBuff_gri Global $_DoubleBuff_Coord[2]=[0,0] $_DoubleBuff_hWnd=ControlGetHandle($hWnd,'',$iControl) ;ConsoleWrite('+> CREATE '&$_DoubleBuff_hWnd&@CRLF) _doublebuff_resize() EndFunc Func _doublebuff_resize($BufferRedraw=True) _doublebuff_destroy() Global $_DoubleBuff_hWnd, $_DoubleBuff_gro, $_DoubleBuff_grb, $_DoubleBuff_gri Global $_DoubleBuff_Coord[2]=[0,0] Local $wgp=WinGetPos($_DoubleBuff_hWnd) $_DoubleBuff_Coord[0]=$wgp[2] $_DoubleBuff_Coord[1]=$wgp[3] $wgp=0 $_DoubleBuff_gro=_GDIPlus_GraphicsCreateFromHWND($_DoubleBuff_hWnd) $_DoubleBuff_grb=_GDIPlus_BitmapCreateFromGraphics($_DoubleBuff_Coord[0], $_DoubleBuff_Coord[1], $_DoubleBuff_gro) $_DoubleBuff_gri=_GDIPlus_ImageGetGraphicsContext($_DoubleBuff_grb) If $BufferRedraw Then _doublebuff_buffer_draw() ;ConsoleWrite('>> RESIZE '&$_DoubleBuff_hWnd&' '&$_DoubleBuff_Coord[0]&'x'&$_DoubleBuff_Coord[1]&@CRLF) EndFunc Func _doublebuff_destroy() Global $_DoubleBuff_gro, $_DoubleBuff_grb, $_DoubleBuff_gri Global $_DoubleBuff_Coord=0 If $_DoubleBuff_gri<>0 Then _GDIPlus_GraphicsDispose($_DoubleBuff_gri) If $_DoubleBuff_grb<>0 Then _GDIPlus_BitmapDispose($_DoubleBuff_grb) If $_DoubleBuff_gro<>0 Then _GDIPlus_GraphicsDispose($_DoubleBuff_gro) ;ConsoleWrite('!> DESTROY '&@CRLF) EndFunc Func _doublebuff_buffer_clear($iColor=0xFF000000) Global $_DoubleBuff_gro _GDIPlus_GraphicsClear($_DoubleBuff_gri,$iColor) ;ConsoleWrite('!> CLEAR '&@CRLF) EndFunc Func _doublebuff_buffer_draw($x=0,$y=0,$w=Default,$h=Default) Global $_DoubleBuff_gro, $_DoubleBuff_grb, $_DoubleBuff_Coord If $w=Default Then $w=$_DoubleBuff_Coord[0] If $h=Default Then $h=$_DoubleBuff_Coord[1] _GDIPlus_GraphicsDrawImageRect ($_DoubleBuff_gro, $_DoubleBuff_grb, $x, $y, $w, $h) ;ConsoleWrite('+> DRAW '&$w&'x'&$h&@CRLF) EndFunc ; Reduce memory - written by wOuter Func _RedMem($i_PID = -1) If $i_PID <> -1 Then Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1F0FFF, 'int', False, 'int', $i_PID) Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0]) DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0]) Else Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1) EndIf Return $ai_Return[0] EndFuncCredits:Rasim - _CPUCalc functions from his CPU Usage example without WMIw0uter - _ReduceMemory5-5-13 Edit: Screenshot re-added. Edited May 6, 2013 by crashdemons My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.) Link to comment Share on other sites More sharing options...
rasim Posted September 10, 2008 Share Posted September 10, 2008 Nice! Also you can add a "sticky" feature for docking a window to screen edges for improving the exterior Link to comment Share on other sites More sharing options...
crashdemons Posted September 10, 2008 Author Share Posted September 10, 2008 Glad you liked it - I'll try to find some way to do docking in v7 My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.) Link to comment Share on other sites More sharing options...
crashdemons Posted September 11, 2008 Author Share Posted September 11, 2008 (edited) ... feature for docking a window to screen edges ...- And so it shall be. UPDATE 7: Added Screen-Border/Taskbar Docking, disable-able via a button to the left of the graphical CPU Meter. Added checking for preset icons for drives Note: this value is read from: HKCU\Applications\Explorer.exe\Drives\DriveIcons\{DriveLetter}\DefaultIcon Example: CloneCD sets a Sheep icon here for it's virtual drives. Edited September 11, 2008 by crashdemons My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.) Link to comment Share on other sites More sharing options...
crashdemons Posted September 12, 2008 Author Share Posted September 12, 2008 I'm guessing that this doesn't look too appealing to the forum since I only got one reply and 170*-some views. Does anyone have any suggestions for this? (I, not being very creative unless ideas accidentally occur at the same time and sound cool ) My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.) Link to comment Share on other sites More sharing options...
Merovingian Posted September 12, 2008 Share Posted September 12, 2008 I'm guessing that this doesn't look too appealing to the forum since I only got one reply and 170*-some views.Does anyone have any suggestions for this?(I, not being very creative unless ideas accidentally occur at the same time and sound cool )How about interfacing it with a USB menu tool with kewl features like a USB search, eject, nested groupable menu's with icons, a menu organizer similar to FireFox's bookmark organizer, a USB tool kit along with a skinnable interface Jazz it up man >_< I think this Drive tool would do well with something like this. I love USB Flash Drive Tool suites. Meanwhiles I'll use this as part of my usual assortment of USB Drive toys *Grinz* 01000001 01110101 01110100 01101111 01001001 01110100 00100000An immortal object must be copied, so that we get a mortal copy of it, since we try not to destroy immortal objects. Link to comment Share on other sites More sharing options...
crashdemons Posted June 19, 2009 Author Share Posted June 19, 2009 (edited) Updated: Version 8 I was made aware of an issue in the window-docking code that caused the program to crash. Originally, if the Start Menu/Tray window was closed during the _dock_check function, WinGetPos would fail and my script would also fail to check for errors - causing it to crash when the result was not an array. I have edited the code to avoid crashing in this particular instance. If I was smart I'd redo the pie-graphs in GDI+ functions. Edited June 19, 2009 by crashdemons My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.) Link to comment Share on other sites More sharing options...
crashdemons Posted June 22, 2009 Author Share Posted June 22, 2009 (edited) [sS]Update 9:+ All drawings are now done via GDI+, but otherwise look exactly the same.+ Leftover drawings (pixels) are now not seen on the edge of the graphs anymore.+ The window dimensions are now set more correctly; that is, changing the window size didn't originally produce - -the same client size for everyone; so instead of it being easy, some extra work had to be done.+ The drive's Autorun.inf for will now also be checked for icon settings (CD's/USB/etc.) - - which should display a more accurate icon.+ Drive icons are now updated when drive changes occur - they should update at times when the icon could change.+ The drive Serial Number and File System are now shown in the drive-letter tooltip. (when available)+ The information in the drive-letter tooltips is now a little cleaner and better organized. Edited June 22, 2009 by crashdemons My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now