Jump to content
Sign in to follow this  
Aces

running paths from GUICtrlCreateInput 's

Recommended Posts

Aces

im using:

#include <GUIConstants.au3>

GUICreate("MultiProgz v1.0 - Example: C:\Program Files\Program\program.exe - With quotes", 800, 400)

$prog1 = GUICtrlCreateInput("", 100,20, 400,25)
$label1 = GUICtrlCreateLabel("First Path:", 20,25, 70,25)
$prog2 = GUICtrlCreateInput("", 100,55, 400,25)
$label2 = GUICtrlCreateLabel("Second Path:", 20,60, 70,25)
$prog3 = GUICtrlCreateInput("", 100,90, 400,25)
$label3 = GUICtrlCreateLabel("Third Path:", 20,95, 70,25)
$prog4 = GUICtrlCreateInput("", 100,125, 400,25)
$label4 = GUICtrlCreateLabel("Fourth Path:", 20,130, 70,25)
$prog5 = GUICtrlCreateInput("", 100,160, 400,25)
$label5 = GUICtrlCreateLabel("Fifth Path:", 20,165, 70,25)
$prog6 = GUICtrlCreateInput("", 100,195, 400,25)
$label6 = GUICtrlCreateLabel("Sixth Path:", 20,200, 70,25)
$prog7 = GUICtrlCreateInput("", 100,230, 400,25)
$label7 = GUICtrlCreateLabel("Seventh Path:", 20,235, 70,25)
$prog8 = GUICtrlCreateInput("", 100,265, 400,25)
$label8 = GUICtrlCreateLabel("Eighth Path:", 20,270, 70,25)
$prog9 = GUICtrlCreateInput("", 100,300, 400,25)
$label9 = GUICtrlCreateLabel("Ninth Path:", 20,305, 70,25)
$prog10 = GUICtrlCreateInput("", 100,335, 400,25)
$label10 = GUICtrlCreateLabel("Tenth Path:", 20,340, 70,25)

$save = GUICtrlCreateButton("Save Paths", 525,20, 150,80)
$load = GUICtrlCreateButton("Load Paths", 525, 110, 150,80)
$run = GUICtrlCreateButton("Run Paths", 525, 200, 150,80)

GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $save
            save()
        Case $msg = $load
            load()
        Case $msg = $run
            prun()
    EndSelect
WEnd

Func save()
    RegWrite("HKEY_CURRENT_USER\Software\multiprogz", "multiprogz_path1", "REG_SZ", GUICtrlRead($prog1))
    RegWrite("HKEY_CURRENT_USER\Software\multiprogz", "multiprogz_path2", "REG_SZ", GUICtrlRead($prog2))
    RegWrite("HKEY_CURRENT_USER\Software\multiprogz", "multiprogz_path3", "REG_SZ", GUICtrlRead($prog3))
    RegWrite("HKEY_CURRENT_USER\Software\multiprogz", "multiprogz_path4", "REG_SZ", GUICtrlRead($prog4))
    RegWrite("HKEY_CURRENT_USER\Software\multiprogz", "multiprogz_path5", "REG_SZ", GUICtrlRead($prog5))
    RegWrite("HKEY_CURRENT_USER\Software\multiprogz", "multiprogz_path6", "REG_SZ", GUICtrlRead($prog6))
    RegWrite("HKEY_CURRENT_USER\Software\multiprogz", "multiprogz_path7", "REG_SZ", GUICtrlRead($prog7))
    RegWrite("HKEY_CURRENT_USER\Software\multiprogz", "multiprogz_path8", "REG_SZ", GUICtrlRead($prog8))
    RegWrite("HKEY_CURRENT_USER\Software\multiprogz", "multiprogz_path9", "REG_SZ", GUICtrlRead($prog9))
    RegWrite("HKEY_CURRENT_USER\Software\multiprogz", "multiprogz_path10", "REG_SZ", GUICtrlRead($prog10))
EndFunc

