cool400 Posted July 12, 2005 Posted July 12, 2005 Hello folks,I'm using the following script to recognize my fixed drives and display them in a window with a variable height (depending on the number of drives found):#include <GUIConstants.au3>HotKeySet( "{ESC}", "gotoExit" )AutoItSetOption("WinTitleMatchMode", 4)AutoItSetOption ( "RunErrorsFatal", 0 ) AutoItSetOption ( "TrayIconHide", 1 )Opt("GuiOnEventMode", 1)Opt("GUICoordMode",1)Global $FS = 9 ;;Font size 9Global $B = 800 ;;Bold Text ;;Get System memory infoGlobal $memget = MemGetStats();;Get System RAM & round it down to more human friendly format Global $SysRam = Round($memget[1]/ 1024);;check for setpagefile.exe - not much point in running this GUI if setpagefile.exe isnt on the CD If NOT FileExists( "setpagefile.exe" ) Then MsgBox(16, "SetPageFile.exe nicht gefunden!", "Stellen Sie sicher, dass SetPageFile.exe existiert.", 20000) ExitEndIfIf WinExists ( "%_SetPageFileGUI_%" ) Then ExitEndIfAutoItWinSetTitle ( "%_SetPageFileGUI_%" )$title = "Erstelle Pagefile(s)"$GUIHandle = WinGetHandle ( "Erstelle Pagefile(s)" );;count the available fixed-drives for a variable height of the GUI$yDrives = DriveGetDrive( "FIXED" )For $nDrv = 1 to $yDrives [0]Next$yheight = ($nDrv * 20) + 170GuiCreate($title, 250, $yheight, 0, 0, $WS_CAPTION) ;;create window, you can change the 0, 0 part to orientate the window on screen;;I set it to be top left, so those who may not start with 1024x768 will see it without hiding the XPE progress which setting ;;center will doGUISetFont ($FS, 400) ;;Set general window font$progressbar1 = GuiCtrlCreateProgress(10, 30, 230, 20,$PBS_SMOOTH)$Label_1 = GuiCtrlCreateLabel("Status:", 10, 10, 40, 15)$Label_2 = GuiCtrlCreateLabel("fertig", 50, 10, 140, 15)$Label_3 = GuiCtrlCreateLabel("Laufwerke auswählen:", 10, 60, 150, 15)$Label_3a = GuiCtrlCreateLabel("freier Platz", 162, 60, 75, 15, 0x2)$Label_4 = GuiCtrlCreateLabel("Erstelle Pagefile mit:", 10, $yheight-65, 100, 15)$Label_5 = GuiCtrlCreateLabel("MB", 220, $yheight-65, 15, 15)$Combo_5 = GuiCtrlCreateCombo("", 155, $yheight-70, 60, 20)GUICtrlSetData($Combo_5,"128|256|384|512|768|1024","512") ;;Pagefile sizes - feel free to add/remove your own values;; The ,"128" part sets the default value displayed, feel free to change this tooGUICtrlSetFont ($Combo_5, $FS, $GuiSetState()$drive_letters = DriveGetDrive("FIXED") ;;Get all FIXED drives recognised by the system$s = 0;; Just a simple progress bar control to show scanning of fixed drives$msg = GUIGetMsg() For $i = $s To 100 step 1 $s = 0 GUICtrlSetData ($progressbar1,$i) ;;update the progress bar GUICtrlSetData ($Label_2,"Suche Laufwerke") ;;Show message in status area while scanningNext ;;check that at least one fixed drive is found, if not (that would be weird), display message in status area and then exit $aDrives = DriveGetDrive( "FIXED" ) For $nDrv = 1 to $aDrives [0] If $nDrv = 0 Then GUICtrlSetData ($Label_2, "keine Laufwerke gefunden") Sleep (2000) MsgBox(16, "Keine Laufwerke gefunden!", "Es kann kein Pagefile erstellt werden." & @CR & "Die Anwendung wird jetzt beendet.", 20000) Exit Else If $nDrv = NOT 0 Then GUICtrlSetData ($Label_2, "Laufwerke gefunden") ;;report drives found EndIf EndIf Next;;this took me ages to figure out, checkboxes and arrays are not fun ;;the long $chkboxes[$i]= line had me pulling my hair out for a good hour getting ;;the syntax right, but well worth it in the end!dim $chkboxes[$drive_letters[0]+ 1]$chkboxes[0] = $drive_letters[0]$Ypos = 80for $i = 1 to $drive_letters[0] $chkboxes[$i] = GuiCtrlCreateCheckbox(StringUpper($drive_letters[$i] & " " & "(" &DriveGetLabel( $drive_letters[$i] ) & ")"), 10, $Ypos, 140, 20) GuiCtrlSetState(-1, $GUI_UNCHECKED) $Ypos = $Ypos + 20next$Ypos = 80for $i = 1 to $drive_letters[0] $FreeMem = GuiCtrlCreateLabel(Round(DriveSpaceFree( $drive_letters[$i] )) & " MB", 162, $Ypos, 75, 15, 0x2) GuiCtrlSetFont ($FreeMem, $FS, $ $Ypos = $Ypos + 20next$SysRam_1 = GuiCtrlCreateLabel("System-RAM:", 10, $yheight-95, 85, 15)$SysRam_2 = GuiCtrlCreateLabel($SysRam & " MB", 162, $yheight-95, 75, 15, 0x2)GUICtrlSetFont ($SysRam_2, $FS, $$Button_GO = GuiCtrlCreateButton("OK", 10, $yheight-35, 80, 25)GUICtrlSetOnEvent(-1, "SetPage")$Button_EXIT = GuiCtrlCreateButton("Abbrechen", 160, $yheight-35, 80, 25)GUICtrlSetOnEvent(-1, "gotoExit")While 1 $msg = GUIGetMsg()WEndExitFunc GOPressed() AdlibEnable( "SetPage", 1 )EndFuncFunc EXITPressed() AdlibEnable( "gotoExit", 1 )EndFunc;;finally the main function!;check which checkbox(es) are checked and set a pagefile on it/themFunc SetPage() For $i = 1 to $chkboxes[0] if GUICtrlRead ($chkboxes[$i]) = $GUI_CHECKED then GUICtrlSetData ($Label_2, "Erstelle PageFile auf " & StringUpper( $drive_letters[$i] )) RunWait ( 'setpagefile.exe ' & $drive_letters[$i] & "\pagefile.sys" & " " & GUICtrlRead($Combo_5), "", @SW_HIDE) EndIf Next ExitEndFuncFunc gotoExit() ExitEndFuncI don't know very much about AutoIt, I just modified this script - which I hadn't build myself - a little bit.What I found out is that the functions "DriveGetLabel" and "DriveSpaceFree" are used for getting my desired information.Now I like to know if it's possible to count the letters and digits of the drivenames and the free space?What I need then is to get the highest number of letters and the highest number of digits, add them and get a variable width for my window.My other question is if it's possible to count the number of fixed-drives found without using the for/next-loop (like I did in the above script)?You think this sounds a bit complicated? For me it sounds totally impossible Thanks for any helpcool400
Moderators SmOke_N Posted July 12, 2005 Moderators Posted July 12, 2005 Check out all the "String" options in the help file, and in the forum. Good Luck!! Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
buzz44 Posted July 12, 2005 Posted July 12, 2005 (edited) $yDrives[0] and $drive_letters[0] contain the number of fixed-drives.Now I like to know if it's possible to count the letters and digits of the drivenames and the free space?What I need then is to get the highest number of letters and the highest number of digits, add them and get a variable width for my window.Do you mean like a total of all the drives? What do you mean by the highest numer of letter's? Edited July 12, 2005 by Burrup qq
JSThePatriot Posted July 12, 2005 Posted July 12, 2005 He means he wants to know the highest string length. So he can set his window to be a variable width. Check the String*() functions. I do believe this to be possible. I dont know how to do it myself, but I am interested to see how you do it. I know someone at some point came up with a way to make a window based on the buttons and such. I dont remember nor have I been able to find that in the Scripts and Scraps forum. Let me know how this turns out for you, JS AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)
buzz44 Posted July 12, 2005 Posted July 12, 2005 (edited) My mistake, typo in my post, I was supposed to say "letter" not digit. It has been corrected. Edited July 12, 2005 by Burrup qq
cool400 Posted July 13, 2005 Author Posted July 13, 2005 (edited) @all Thanks for your help - finally I found StringLen to count the number of letters of my drive-names! This is my code: ;;get the longest disk-name and biggest disk-size for a variable width of the GUI $xDrives = DriveGetDrive( "FIXED" ) dim $len[$xDrives[0] + 1] dim $wid[$xDrives[0] + 1] for $xDrv = 1 to $xDrives[0] $len[$xDrv] = StringLen(DriveGetLabel( $xDrives[$xDrv] )) if $len[$xDrv]>$len[$xDrv-1] then $maxlen=$len[$xDrv] endif $wid[$xDrv] = StringLen(Round(DriveSpaceFree( $xDrives[$xDrv] ))) if $wid[$xDrv]>$wid[$xDrv-1] then $maxwid=$wid[$xDrv] endif next Any code-optimization is really much appreciated Best regards cool400 Edited July 13, 2005 by cool400
cool400 Posted July 14, 2005 Author Posted July 14, 2005 Hmmm...now I've got another problem: depending on my code I've now got two variables with the number of letters/digits with the highest width. For a variable width of my GUI I need to convert this value into a pixel-size - and there lies the problem: IMHO the pixel-size of every char varies E.g. an "i" needs less pixel than a "w"... The thing is that I have the drive-names with a leading checkbox left-aligned (with a variable width of the name-field!) and the drive-spaces right-aligned. So if I choose a width for the drive-names that is too high, the drive-space beneath it gets deleted when moving the mouse over the checkbox. I thought about calculating with an average value for a char of 8 pixel, but it seems that this a not a good solution. Even with short drive-names it's too less sometimes... Any help would be really much appreciated! Best regards and thanks a lot cool400
LxP Posted July 14, 2005 Posted July 14, 2005 If no one responds with a way of getting this done then you could resort to using a monospace font for this information.
cool400 Posted July 14, 2005 Author Posted July 14, 2005 Yes, this would be a solution - could you please explain how to use such a font? Best regards cool400
LxP Posted July 14, 2005 Posted July 14, 2005 (edited) Check out the GUICtrlSetFont() command in the help file's index. According to the Splash... Fonts topic in the appendix, Courier, its derivatives and Lucida Console are all safe fonts to use for this task as they are all included on every OS (almost -- Win95 lacks Lucida Console). Edited July 14, 2005 by LxP
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