Jump to content

Apparently I don't understand AutoIt GUIs at all


Fewmitz
 Share

Recommended Posts

So right now, I have this code:

#include <GUIConstants.au3>

[...]

Opt("GUIOnEventMode", 1 )
GuiCreate("MyGUI", 200, 250,-1, -1 )

$add = GuiCtrlCreateButton("Add", 10, 20, 180, 80)
GUICtrlSetOnEvent(-1, "_begin" )
$Edit1 = GUICtrlCreateEdit( "", 0, 100, 200, 150)
 GuiSetState()

But when I run the script, the window flashes, then disappears.

What am I doing wrong? ¬_¬

Link to comment
Share on other sites

Ah, who said anything about constantly displaying the form? your GUI closes because the script ended, now to stop this, you need a loop, and not only that, if you had buttons, you wouldn't be able to check if it was pressed later if you only check once! The most basic of languages makes the most complex of programs.

Edit: (sorry I forgot to answer your question)

$var=InputBox("title","prompt") ;Declare a value with the InputBox

MsgBox(0,"title","Your variable is: "&$var) ;Display your box

Cheers.

P.S. Whats all this about common sense? You need a lot more than just common sense if you want to be serious about scripting

Edited by MethodZero

[center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center]

Link to comment
Share on other sites

If you didn't start with AutoIt as you're programming language I can see why a constant loop would appear useless. I was looking as VisualBasic some and was surprised by the differences. However, I almost always use GuiOnEvent mode and GuiRegisterMsg so my loop almost always look like this:

While 1
Sleep(1000) 
WEnd
My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to comment
Share on other sites

One more question, though: How would I reference the value in an InputBox? Something like if I wanted to put the value of one in a message box.

Another example

#include <GUIConstants.au3>

Global $name_input

GUICreate("Demo", 200, 200)
$name_input = GUICtrlCreateInput("Your Name?", 100, 100, 90, 20)
$next = GUICtrlCreateButton("Next", 150, 170, 50, 20)
GUISetState(@SW_SHOW)

While True
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $next
            nextbutton()
    EndSelect
WEnd

Func nameinput()
    $inputname = GUICtrlRead($name_input)
EndFunc

Func nextbutton()
    Global $inputname = GUICtrlRead($name_input)
GUICreate("Demo", 200, 200)
$label = GUICtrlCreateLabel("Your name is " & $inputname, 50, 50) 
GUISetState(@SW_SHOW)

While True
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd
EndFunc
Edited by toothyXdip
---╔╦═╗╔╗'''╔╗╔═╦═╗╔╦═╗---╝╠═╣╝║'''║╝╝''''''╝╝║'''......''''''''''''''''''''''''''''''---╔╩═╩═╩═╩═══╩═╦═╩═╩══╦══════╗''''╔╩════════════╩══╗╔══╩══╗╔══╝ ''''''''''''''''''''''''''''''''''''''''''''''''''''║║'''''''''''''''║║ ''''''''''''''''''''''''''''''''''''''''''''''╔══╝╚══╗''''''║║''''''''''''''''''''''''''''''''''''''''''''''╚══════╝''''''╚╝
Link to comment
Share on other sites

If you didn't start with AutoIt as you're programming language I can see why a constant loop would appear useless. I was looking as VisualBasic some and was surprised by the differences. However, I almost always use GuiOnEvent mode and GuiRegisterMsg so my loop almost always look like this:

While 1
Sleep(1000) 
WEnd
Correct me if I'm wrong, but that's a shoddy bit of code. With the Sleep command, message events are almost always delayed indefinitely in Windows XP, sometimes making it ridiculously slow. I don't doubt it might work, but for a beginner, a $msg loop is more than enough.

Proper code would run more along these lines:

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $button
         ; code...
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

I discovered the Switch loop all too slowly.

Edited by RobertKipling
Link to comment
Share on other sites

Correct me if I'm wrong, but that's a shoddy bit of code. With the Sleep command, message events are almost always delayed indefinitely in Windows XP, sometimes making it ridiculously slow. I don't doubt it might work, but for a beginner, a $msg loop is more than enough.

Proper code would run more along these lines:

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $button
        ; code...
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

I discovered the Switch loop all too slowly.

With the GuiOnEvent options the reaction time is possibly faster then using a GuiGetMsg() in your loop. Try using it sometime... I find it makes my code more organized, shorter and cleaner.
My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
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...