Jump to content

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

A useful GUI example using AU3GUI program


  • Please log in to reply
5 replies to this topic
MikeG
  • Members
  • 34 posts
  • Last active: Jul 17 2011 05:13 AM
  • Joined: 23 Apr 2004
This script provides a GUI interface to "Defragment all drives". As well as being useful in it's own right, I thought it might be helpful for others who'd like to do some GUI scripting.

Checkboxes for drives and options are added dynamically depending on your hardware and OS. The entire GUI is automatically sized to fit everything neatly. I'm quite proud of this ;-)

Note: You'll need AHK 1.0.10+ for the DriveGet command (Thanks!) and also AU3GUI.exe (I suggest you just put it in C:\Windows)

; Determine drives with free space and defragment them
; This script requires AU3GUI.exe (NOT AU3GUIXP.exe)

#NoTrayIcon
SetBatchLines,-1
StringTrimRight,title,A_ScriptName,4

; Basic parameters for the GUI; Height & focus set later
EnvSet,GUI.title,%title%
EnvSet,GUI.x,-1
EnvSet,GUI.y,-1
EnvSet,GUI.w,300
EnvSet,GUI.icon,defrag.ico
EnvSet,GUI.action,1
EnvSet,GUI.file,%temp%\au3gui.ini

; Now add GUI objects as needed
n=0    ; GUI object number
y=5    ; position of object
yg=%y% ; position of group
hg=25  ; height of empty group

; Get list of drives, remove floppies (prevent slow & noisy attempt to read empty drive)
DriveGet,list,list
StringReplace,list,list,A,
StringReplace,list,list,B,

; Add a checkbox for each drive with free space and save drives list
Loop,Parse,list
{
  DriveSpaceFree,free,%A_LoopField%:\
  If free > 0
  {
    GoSub,AddDriveCheckBox
    SetEnv,drives,%drives%%A_LoopField%
  }
}

; Put a group box around drive checkboxes
n++
EnvSet,OBJ%n%.type,group
EnvSet,OBJ%n%.x,10
EnvSet,OBJ%n%.y,%yg%
EnvSet,OBJ%n%.w,280
EnvSet,OBJ%n%.h,%hg%
EnvSet,OBJ%n%.text,Drives to defragment

; Option checkboxes
EnvAdd,y,30
yg=%y% ; position of group
hg=25  ; height of empty group

; Option to scan drives for errors first (win98 only)
IfEqual,A_OSVersion,WIN_98
{
  n++
  n_scan=%n%
  EnvAdd,y,20
  EnvAdd,hg,20
  EnvSet,OBJ%n%.type,checkbox
  EnvSet,OBJ%n%.x,20
  EnvSet,OBJ%n%.y,%y%
  EnvSet,OBJ%n%.text,Check drives for errors first
  EnvSet,OBJ%n%.selected,1
  EnvSet,OBJ%n%.tooltip,Use scandisk or chkdsk to check each drive for errors before trying to defragment it

; Option for full or quick defragment (Win98 only)
  n++
  n_full=%n%
  EnvAdd,y,20
  EnvAdd,hg,20
  EnvSet,OBJ%n%.type,checkbox
  EnvSet,OBJ%n%.x,20
  EnvSet,OBJ%n%.y,%y%
  EnvSet,OBJ%n%.text,Full defragment (including free space)
  EnvSet,OBJ%n%.selected,1
  EnvSet,OBJ%n%.tooltip,Defragments files and free space, but can take much longer
}

; Option to run minimized
n++
n_min=%n%
EnvAdd,y,20
EnvAdd,hg,20
EnvSet,OBJ%n%.type,checkbox
EnvSet,OBJ%n%.x,20
EnvSet,OBJ%n%.y,%y%
EnvSet,OBJ%n%.text,Run defragment minimized
EnvSet,OBJ%n%.selected,1
EnvSet,OBJ%n%.tooltip,Run programs minimized so you can continue working without interruption

; Option to shut down when finished
n++
n_shut=%n%
EnvAdd,y,20
EnvAdd,hg,20
EnvSet,OBJ%n%.type,checkbox
EnvSet,OBJ%n%.x,20
EnvSet,OBJ%n%.y,%y%
EnvSet,OBJ%n%.text,Shut down the computer when done
EnvSet,OBJ%n%.selected,0
EnvSet,OBJ%n%.tooltip,Shut down the computer when defragmentation is finished

