Jump to content
Sign in to follow this  
hasoon2000

List box with choices and button to do the command

Recommended Posts

hasoon2000

Here is what I am working on.

Posted Image

What I want it to do is when I press for example, 1. Install HTC Drivers and I press Go, it will install the drivers. Or, if I press "1. CWM 5.0.2.7" and press flash, I want it to run the .bat command that I have. What it does now is when I open the .au3 file, it will automatically runs all my commands by itself. Here is the code

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$List1 = GUICtrlCreateList("", 24, 56, 121, 110)
GUICtrlSetData(-1, "1. Install HTC Drivers|2. Register at HTCDev|3. Get Token ID|4. Submit Token ID|5. Unlock Bootloader")
$Label1 = GUICtrlCreateLabel("Root the phone. Follow in order", 24, 16, 152, 17)
$List2 = GUICtrlCreateList("", 304, 56, 97, 84)
GUICtrlSetData(-1, "1. CWM 5.0.2.7|2. CWM 5.5.0.4|3. CWM Touch|4. TWRP 2.0.0|5. Stock")
$Label2 = GUICtrlCreateLabel("Next, Flash a Recovery.", 160, 72, 118, 17)
$Go = GUICtrlCreateButton("Go", 48, 176, 65, 17)
$Flash = GUICtrlCreateButton("Flash", 320, 176, 65, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;Default Variables
$recov= ""
;Default commands
$5027 = RunWait(@ComSpec & " /K " & @ScriptDir & "\data\FlashCWM5027.bat", @ScriptDir & "\data\", @SW_SHOW)
$5504 = RunWait(@ComSpec & " /K " & @ScriptDir & "\data\FlashCWM5504.bat", @ScriptDir & "\data\", @SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
   Case 1
      $selected = GUICtrlRead($Flash)
      switch $selected
   Case "1. CWM 5.0.2.7"
      $recov = $5027
   Case "2. CWM 5.5.0.4"
      $recov = $5504
   EndSwitch   
EndSwitch
WEnd

Share this post


Link to post
Share on other sites
hasoon2000

You can try ShellExecute.

case $Flash
   $read = GUICtrlRead($List2)
    if $read = true Then
  ShellExecute($read)
  EndIf
   EndSwitch

I think you can also make it like this for ur .bat

ShellExecute($read, "*.bat")

I am not understanding on how to edit the code with what you are trying to see. Can you edit mine so I can see how it is supposed to look?

Share this post


Link to post
Share on other sites
hawkair

the following lines unconditionally run the bat files even before you load the Gui:

$5027 = RunWait(@ComSpec & " /K " & @ScriptDir & "dataFlashCWM5027.bat", @ScriptDir & "data", @SW_SHOW)

$5504 = RunWait(@ComSpec & " /K " & @ScriptDir & "dataFlashCWM5504.bat", @ScriptDir & "data", @SW_SHOW)

So remove them

Your While loop should be like this

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
    Case $GUI_EVENT_CLOSE
        Exit
    Case $Go
        $Selected = GUICtrlRead($List1)
        Switch $selected
            Case "1. Install HTC Drivers"
                MsgBox (0, "", 'Run command to Install HTC Drivers')
            Case "2. Register at HTCDev"
;~             ...
        EndSwitch
    Case $Flash
        $Selected = GUICtrlRead($List2)
        Switch $selected
            Case "1. CWM 5.0.2.7"
                MsgBox (0, "", 'RunWait(@ComSpec & " /K " & @ScriptDir & "dataFlashCWM5027.bat", @ScriptDir & "data", @SW_SHOW)')
            Case "2. CWM 5.5.0.4"
                MsgBox (0, "", 'RunWait(@ComSpec & " /K " & @ScriptDir & "dataFlashCWM5504.bat", @ScriptDir & "data", @SW_SHOW)')
            Case Else

        EndSwitch
EndSwitch
WEnd

of course you should replace the msgbox statements with the actual ones

Edited by hawkair

Share this post


Link to post
Share on other sites
kspratik

Try to use Break(1) in each case.....it sud work

Share this post


Link to post
Share on other sites
BrewManNH

Try to use Break(1) in each case.....it sud work

Break only disables closing the script from the tray icon, I'm not sure how this would help with what the poster is trying to do.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
ileandros

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$List1 = GUICtrlCreateList("", 24, 56, 121, 110)
GUICtrlSetData(-1, "1. Install HTC Drivers|2. Register at HTCDev|3. Get Token ID|4. Submit Token ID|5. Unlock Bootloader")
$Label1 = GUICtrlCreateLabel("Root the phone. Follow in order", 24, 16, 152, 17)
$List2 = GUICtrlCreateList("", 304, 56, 97, 84)
GUICtrlSetData(-1, "1. CWM 5.0.2.7|2. CWM 5.5.0.4|3. CWM Touch|4. TWRP 2.0.0|5. Stock")
$Label2 = GUICtrlCreateLabel("Next, Flash a Recovery.", 160, 72, 118, 17)
$Go = GUICtrlCreateButton("Go", 48, 176, 65, 17)
$Flash = GUICtrlCreateButton("Flash", 320, 176, 65, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;Default Variables
$recov= ""
;Default commands
$5027 = RunWait(@ComSpec & " /K " & @ScriptDir & "dataFlashCWM5027.bat", @ScriptDir & "data", @SW_SHOW)
$5504 = RunWait(@ComSpec & " /K " & @ScriptDir & "dataFlashCWM5504.bat", @ScriptDir & "data", @SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
case $Flash 
$read = GuiCtrlRead($List2)
if $read = true Then
ShellExecute($read)
EndSwitch
WEnd

I think it should be like this so it executes the programmes you want and if its a .bat you should make it execute .bat if you want


I feel nothing.It feels great.

Share this post


Link to post
Share on other sites
BrewManNH

I think this might be more in line with what you're trying to achieve with the script. You might need to play around with the quotes but I think it should do what you want.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$List1 = GUICtrlCreateList("", 24, 56, 121, 110)
GUICtrlSetData(-1, "1. Install HTC Drivers|2. Register at HTCDev|3. Get Token ID|4. Submit Token ID|5. Unlock Bootloader")
$Label1 = GUICtrlCreateLabel("Root the phone. Follow in order", 24, 16, 152, 17)
$List2 = GUICtrlCreateList("", 304, 56, 97, 84)
GUICtrlSetData(-1, "1. CWM 5.0.2.7|2. CWM 5.5.0.4|3. CWM Touch|4. TWRP 2.0.0|5. Stock")
$Label2 = GUICtrlCreateLabel("Next, Flash a Recovery.", 160, 72, 118, 17)
$Go = GUICtrlCreateButton("Go", 48, 176, 65, 17)
$Flash = GUICtrlCreateButton("Flash", 320, 176, 65, 17)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
;Default Variables
$recov = ""
;Default commands
$5027 = @ComSpec & " /K " & '"' & @ScriptDir & "dataFlashCWM5027.bat"""
$5504 =@ComSpec & " /K " &  '"' & @ScriptDir & "dataFlashCWM5504.bat"""
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Flash
            $selected = GUICtrlRead($List2)
            Switch $selected
                Case "1. CWM 5.0.2.7"
                    $recov = RunWait($5027, @ScriptDir & "data", @SW_SHOW)
                Case "2. CWM 5.5.0.4"
                    $recov = RunWait($5504, @ScriptDir & "data", @SW_SHOW)
            EndSwitch
    EndSwitch
WEnd

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
hasoon2000

I think this might be more in line with what you're trying to achieve with the script. You might need to play around with the quotes but I think it should do what you want.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$List1 = GUICtrlCreateList("", 24, 56, 121, 110)
GUICtrlSetData(-1, "1. Install HTC Drivers|2. Register at HTCDev|3. Get Token ID|4. Submit Token ID|5. Unlock Bootloader")
$Label1 = GUICtrlCreateLabel("Root the phone. Follow in order", 24, 16, 152, 17)
$List2 = GUICtrlCreateList("", 304, 56, 97, 84)
GUICtrlSetData(-1, "1. CWM 5.0.2.7|2. CWM 5.5.0.4|3. CWM Touch|4. TWRP 2.0.0|5. Stock")
$Label2 = GUICtrlCreateLabel("Next, Flash a Recovery.", 160, 72, 118, 17)
$Go = GUICtrlCreateButton("Go", 48, 176, 65, 17)
$Flash = GUICtrlCreateButton("Flash", 320, 176, 65, 17)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
;Default Variables
$recov = ""
;Default commands
$5027 = @ComSpec & " /K " & '"' & @ScriptDir & "dataFlashCWM5027.bat"""
$5504 =@ComSpec & " /K " &  '"' & @ScriptDir & "dataFlashCWM5504.bat"""
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Flash
            $selected = GUICtrlRead($List2)
            Switch $selected
                Case "1. CWM 5.0.2.7"
                    $recov = RunWait($5027, @ScriptDir & "data", @SW_SHOW)
                Case "2. CWM 5.5.0.4"
                    $recov = RunWait($5504, @ScriptDir & "data", @SW_SHOW)
            EndSwitch
    EndSwitch
WEnd

You my friend, is awesome. So far your revisions are working. I just have 1 more question. I hope you can help out. I am trying to allow an exe file to be executed (drivers for the phone).

Under my default commands, I added

$Driver = @ComSpec & " /K " & '"' & @ScriptDir & "dataHTCDriver.exe"""

From what I know @Comspec is a RunWait command. It'll execute the drivers but the a blank command prompt shows up. I just don't want the cmd to pop up.

Thanks everyone for helping me. Really, I appreciate all the help you are giving me.

Share this post


Link to post
Share on other sites
BrewManNH

Try changing the @SW_SHOW to @SW_HIDE for that line in your script and see if it does what you're looking to do.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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  

×