Sign in to follow this  
Followers 0
Fewmitz

Apparently I don't understand AutoIt GUIs at all

12 posts in this topic

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? ¬_¬

Share this post


Link to post
Share on other sites



make a loop so that it will be shown

Share this post


Link to post
Share on other sites

make a loop so that it will be shown

Taken from SampleControls.au3 GUI

; GUI MESSAGE LOOP
GuiSetState()
While GuiGetMsg() <> $GUI_EVENT_CLOSE
WEnd

Share this post


Link to post
Share on other sites

That is such a bad way to make a programming language.

I feel stupid.

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.

Share this post


Link to post
Share on other sites

That is such a bad way to make a programming language.

No its not, its commom sense.

Share this post


Link to post
Share on other sites

No its not, its commom sense.

No. Common sense would make it so you don't have to constantly display the form, and just have it up, and you can close it when needed.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

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]

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

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

---╔╦═╗╔╗'''╔╗╔═╦═╗╔╦═╗---╝╠═╣╝║'''║╝╝''''''╝╝║'''......''''''''''''''''''''''''''''''---╔╩═╩═╩═╩═══╩═╦═╩═╩══╦══════╗''''╔╩════════════╩══╗╔══╩══╗╔══╝ ''''''''''''''''''''''''''''''''''''''''''''''''''''║║'''''''''''''''║║ ''''''''''''''''''''''''''''''''''''''''''''''╔══╝╚══╗''''''║║''''''''''''''''''''''''''''''''''''''''''''''╚══════╝''''''╚╝

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

The Sleep() function in AutoIt is not the same as the thread sleeping function in Windows. The AutoIt Sleep function allows it to pause the current execution, events will still be triggered, such as hot keys or GUI events (if turned on).

Share this post


Link to post
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]

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