; Put a group box around option checkboxes
n++
EnvSet,OBJ%n%.type,group
EnvSet,OBJ%n%.x,10
EnvSet,OBJ%n%.y,%yg%
EnvSet,OBJ%n%.w,280
EnvSet,OBJ%n%.h,%hg%
EnvSet,OBJ%n%.text,Options

; Buttons for start or cancel
n++
EnvAdd,y,40
EnvSet,OBJ%n%.type,button
EnvSet,OBJ%n%.x,50
EnvSet,OBJ%n%.y,%y%
EnvSet,OBJ%n%.w,60
EnvSet,OBJ%n%.h,-1
EnvSet,OBJ%n%.text,Start
EnvSet,OBJ%n%.submit,1
EnvSet,OBJ%n%.close,1
EnvSet,GUI.focus,%n% ; Start button has focus

n++
EnvSet,OBJ%n%.type,button
EnvSet,OBJ%n%.x,190
EnvSet,OBJ%n%.y,%y%
EnvSet,OBJ%n%.w,60
EnvSet,OBJ%n%.h,-1
EnvSet,OBJ%n%.text,Cancel
EnvSet,OBJ%n%.cancel,1

EnvAdd,y,30
EnvSet,GUI.h,%y% ; height of GUI to contain displayed objects neatly

; Display the GUI
FileDelete,%temp%\au3gui.ini
RunWait,au3gui

; Read and process the responses
IniRead,Status,%temp%\au3gui.ini,GUI,GUI
IfNotEqual,Status,SUBMIT,Exit ; User cancelled
IniRead,scan,%temp%\au3gui.ini,GUI,OBJ%n_scan%
IniRead,full,%temp%\au3gui.ini,GUI,OBJ%n_full%
IniRead,min, %temp%\au3gui.ini,GUI,OBJ%n_min%
IniRead,shut,%temp%\au3gui.ini,GUI,OBJ%n_shut%
Loop,Parse,drives
{
  IniRead,drive,%temp%\au3gui.ini,GUI,OBJ%A_Index%
  IfEqual,drive,checked,GoSub,Defragment
}

; All done!
FileDelete,%temp%\au3gui.ini
IfEqual,shut,checked,Shutdown 9
Exit

;*******************************************************************************
; Add a checkbox for a drive
;*******************************************************************************
AddDriveCheckBox:
  n++
  EnvAdd,y,20
  EnvAdd,hg,20
  EnvSet,OBJ%n%.type,checkbox
  EnvSet,OBJ%n%.x,20
  EnvSet,OBJ%n%.y,%y%
  ; Get the drive volume label (thanks to new function!)
  DriveGet,label,label,%A_LoopField%:
  StringLower,label,label,T
  EnvSet,OBJ%n%.text,%label% (%A_LoopField%:) - %free%MB free
  ; Select only fixed drives by default (some removable drives can be defragmented)
  DriveGet,type,type,%A_LoopField%:
  IfEqual,type,fixed,EnvSet,OBJ%n%.selected,1
Return

;*******************************************************************************
; Defragment a drive
;*******************************************************************************
Defragment:
  IfEqual,min,checked,SetEnv,runopt,min ; Minimize
  IfEqual,A_OSVersion,WIN_98
  {
    IfEqual,full,checked
      SetEnv,option,/f
    Else
      SetEnv,option,/u
    IfEqual,scan,checked,RunWait,%windir%\scandskw.exe %A_LoopField%: /noninteractive /silent,,%runopt%
    RunWait,%windir%\defrag.exe %A_LoopField%: /noprompt %option%,,%runopt%
  }
  Else
    RunWait,defrag.exe %A_LoopField%: -v -f,,%runopt%
Return


Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Wow, that's a very professional looking interface. If I didn't know better I'd think this was something that came bundled with Windows :)

Btw, does anyone have a direct download link that can be relied on to get the latest version of AU3GUI.exe?

Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004
unless Larry confirms otherwise, these should be latest:

http://www.hiddensof... ... au3gui.zip
http://www.hiddensof... ... 3guixp.zip

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat


Larrydalooza
  • Guests
  • Last active:
  • Joined: --
cunphirmed

Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004
Larry,
I've always been benefitted by your stuff, the au2 debugger, the GUI, the key recorder... thanx!

just one question... where do u announce when u make something nice?... its just by chance that i saw that u've made a key recorder for au3 as well!

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat


Larry
  • Guests
  • Last active:
  • Joined: --
I'm just a whim coder. Like I may create a DLL interface utiltiy like used like...

DLL.exe user32 MessageBox NULL "text" "title" 4096

but it will need to return info and use some sort of pointers to return certain data... ewwww I am thinking too much... that's not good. that always scares me away from starting.