Func load()
    $regread1 = RegRead("HKEY_CURRENT_USER\Software\multiprogz", "multiprogz_path1")
    $regread2 = RegRead("HKEY_CURRENT_USER\Software\multiprogz", "multiprogz_path2")
    $regread3 = RegRead("HKEY_CURRENT_USER\Software\multiprogz", "multiprogz_path3")
    $regread4 = RegRead("HKEY_CURRENT_USER\Software\multiprogz", "multiprogz_path4")
    $regread5 = RegRead("HKEY_CURRENT_USER\Software\multiprogz", "multiprogz_path5")
    $regread6 = RegRead("HKEY_CURRENT_USER\Software\multiprogz", "multiprogz_path6")
    $regread7 = RegRead("HKEY_CURRENT_USER\Software\multiprogz", "multiprogz_path7")
    $regread8 = RegRead("HKEY_CURRENT_USER\Software\multiprogz", "multiprogz_path8")
    $regread9 = RegRead("HKEY_CURRENT_USER\Software\multiprogz", "multiprogz_path9")
    $regread10 = RegRead("HKEY_CURRENT_USER\Software\multiprogz", "multiprogz_path10")
    GUICtrlSetData($prog1, $regread1)
    GUICtrlSetData($prog2, $regread2)
    GUICtrlSetData($prog3, $regread3)
    GUICtrlSetData($prog4, $regread4)
    GUICtrlSetData($prog5, $regread5)
    GUICtrlSetData($prog6, $regread6)
    GUICtrlSetData($prog7, $regread7)
    GUICtrlSetData($prog8, $regread8)
    GUICtrlSetData($prog9, $regread9)
    GUICtrlSetData($prog10, $regread10)
EndFunc

Func prun()
    Run(GUICtrlRead($prog1))
    Run(GUICtrlRead($prog2))
    Run(GUICtrlRead($prog3))
    Run(GUICtrlRead($prog4))
    Run(GUICtrlRead($prog5))
    Run(GUICtrlRead($prog6))
    Run(GUICtrlRead($prog7))
    Run(GUICtrlRead($prog8))
    Run(GUICtrlRead($prog9))
    Run(GUICtrlRead($prog10))
EndFunc

what i want to do is get "prun()" to run ONLY the $prog1-10 input's that have paths written into them


~~ AutoIt v3 Minion ~~Name: Kevin "Aces-X" MorrisOrganization: A C DevelopmentE-Mail: AcesX91@acecoding.netOS: XP Professional; Vista package~~ Released Software ~~CPU-Mach: Topic at acecoding.net ForumsProxyzBuddy: Beta testing at the moment, private onlyWHSTool: Not released to the public

Share this post


Link to post
Share on other sites
star2

If GUICtrlRead($prog1) <> "" Then
        Run(GUICtrlRead($prog1))
    EndIf

Edited by star2

[quote]Baby you're all that I want, When you're lyin' here in my armsI'm findin' it hard to believe, We're in heavenAnd love is all that I need , And I found it there in your heartIt isn't too hard to see, We're in heaven .Bryan Adams[/quote].............................................................................[u]AUTOIT[/u]

Share this post


Link to post
Share on other sites
smashly

I was bored so I had a poke at your code.

Added Clear Registry button.

Added Drag & Drop file in an input boxes.

Eliminated the need for a user to wrap the path in quote tags

Looped the save, load and run functions, to briefen them.

Added some msg boxes when things are ok or not.

If no reg settings are stored then disable Load and Clear buttons

If Reg Settings are found then enable Load and Clear buttons.

Used ShellExecute to run the files instead of run.

Tthis way a user can launch any type of file that their pc can open. .lnk , urls , exe, pictures..etc just drag it into the input box :rolleyes:

I added some comments to the script to hopefully help with what's going on.

#include <GUIConstants.au3>

Global $Control[15][2], $clr = 1
;$Control[n][0] stores the labels (n being a number from 1 To 10)
;$Control[n][1] stores the input boxes (n being a number from 1 To 10)
;$Control[x][1] stores the buttons (x being a number from 11 To 14)
;$clr = 1 is just a state so that the enable/disable buttons doesn't cause filckering from repeating the same task unnecessarily.

$Main = GUICreate("MultiProgz v1.0 - Example: C:\Program Files\Program\program.exe", 800, 400, -1, -1, -1, $WS_EX_ACCEPTFILES)
$spl = StringSplit('First Path:|Second Path:|Third Path:|Fourth Path:|Fifth Path:|Sixth Path:|Seventh Path:|' & _
                    'Eighth Path:|Ninth Path:|Tenth Path:|Save Paths|Load Paths|Run Paths|Clear Registry', '|')
;$spl is an array to store all the control names and label names to be used when the controls are drawn.
$y = 20 
For $c = 1 To 14 ;here is the start of creating your controls
    If $c = 11 Then $y = 20 
    If $c < 11 Then
        $Control[$c][0] = GUICtrlCreateLabel($spl[$c], 20, $y + 5, 70, 25)
        $Control[$c][1] = GUICtrlCreateInput("", 100, $y, 400, 25)
        GUICtrlSetState($Control[$c][1], $GUI_DROPACCEPTED)
        GuiCtrlSetFont(-1, 11)
        $y = $y + 35
    ElseIf $c > 10 Then
        $Control[$c][1] = GUICtrlCreateButton($spl[$c], 525, $y, 150,80)
        $y = $y + 90
    EndIf   
