Jump to content

GUI Questions


Recommended Posts

Hey, just playing around with the GUI functions in AutoIT, and what i want to do is to start opening with a MsgBox, that when clicked will open a GUI Box with input boxes/menus/ect to choose.

#include <GUIConstantsEx.au3>
#Include <Misc.au3>
#include <EditConstants.au3>
$InputBox = MsgBox(0,'Title', "Made By: Feonix")
While 1
    If GUIGetMsg() = $InputBox Then
        Do  
            GUICreate("Title - Main",150,350)
        Until Sleep(100)
    EndIf
WEnd

With this code the Msg box opens, but when clicked it does nothing. I guess im stuck at the DO, IF, THEN part for creating the GUI Thanks in advance D:

Link to comment
Share on other sites

Unless you have reason for the includes you do not need them.

Try this

GUICreate("Title - Main",150,350)
$InputBox = MsgBox(0,'Title', "Made By: Feonix")
GUISETSTATE()
Do
Until GUIGetMsg() = -3oÝ÷ Ûú®¢×®'ò¢çhmÁ©í¶"¨º³Âjëh×6GUICreate("Title - Main",150,350)
$InputBox = MsgBox(0,'Title', "Made By: Feonix")
GUISetState()
Do
sleep(100)
Until GUIGetMsg() = -3
Link to comment
Share on other sites

@Paulie

Why would this "kill my PC"?

I only get a 20% CPU spike at runtime and then idle down to 0.

I am new to this so don't "kill me" if the answer is obvious.

well, it won't quite kill your PC as bad as someting like this

While 1
Wend

because it is still doing something else (polling GuiGetMsg) but a sleep in a loop like that is essential to save any slow computer.

Edited by Paulie
Link to comment
Share on other sites

GUICreate("Title - Main",150,350)
$InputBox = MsgBox(0,'Title', "Made By: Feonix")
GUISetState()
Do
sleep(100)
Until GUIGetMsg() = -3

Kk, this works just as i wanted thanks muttley

but, if at all possible, can u explain some things?

Why does the MsgBox need a variable if were not using that var within the code, and what does the -3 result in?

Link to comment
Share on other sites

In this case the MsgBox does not need to be a variable but if you were to use a different flag you would need to call the return value... see help file for MsgBox.

Not exactly sure but I believe -3 is equivalent to the GUI being closed or not existing.

Link to comment
Share on other sites

GUICreate("Title - Main",150,350)
$InputBox = MsgBox(0,'Title', "Made By: Feonix")
GUISetState()
Do
sleep(100)
Until GUIGetMsg() = -3

Kk, this works just as i wanted thanks muttley

but, if at all possible, can u explain some things?

Why does the MsgBox need a variable if were not using that var within the code, and what does the -3 result in?

Sure I'll explain

The msgbox does not need a variable. We only kept the variable there because it was in you original code.

-3 is a JMeyers Magic number for the variable $GUI_EVENT_CLOSE

Link to comment
Share on other sites

Sure I'll explain

The msgbox does not need a variable. We only kept the variable there because it was in you original code.

-3 is a JMeyers Magic number for the variable $GUI_EVENT_CLOSE

Awesome thanks to both of you muttley This will help me immensly in experimenting with the GUI functions.

Link to comment
Share on other sites

Thanks Paulie, I will start adding sleep to my loops to slow them down.

; Run Task Manager

Dim $Exiter = 0

HotKeySet("{F5}", "Set_Exiter")
HotKeySet("{ESC}", "Terminate")

; I dont see much difference here, I was told this first loop is fine and GUIGetMsg() has a "built-in" sleep ( more or less )

Do
    If $Exiter Then ExitLoop
Until GUIGetMsg() = -3

$Exiter = 0

Do
    Sleep(100)
Until $Exiter

; This will use 100% 
$Exiter = 0

Do
    ; nada
Until $Exiter

; Functions only 

Func Set_Exiter()
    $Exiter = 1
EndFunc   ;==>Set_Exiter

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

@Paulie

-3 is a JMeyers Magic number for the variable $GUI_EVENT_CLOSE

