Jump to content

Combo box problem, plus looking for more tutorials


Recommended Posts

Guest Phibian
Posted

I'm a new user, so please be kind.

I've combed the manual, forum and the examples, but can't seem to apply them to my situation.

I am trying to create a basic window with a dropdown to let the user select IE or FireFox.

When the dropdown selection changes, I want to open the program they selected.

I started out using GUIGetMsg, but then the documentation I read suggested that I needed to use On Event mode. So I was more or less fine until in my function I needed to differentiate between the options in the dropdown. The example used GUI_CTRLID, which I think I set to $SelectBrowser, but that is the whole element and not the individual items.

Here's my non-working code, because I got stuck in the function and don't know how to access the info I need..

#include <GUIConstants.au3>

Opt("GUIOnEventMode", 1)

GUICreate("Select system for testing")

$SelectBrowser = GUICtrlCreateCombo("--Select your browser--", 60, 20, 160,21)

GUICtrlSetData (-1, "IE|FireFox")

GUICtrlSetOnEvent($SelectBrowser, "BrowserSelected")

GUISetState(@SW_SHOW)

While 1

Sleep(10)

Wend

Func BrowserSelected()

Select

Case @GUI_CTRLID = ??

If $msg = "IE" then Run("C:\Program Files\Internet Explorer\iexplore.exe")

If $msg = "FireFox" then Run ("C:\Program Files\Mozilla Firefox\firefox.exe")

EndFunc

Thanks for any help!

PS If anyone could point me to some simple examples of clicking around a web page, that would be super (I'm really looking for examples on the level of the tutorials that came with autoitscript). I'm hoping to find a more reliable way to select elements without figuring out where the mouse coordinates should be, because although I can set the size of the window, this doesn't help me if the dropdown menu moves slightly to the right for other reasons.

Posted (edited)

analyse the modification I did

#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)

GUICreate("Select system for testing")
GUISetOnEvent($GUI_EVENT_CLOSE, "CloseGUI")

$SelectBrowser = GUICtrlCreateCombo("--Select your browser--", 60, 20, 160,21)
GUICtrlSetData (-1, "IE|FireFox")
GUICtrlSetOnEvent($SelectBrowser, "BrowserSelected")
GUISetState(@SW_SHOW)
While 1
Sleep(10)
Wend
Func BrowserSelected()
If GUICtrlRead($SelectBrowser) = "IE" then Run(@programfilesdir & "\Internet Explorer\iexplore.exe")
If GUICtrlRead($SelectBrowser) = "FireFox" then Run (@programfilesdir & "\Mozilla Firefox\firefox.exe")
EndFunc
Func CloseGUI()
    Exit
EndFunc

EDIT: slight edition about @programfilesdir

Edited by jpm
Posted

I suggest you that:

- Check the examples included. Read this: Install Directory Structure

Read more about GUI Event modes and differences.

#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)

GUICreate("Select system for testing")

$SelectBrowser = GUICtrlCreateCombo("--Select your browser--", 60, 20, 160, 80)
GUICtrlSetData (-1, "IE|FireFox")
GUICtrlSetOnEvent($SelectBrowser, "BrowserSelected")

GUISetOnEvent($GUI_EVENT_CLOSE,"OnExit")

GUISetState(@SW_SHOW)

While 1
    Sleep(10)
Wend

Func BrowserSelected()
    $sBrowser = GUICtrlRead(@GUI_CTRLID)
    
    Select
    Case $sBrowser = "IE"
        MsgBox(0, "", "IE selected")
    ;Run("C:\Program Files\Internet Explorer\iexplore.exe")
    
    Case $sBrowser = "FireFox"
        MsgBox(0, "", "Firefox selected")
    ;Run ("C:\Program Files\Mozilla Firefox\firefox.exe")
    EndSelect
EndFunc

Func OnExit()
    Exit
EndFunc

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
  • Recently Browsing   0 members

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