Jump to content
VollachR

Can't get buttons to work correctly

Recommended Posts

VollachR

Hi,

I'm new to AutoIt, decided to try it in order to gradually re-write a very big Batch script I created and add a GUI for it.

Anyway, I've been experimenting with AutoIt and it's GUI features and I've been able to create a basic GUI with buttons and image background.

I have a couple of Browse buttons and an OK button, nothing much, the problem is that the Browse buttons works only once, once the selection have been transferred to the Input box clicking the Browse button just closes the program.

Also, most buttons, including the X button in the Title bar needs to be pressed a few times before they do anything.

Here's the relevant parts of the script file:

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <WinAPIDlg.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ColorConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
;#include ".\BG.jpg"
Opt("ExpandEnvStrings", 1) ;0=don't expand, 1=do expand
Opt("ExpandVarStrings", 1) ;0=don't expand, 1=do expand
if not FileExists (@TempDir & "\UCC\") then DirCreate (@TempDir & "\UCC\")
FileInstall (".\Common\UCCInclude\Common\fSplit.exe", @TempDir & "\UCC\fSplit.exe")
FileInstall (".\Common\UCCInclude\Common\piso.exe", @TempDir & "\UCC\piso.exe")
FileInstall (".\Common\UCCInclude\Common\PowerISO.exe", @TempDir & "\UCC\PowerISO.exe")
FileInstall (".\Common\UCCInclude\Common\BG.jpg", @TempDir & "\UCC\BG.JPG")
Const $Ver = "v4.1.4", $ScriptName = "Ultimate Conversion Compressor", $Author = "VollachR", $Build = "Beta"

GUI()
Func GUI()
    ;Create the GUI
    $hGUI = GUICreate($ScriptName & " " & $Ver & " " & "by " & $Author, 800, 500)
    GUISetBkColor(0xffffff, $hGUI )
    $BG = GUICtrlCreatePic(@TempDir & "\UCC\BG.JPG", 0, 0, 800, 500)
    GUICtrlSetState($BG, $GUI_DISABLE)
    Local $idOK = GUICtrlCreateButton("OK", 310, 370, 85, 25)
    $icon = GUISetIcon ("UCC.ico")
    $SourceLabel = GUICtrlCreateLabel("Source Folder:", 10, 35, 367)
    GUICtrlSetColor($SourceLabel, $COLOR_WHITE)
    GUICtrlSetBkColor($SourceLabel, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetFont ($SourceLabel,9, 700); bold
    $OutputLabel = GUICtrlCreateLabel("Output Folder:", 10, 110, 367)
    GUICtrlSetColor($OutputLabel, $COLOR_WHITE)
    GUICtrlSetBkColor($OutputLabel, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetFont (-1,9, 700); bold
    $Source = GUICtrlCreateInput("Select Game Folder",10,53,367,23)
    $Output = GUICtrlCreateInput("Select Destination",10,130,367,23)
    $browseSource = GUICtrlCreateButton("Browse", 400, 53,100, 23)
    $browseOut = GUICtrlCreateButton("Browse", 400, 130,100, 23)


    ;Display GUI
    GUISetState(@SW_SHOW, $hGUI)
    $msg = 0

    $hChild = GUICreate("", 210, 72, 20, 15, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hGUI)
    ; Display the child GUI.
    GUISetState(@SW_SHOW)
; Loop until the user exits.
    While 1
        $msg = GUIGetMsg()
        Select
            case $msg = $browseSource
                Local $sMessage1 = 'Select the '
                Local $sMessage2 = ' folder'
                Local const $sMessageSource = $sMessage1 & $sGameTitle & $sMessage2
                $SourceFolder = FileSelectFolder ($sMessageSource, "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}")
                GUICtrlSetData($Source, $SourceFolder)
        EndSelect
        Select
            case $msg = $browseout
                Local Const $sMessageout = 'Select Where to Create the Conversion'
                $OutputFolder = FileSelectFolder ($sMessageout, "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}")
                GUICtrlSetData($Output, $OutputFolder)
        EndSelect
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idOK
                ExitLoop
        EndSwitch
    WEnd

    ; Delete the previous GUIs and all controls.
    GUIDelete($hGUI)
    GUIDelete($hChild)
    FileDelete(@TempDir & "\UCC\")
EndFunc

Any help would be appreciated, thanks.


Ron Vollach
Microsoft Certified Professional (MCP)
Creator of Ultimate Conversion Compressor (UCC)
UCC Wikia

Share this post


Link to post
Share on other sites
BrewManNH

It doesn't just close, it gives you an error message, and the error message tells you what went wrong. Don't use Const in the declaration of $sMessageSource and it works ok.

  • Thanks 1

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
VollachR
33 minutes ago, BrewManNH said:

It doesn't just close, it gives you an error message, and the error message tells you what went wrong. Don't use Const in the declaration of $sMessageSource and it works ok.

OK, that worked in solving the browse buttons problem, thanks.

That said, there's still a problem that when trying to click the browse buttons a second time the click only work the 2nd time, that is I need to click the button twice to get it to open the folder selection dialog window after already selecting a folder.


Ron Vollach
Microsoft Certified Professional (MCP)
Creator of Ultimate Conversion Compressor (UCC)
UCC Wikia

Share this post


Link to post
Share on other sites
BrewManNH

Maybe something like this:

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <WinAPIDlg.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ColorConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
;#include ".\BG.jpg"
Opt("ExpandEnvStrings", 1) ;0=don't expand, 1=do expand
Opt("ExpandVarStrings", 1) ;0=don't expand, 1=do expand
;~ if not FileExists (@TempDir & "\UCC\") then DirCreate (@TempDir & "\UCC\")
;~ FileInstall (".\Common\UCCInclude\Common\fSplit.exe", @TempDir & "\UCC\fSplit.exe")
;~ FileInstall (".\Common\UCCInclude\Common\piso.exe", @TempDir & "\UCC\piso.exe")
;~ FileInstall (".\Common\UCCInclude\Common\PowerISO.exe", @TempDir & "\UCC\PowerISO.exe")
;~ FileInstall (".\Common\UCCInclude\Common\BG.jpg", @TempDir & "\UCC\BG.JPG")
Const $Ver = "v4.1.4", $ScriptName = "Ultimate Conversion Compressor", $Author = "VollachR", $Build = "Beta"

GUI()
Func GUI()
    Local $sGameTitle = "",$sMessage1 = 'Select the ', $sMessage2 = ' folder'
    ;Create the GUI
    $hGUI = GUICreate($ScriptName & " " & $Ver & " " & "by " & $Author, 800, 500)
    GUISetBkColor(0xffffff, $hGUI)
    $BG = GUICtrlCreatePic(@TempDir & "\UCC\BG.JPG", 0, 0, 800, 500)
    GUICtrlSetState($BG, $GUI_DISABLE)
    Local $idOK = GUICtrlCreateButton("OK", 310, 370, 85, 25)
    $icon = GUISetIcon("UCC.ico")
    $SourceLabel = GUICtrlCreateLabel("Source Folder:", 10, 35, 367)
    GUICtrlSetColor($SourceLabel, $COLOR_WHITE)
    GUICtrlSetBkColor($SourceLabel, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetFont($SourceLabel, 9, 700) ; bold
    $OutputLabel = GUICtrlCreateLabel("Output Folder:", 10, 110, 367)
    GUICtrlSetColor($OutputLabel, $COLOR_WHITE)
    GUICtrlSetBkColor($OutputLabel, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetFont(-1, 9, 700) ; bold
    $Source = GUICtrlCreateInput("Select Game Folder", 10, 53, 367, 23)
    $Output = GUICtrlCreateInput("Select Destination", 10, 130, 367, 23)
    $browseSource = GUICtrlCreateButton("Browse", 400, 53, 100, 23)
    $browseOut = GUICtrlCreateButton("Browse", 400, 130, 100, 23)


    ;Display GUI
    GUISetState(@SW_SHOW, $hGUI)
    $msg = 0

    $hChild = GUICreate("", 210, 72, 20, 15, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hGUI)
    ; Display the child GUI.
    GUISetState(@SW_SHOW)
    ; Loop until the user exits.
    While 1
;~         $msg = GUIGetMsg()
;~         Select
        Switch GUIGetMsg()
;~             case $msg = $browseSource
            Case $browseSource
                $sMessageSource = $sMessage1 & $sGameTitle & $sMessage2
                $SourceFolder = FileSelectFolder($sMessageSource, "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}")
                GUICtrlSetData($Source, $SourceFolder)
;~         EndSelect
;~         Select
;~             case $msg = $browseout
            Case $browseOut
                Local Const $sMessageout = 'Select Where to Create the Conversion'
                $OutputFolder = FileSelectFolder($sMessageout, "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}")
                GUICtrlSetData($Output, $OutputFolder)
;~         EndSelect
;~         Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idOK
                ExitLoop
        EndSwitch
    WEnd

    ; Delete the previous GUIs and all controls.
    GUIDelete($hGUI)
    GUIDelete($hChild)
;~  FileDelete(@TempDir & "\UCC\")
EndFunc   ;==>GUI

 

  • Thanks 1

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
VollachR

Yes, that works perfectly, just making sure I understand what you did there, you basically put all the buttons inside one "Switch" instead of using "Select" twice and separate "Switch" for the OK Button, am I right?

 

Thank you.


Ron Vollach
Microsoft Certified Professional (MCP)
Creator of Ultimate Conversion Compressor (UCC)
UCC Wikia

Share this post


Link to post
Share on other sites
BrewManNH

It streamlines the code without so many conditional statements. Also, you only want one button at a time to be activated, so this does that.

  • Thanks 1

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

×