Jump to content

_GUICtrlComboBoxEx_Create


Fran
 Share

Recommended Posts

Hi there...

I'm pretty new to AutoIt, so please excuse me for my silly questions :blink:

I've created a GUI with a combobox. I get the lines for the combobox from a text file. How do I get the result in the form of the selected text?

You'll see I've added a msgbox to display my result, but what I want is if the person selects "Azure", the msgbox must echo "Azure".

I have a attached my script.

Looking forward to adding another item to my "things-I-know-now-that-I-didn't-know-before" -list.

Cheers!

Fran

CreateContentUpdate.au3

Edited by Fran
Link to comment
Share on other sites

  • Moderators

Fran,

Welcome to the AutoIt forum. :blink:

There are quite a few things you might want to add to your "things-I-know-now-that-I-didn't-know-before" list in this shortened version of your script. :P

- 1. Use _FileListToArray to get a list of the files in a folder - much easier than FileFindFirst/NextFile.

- 2. Use the built-in combo rather than the UDF version - much less trouble to work with.

- 3. Switch can accept multiple versions of a Case - saves typing!

- 4. You can use the MsgBox directly in the If statement.

- 5. And you use GUICtrlRead to get the selected value of a built-in combo!

Here is the script - look for the <<<<<<<<<<<<<<<<< lines:

; Script Start - Add your code below here
;#RequireAdmin

#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ProgressConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <array.au3>
#include <file.au3>
#include <GUIComboBox.au3>
#include <GUIComboBoxEx.au3>

Opt("TrayAutoPause", 0)
Opt("TrayIconHide", 0)

; Shows the filenames of all files in the current directory.
$aFileList = _FileListToArray("ContentUpdates\mphoto\", "*.*", 1) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
If @error Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf
; Put array into a string
$sFileList = "|" & _ArrayToString($aFileList, "|", 1)

_Main()

Func _Main()
    $gui = GUICreate("Create exe", 460, 250)

    $hCombo = GUICtrlCreateCombo("", 40, 100, 380, 296) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    GUICtrlSetData($hCombo, $sFileList)

    $butNext = GUICtrlCreateButton("Next", 350, 210, 90, 30, BitOR($BS_DEFPUSHBUTTON, $BS_NOTIFY))
    $butCancel = GUICtrlCreateButton("Cancel", 250, 210, 90, 30, BitOR($BS_DEFPUSHBUTTON, $BS_NOTIFY))

    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $butCancel ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                If MsgBox(8196, "Cancel setup", "Are you sure you want to cancel this operation?") = 6 Then Exit ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            Case $butNext
                MsgBox(4096, "result", "You have chosen: " & GUICtrlRead($hCombo)) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        EndSwitch
    WEnd

EndFunc   ;==>_Main

I hope it all makes sense - please ask if not. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Wow, thanks!

This helps me a great deal.

Have a good one!

Fran,

Welcome to the AutoIt forum. :blink:

There are quite a few things you might want to add to your "things-I-know-now-that-I-didn't-know-before" list in this shortened version of your script. :P

- 1. Use _FileListToArray to get a list of the files in a folder - much easier than FileFindFirst/NextFile.

- 2. Use the built-in combo rather than the UDF version - much less trouble to work with.

- 3. Switch can accept multiple versions of a Case - saves typing!

- 4. You can use the MsgBox directly in the If statement.

- 5. And you use GUICtrlRead to get the selected value of a built-in combo!

Here is the script - look for the <<<<<<<<<<<<<<<<< lines:

; Script Start - Add your code below here
;#RequireAdmin

#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ProgressConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <array.au3>
#include <file.au3>
#include <GUIComboBox.au3>
#include <GUIComboBoxEx.au3>

Opt("TrayAutoPause", 0)
Opt("TrayIconHide", 0)

; Shows the filenames of all files in the current directory.
$aFileList = _FileListToArray("ContentUpdates\mphoto\", "*.*", 1) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
If @error Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf
; Put array into a string
$sFileList = "|" & _ArrayToString($aFileList, "|", 1)

_Main()

Func _Main()
    $gui = GUICreate("Create exe", 460, 250)

    $hCombo = GUICtrlCreateCombo("", 40, 100, 380, 296) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    GUICtrlSetData($hCombo, $sFileList)

    $butNext = GUICtrlCreateButton("Next", 350, 210, 90, 30, BitOR($BS_DEFPUSHBUTTON, $BS_NOTIFY))
    $butCancel = GUICtrlCreateButton("Cancel", 250, 210, 90, 30, BitOR($BS_DEFPUSHBUTTON, $BS_NOTIFY))

    GUISetState()

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $butCancel ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                If MsgBox(8196, "Cancel setup", "Are you sure you want to cancel this operation?") = 6 Then Exit ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            Case $butNext
                MsgBox(4096, "result", "You have chosen: " & GUICtrlRead($hCombo)) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        EndSwitch
    WEnd

EndFunc   ;==>_Main

I hope it all makes sense - please ask if not. ;)

M23

Link to comment
Share on other sites

  • Moderators

Fran,

Glad I could help. ;)

A small thing - when you reply please use the "Add Reply" button at the top and bottom of the page rather then the "Reply" button in the post itself. That way you do not get the contents of the previous post quoted in your reply and the whole thread becomes easier to read. :blink:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

:blink: - like this?

Just wanted to let you know you've helped me tremendously. Not only with this specific script, but also with my other scripts.

They are shorter by at least 20%!

Much less typing ;)

You rock!

Can I ask one more question?

How would you manage a "back" button in a GUI... as there is no GOTO function.

Fran

Link to comment
Share on other sites

  • Moderators

Fran,

like this?

Exactly! :blink:

Who needs GoTo? You manage multiple GUIs in GetMessage mode by using the "advanced" parameter in GUIGetMsg like this:

#include <GUIConstantsEx.au3>

; We need to declare this early becasue we check it even if GUI_2 does not exist
Global $hGUI_2 = 9999

; Create GUI_1
$hGUI_1 = GUICreate("GUI 1", 500, 500)
$hButton_1 = GUICtrlCreateButton("New GUI", 10, 10, 80, 30)
GUISetState()

While 1

    ; Use GUIGetMsg with advanced parameter to see which GUI is sending message
    $aMsg = GUIGetMsg(1)
    ; Check which GUI
    Switch $aMsg[1]
        Case $hGUI_1
            ; Check which message GUI_1 sent
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    Exit
                Case $hButton_1
                    ; Create GUI_2
                    $hGUI_2 = GUICreate("GUI 2", 200, 200)
                    $hButton_2 = GUICtrlCreateButton("Back", 10, 10, 80, 30)
                    GUISetState()
            EndSwitch
        Case $hGUI_2
            ; Check which message GUI_2 sent
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE, $hButton_2
                    GUIDelete($hGUI_2)
            EndSwitch
    EndSwitch

WEnd

Note how we can differentiate between the $GUI_EVENT_CLOSE messages from the 2 windows. :P

All clear? ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

mmmm... not so clear yet, but I'll get there soon enough.

Another q (I'm keeping you busy)

How do I open windows explorer to a specific path?

example "S:\ContentUpdates\finished"

I've gotten so far as:

Run(explorer.exe)

F

Link to comment
Share on other sites

  • Moderators

Fran,

ShellExecute("Your_Folder_Path") :blink:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

and I thought "It can't be this easy.." by low and behold, it is!

Thanx dude!

I got some more questions, but I'll post a new thread for the next one.

Once again... Thank you!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...