Next ;All your controls have been created
$spl = 0 ; now the controls and labels are drawn we can clear the $spl array.
GuiCtrlSetState($Control[12][1], $GUI_DISABLE)
GuiCtrlSetState($Control[14][1], $GUI_DISABLE)
GUISetState()

While 1
    RegEnumVal("HKEY_CURRENT_USER\Software\multiprogz",1) 
    If @error = 0 And $clr = 1 Then ;If the registry has any settings stored then enable load and clear buttons
        GuiCtrlSetState($Control[12][1], $GUI_ENABLE)
        GuiCtrlSetState($Control[14][1], $GUI_ENABLE)
        $clr = 0
    ElseIf @error = 1 And $clr = 0 Then ;If the registry doesn't have any settings stored then disable load and clear button
        GuiCtrlSetState($Control[12][1], $GUI_DISABLE)
        GuiCtrlSetState($Control[14][1], $GUI_DISABLE)
        $clr = 1
    EndIf   
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $Control[11][1] ;Save Button
            save()
        Case $msg = $Control[12][1] ;Load Button
            load()
        Case $msg = $Control[13][1] ;Run Button
            prun()
        Case $msg = $Control[14][1] ; Clear Registry Button
            creg()
    EndSelect
WEnd

Func save() ;Save will give warning of success or failure.
    For $s = 1 To 10
        $rw = RegWrite("HKEY_CURRENT_USER\Software\multiprogz", "multiprogz_path" & $s, "REG_SZ", GUICtrlRead($Control[$s][1]))
        If $rw <> 1 Then 
            MsgBox(16,'Error writing to registry', 'Save Paths has failed to write settings to the registry') 
            Return -1
        ElseIf $rw = 1 And $s = 10 Then
            MsgBox(64, 'Success writing to registry', 'Save Paths has successfully saved paths to the registry')
            Return 1
        EndIf   
    Next    
EndFunc

Func load() ; 3 lines does the same thing as your original 20 lines
    For $l = 1 To 10
        GUICtrlSetData($Control[$l][1], RegRead("HKEY_CURRENT_USER\Software\multiprogz", "multiprogz_path" & $l))
    Next
EndFunc

Func prun() ;Made it so a user doesn't have to worry about adding quotes to paths with spaces
    For $r = 1 To 10 
        If FileExists(GUICtrlRead($Control[$r][1])) Then ; If the file exists then shellexecute it, just about any file runs.
            ShellExecute('"' & GUICtrlRead($Control[$r][1]) & '"') ; User doesn't need to worry about Quotes arround the path
        ElseIf StringLeft(GUICtrlRead($Control[$r][1]), 4) = 'http' Or StringLeft(GUICtrlRead($Control[$r][1]), 4) = 'ftp:' _
                                                                    Or StringLeft(GUICtrlRead($Control[$r][1]), 4) = 'www.' Then
            ShellExecute(GUICtrlRead($Control[$r][1])) ; Added a small check so you can also run urls, ftp..etc
        EndIf   
    Next
EndFunc

Func creg() ; offer to Delete the reg entries added by your gui , sinc ethey're not mission critical.
    $rd = RegDelete("HKEY_CURRENT_USER\Software\multiprogz")
    If $rd = 1 Then
        MsgBox(64, 'Success clearing registry', 'Clear Registry has successfully removed registry entries.')
    EndIf   
EndFunc

Have fun

Cheers

Share this post


Link to post
Share on other sites
star2

I was bored so I had a poke at your code.

Added Clear Registry button.

Added Drag & Drop file in an input boxes.

Eliminated the need for a user to wrap the path in quote tags

Looped the save, load and run functions, to briefen them.

Added some msg boxes when things are ok or not.

If no reg settings are stored then disable Load and Clear buttons

If Reg Settings are found then enable Load and Clear buttons.

Used ShellExecute to run the files instead of run.

Tthis way a user can launch any type of file that their pc can open. .lnk , urls , exe, pictures..etc just drag it into the input box :rolleyes:

I added some comments to the script to hopefully help with what's going on.

Have fun

Cheers

what was goning to happen if u weren't board !!

nice job


[quote]Baby you're all that I want, When you're lyin' here in my armsI'm findin' it hard to believe, We're in heavenAnd love is all that I need , And I found it there in your heartIt isn't too hard to see, We're in heaven .Bryan Adams[/quote].............................................................................[u]AUTOIT[/u]

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×