J03Z Posted March 20, 2010 Posted March 20, 2010 Hey Team, I am in need of a little direction with this new script idea I have begun to work on so that I can gain better understanding of this language. I am fully aware that this program may have been created several times but I am unable to find any useful post based on my searches. 1.The Idea of the program is to give the user the ability to select the programs they would like to startup when windows load. 2.Give the user the ability to save the current window cordinates to an .ini file or such. 3.Save settings. When the user restarts the computer, it automaticaly loads all programs selected and position them based on information selected by user. I have coded majority of the buttons exluding the "Save Pos"(need a method for saving positions of the progams selected). I have browsed the help file, and found some interesting functions but need alittle more assistance. Any help will be greatly appreciated. Below is the code for what I have completed so far. expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <file.au3> Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form=j:\autoit\projects\work space automator\workspaceautomator2.kxf $Main = GUICreate("Work Space Automator v1.0", 519, 190, 254, 340) GUISetOnEvent($GUI_Event_Close, "_Exit") $men_File = GUICtrlCreateMenu("&File") $men_Save = GUICtrlCreateMenuItem("Save Settings", $men_File) GUICtrlSetOnEvent(-1, "_Save") $men_Exit = GUICtrlCreateMenuItem("Exit", $men_File) GUICtrlSetOnEvent(-1, "_Exit") $prg_List = GUICtrlCreateList("", 110, 20, 376, 110) GUICtrlSetData(-1, "") $inf_Label = GUICtrlCreateLabel("Programs set to load on startup", 208, 2, 150, 17) $btn_Add = GUICtrlCreateButton("Add", 10, 47, 90, 25, $WS_GROUP) GUICtrlSetOnEvent(-1, "_Add") $btn_Delete = GUICtrlCreateButton("Delete", 10, 74, 90, 25, $WS_GROUP) GUICtrlSetOnEvent(-1, "_Delete") $btn_Pos = GUICtrlCreateButton("Save Positions", 10, 102, 90, 26, $WS_GROUP) GUICtrlSetOnEvent(-1, "_POS") $win_Size = GUICtrlCreateButton("Run Applications", 10, 20, 90, 25, $WS_GROUP) GUICtrlSetOnEvent(-1, "_Run") $inp_Ms = GUICtrlCreateInput("", 296, 142, 41, 21) $lb_Time = GUICtrlCreateLabel("Time Between Aplications (Seconds)", 112, 146, 177, 17) $Label1 = GUICtrlCreateLabel("Status : ", 408, 144, 43, 17) $Label2 = GUICtrlCreateLabel("Unsaved", 456, 144, 47, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $file = @ScriptDir & "\" & "Plist.dat" Global $tFile = @ScriptDir & "\" & "Temp.dat" Global $ab = _FileCountLines($file) Global $SaveToggle = 0 Global $FileCheck = FileExists($file) ;-------------------Initial Display----------------------------- If $FileCheck = 1 Then ;Check to see if "File" Exists For $a = 1 To $ab GUICtrlSetData($prg_List, FileReadLine($file, $a)) Next Else FileWrite($file, "") ;If file doesn't exists, create it. EndIf ;--------------------------------------------------------------- While 1 Sleep(100) WEnd ;--------------------Begin Exit-------------------------- Func _Exit() ;If _FileCountLines($file) = 0 Or GUICtrlRead($prg_List) = "" Then Exit If $ab = _FileCountLines($file) AND FileExists($tFile) = 0 Then Exit If $SaveToggle = 0 And _FileCountLines($tFile) > 0 Then $saveAnswer = MsgBox(4, "Unsaved Warning", "Are you sure you want to exit without saving this information ?") If $saveAnswer = 6 Then FileDelete($tFile) Exit Else Return 0 EndIf EndIf If $SaveToggle = 1 And _FileCountLines($tFile) > 0 Then FileDelete($tFile) Exit ElseIf FileExists($File) = 0 AND FileExists($tFile) = 0 Then Exit EndIf EndFunc ;==>_Exit ;--------------------End Exit------------------------------ ;--------------------Begin ADD----------------------------- Func _ADD() $program = FileOpenDialog("Select Program", @ProgramFilesDir & "\", "Programs(*.exe)") If @error Then Return 0 Else FileWriteLine($tFile, $program) GUICtrlSetData($prg_List, $program) EndIf EndFunc ;==>_ADD ;--------------------END ADD-------------------------------- ;--------------------Begin Delete--------------------------- Func _Delete() If GUICtrlRead ($prg_List) == "" Then Return @Error If _FileCountLines ($file) == 1 Then If FileReadLine ($file, 1) == GUICtrlRead ($prg_List) Then FileDelete ($file) _Update() EndIf EndIf For $c = 1 To _FileCountLines ($file) $cLine = FileReadLine ($file, $c) If $cLine <> GUICtrlRead ($prg_List) Then FileWriteLine ('Saved_Temp.dat', $cLine) EndIf Next FileCopy ("Saved_Temp.dat", $file, 1) FileDelete ('Saved_Temp.dat') _Update () Return 1 EndFunc ;--------------------END DELETE----------------------------- ;--------------------Begin Update--------------------------- Func _Update() GUICtrlSetData ($prg_List, "") If FileExists ($file) Then For $d = 1 To _FileCountLines ($file) GUICtrlSetData ($prg_list, FileReadLine ($file, $d)) Next EndIf ;==>_Delete EndFunc Func _Save() $SaveToggle = 1 For $b = 1 To _FileCountLines($tFile) $tLine = FileReadLine($tFile, $b) FileWriteLine($file, $tLine) Next _Update() EndFunc ;==>_Save ;--------------------END UPDATE----------------------------- ;--------------------BEGIN RUN-------------------------- Func _Run() For $E = 1 to _FileCountLines($file) $runline = FileReadLine($file, $E) ShellExecute($runline) Next EndFunc ;--------------------END RUN-------------------------- ;--------------------BEGIN POS-------------------------- Func _POS() EndFunc ;--------------------END POS--------------------------
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