Sign in to follow this  
Followers 0
hozdaman

Running a combobox in a function

3 posts in this topic

Hi,

I am a complete beginner at this so please excuse my ignorance. First I would like AutoIT is great I have been studying it pretty hard for the last month or so...

I now have some confidence in starting to write some of my own scripts. I am trying to write one that has a GUI and when you press the button it goes into a combobox. Here is what I have so far and I wanted to make sure I was on the right track or completely off my rocker. Thanks for your help in advance.

;Button 1; windows utilities

GUICtrlCreateButton("Windows Utilities",100,210,200,30

GUICtrlSetOnEvent(-1,'win_util');opens windows utilities combobox when button is pressed

;Windows Utilities function

Func win_util()

GUISetState(@SW_Hide);hide the GUI while function is running

$combobox=GUICtrlCreateCombo("Defrag",10,10,120,20)

GUICtrlSetData(-1,"Disk Cleanup|Calculator")

;loop to check for GUI events

While 1

$guimsg=GUIGetMsg()

select

Case $guimsg=$button

MsgBox(0,"Run" & GUICtrlRead($combobox))

select

Case (GUICtrlRead($combobox) = 'Defrag'

Run ("%SystemRoot%\system32\dfrg.msc"

Exit

Case (GUICtrlRead($combobox)= 'Disk Cleanup'

Run ("%SystemRoot%\system32\cleanmgr.exe")

Exit

Case (GUICtrlRead($combobox)= 'Calculator'

Run ("%SystemRoot%\system32\calc.exe")

Exit

EndSelect

Case $guimsg=$GUI_EVENT_CLOSE

Exit

EndSelect

WEnd

EndFunc

Share this post


Link to post
Share on other sites



#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 188, 126, 617, 484)
$Button1 = GUICtrlCreateButton("Start", 16, 48, 153, 65, $WS_GROUP)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$Combo1 = GUICtrlCreateCombo("", 16, 16, 153, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "Defrag|Calc|Cleanup", "Defrag")
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Switch GUICtrlRead($Combo1)
                Case "Defrag"
                    Run (@WindowsDir & "\system32\dfrg.msc")
                Case "Calc"
                    Run (@WindowsDir & "\system32\calc.exe")
                Case "Cleanup"
                    Run (@WindowsDir & "\system32\cleanmgr.exe")
            EndSwitch

    EndSwitch
WEnd


_____________________________________________________________________________

Share this post


Link to post
Share on other sites

Thank you. I will try this.

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  
Followers 0