This is not "My Magic Number", I think I seen it in a script in on the forum and picked it up. Not sure who to credit it to but

is probably not good practice I assume. I will stay with the $GUI_EVENT_CLOSE.

@ Valuater

Thanks for the insight.

; This will use 100%

$Exiter = 0

Do

; nada

Until $Exiter

However this only uses 50% CPU on my laptop... is this because of having a dual core processor?
Link to comment
Share on other sites

Thanks for the insight.

However this only uses 50% CPU on my laptop... is this because of having a dual core processor?

correct. I don't think its possible for 1 single process to use 100% of your CPU with dual core.
Link to comment
Share on other sites

Hey guys, got another problem.

btw, dont mean to be a pest xD ive read the help file for what the GUI functions do, and looked a bit around the forums but no luck.

This new code i made is supposed to have the GUI window with a main opening of 2 buttons. Then, if the top button is selected or "clicked" then it will open another GUI window.

GUICreate("Title - Main",150,350)
GUISetBkColor(0x000000)
$Input = GUICtrlCreateButton("Button 1",5,10,140,20)
$Input2 = GUICtrlCreateButton("Button 2",5, 50, 140, 20)
MsgBox(0,'Title', "Made By: Feonix")
GUISetState()

    If GUIGetMsg() = $Input THEN
        Do
            GUICreate("Button Window",150,200)
            GUISetState() 
            Sleep(100)
        Until GUIGetMsg() = -3
    Else
        Do
            sleep(100)
        Until GUIGetMsg() = -3

    EndIf

Thanks again for any help muttley

Link to comment
Share on other sites

@Paulie

This is not "My Magic Number", I think I seen it in a script in on the forum and picked it up. Not sure who to credit it to but

is probably not good practice I assume.

It is a very good practice. It saves space, and by remembering all of the GUI Constants, It can dramatically reduce the size of your compiled files.

Many members want GUIConstants.au3 to be removed completely (Or phased out)

EDIT: For that last question, You need a loop keeping the window open. You are sleeping for 100MS, AKA 1/10 of a second, which is how long your GUI stays open.

Edited by KentonBomb
Link to comment
Share on other sites

It is a very good practice. It saves space, and by remembering all of the GUI Constants, It can dramatically reduce the size of your compiled files.

Many members want GUIConstants.au3 to be removed completely (Or phased out)

It's not a good practice when you are posting on a public forum where someone may try to use your script as an example to learn from. It's very hard to understand a script when numbers seem to appear out of no where. It may indeed be worth the time to look up constants and replace them in your code if you are planning to release an official copy of a program and are trying to optimize it. But as far as source code goes, you might as well have just obfuscated it. (at least for me)

EDIT: grammar/typos

Edited by Paulie
Link to comment
Share on other sites

Yea, i suspected that was the problem, and ive changed the sleep to a higher value, for 10 seconds 100 seconds ect, but i dont see any window even attempt to appear, its just like clicking a void button.

Link to comment
Share on other sites

It's actually a problem with your GUIGetMsg() call i think.

this is sloppy, but it works i guess. I'm sure there is a more efficient way to do it though :\

EDIT: Personally, I would use OnEvent mode for any GUI with more than one window open at the same time...

$Main = GUICreate("Title - Main",150,350)
GUISetBkColor(0x000000)
$Input = GUICtrlCreateButton("Button 1",5,10,140,20)
$Input2 = GUICtrlCreateButton("Button 2",5, 50, 140, 20)
MsgBox(0,'Title', "Made By: Feonix")
GUISetState(@SW_SHOW, $Main)
While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case -3;$GUI_EVENT_CLOSE
            Exit
        Case $Input
            $GUI1 = GUICreate("Button Window",150,200)
            GUISetState(@SW_SHOW, $GUI1) 
            Do
                $Msg2 = GUIGetMsg(1)
            Until $Msg2[1] = $GUI1 and $Msg2[0] = -3;$GUI_EVENT_CLOSE
            GUIDelete($GUI1)
    EndSwitch
WEnd
Edited by Paulie
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...