Jump to content

My very first GUI help plz.


Recommended Posts

Hey I'm trying to make my first GUI ever.. hm.. i used search tool to find a post that showed a simple working GUI but.. I don't want to copy and paste it.. i feel like i learn less that way.. so this is what i made on my own.. it like shows up.. but then flashes and closes.. why is that? hm.. and in the example it used Case what is that? lol i'm such a noob.. first i'm wanting to make a GUI that will open up a file or folder or in this case simple click bot.au3 that i made before.. this is my simple code. I'm looking for the simplest way to make a GUI and 1 button. Thanks ^_^

#include <GuiConstantsEX.au3>

MyGui()

Func MyGui()
        GUICreate("Click Bot", 400, 500)
        GuiSetState(@SW_SHOW)
        If Not @error Then
            GUICtrlCreateButton("Run - Simple Click Bot.au3",40,50)
            EndIf
        EndFunc
Link to comment
Share on other sites

The basics of using a GUI is understanding that the script will run the lines you give it then exit. For a constant running program, like a GUI, we need the script to remain. Thus it needs to loop till we tell it to exit. In the basics of GUI we use a messageloop mode. Everytime it loops it checks for a response. If there is a response it uses an if or a case statement to check if the values equal various buttons and actions that you can control what it does in case "they" clicked that.

#include <GUIConstantsEx.au3>

GUICreate("Hello World", 200, 100);<<<<<<<<<<<<<<define gui
GUICtrlCreateLabel("Hello world! How are you?", 30, 10);<<<<<<<<<<define a control
$okbutton = GUICtrlCreateButton("OK", 70, 50, 60);<<<<<<<<<define another contrl
GUISetState(@SW_SHOW) ;<<<<<<<<show gui

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; now run the gui

While 1
  $msg = GUIGetMsg();<<<<<<<<<<<<<<check what is pressed

  Select
    Case $msg = $okbutton;<<<<<<<<<<<<<< if ok then do the following lines
      MsgBox(0, "GUI Event", "You pressed OK!")

    Case $msg = $GUI_EVENT_CLOSE;<<<<<<<<<<<<<<<<<<if close the do the follinging lines.
      MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...")
      ExitLoop
  EndSelect
WEnd

The other usable mode is the event mode where all actions can be placed inside seperate functions.

The help file does a good job of explaining. Just search for GUI concepts.

Hope it helps.

Cheers

Link to comment
Share on other sites

I would recommend to use http://www.autoitscript.com/fileman/users/lookfar/formdesign.html for GUI...

edited:

It has user-based interface and quite full data (or even full data) of all GUI form that can be done by Autoit

Edited by P0ZiTR0N
Link to comment
Share on other sites

Try adding

While 1

sleep(1000)

wend

after the MyGui() function call

Hope that helps

NBJ

Tried this first, it made the GUI show up correctly.. but.. it opened it like a loop over and over and over and over and over lol so didn't use that.

Here's my attempt at the same thing. Hope it helps

Global $msg
Global $gui, $button

$gui = GUICreate("Click Bot", 400, 500)
$button = GUICtrlCreateButton("Run - Simple Click Bot.au3",40,50)

GUISetState()

Do
   $msg = GUIGetMsg()

   If ($msg = $button) Then
     ;do your stuff here
   EndIf
Until ($msg = -3) ;the exit code
This helped the most thank you very much crzftx :D I re-wrote it and added stuff my own way so i learned what everything did ^_^ Thank you so much. My script works now and i added a hotkey.. and didn't know what your -3 did.. but noticed the GUI would not close by clicking the X button.. tried adding that part.. and then it worked so that's what that does! And I still don't get the point of GUIGetMsg tho.. looked it up in online documentation still doesn't make sense haha maybe my english is bad. And what's the point of putting ()'s around the ($msg=-3)? Anyways thanks a lot ;)

@Stampy - Thank you very much for your reply :) your way works too but it just seems more in depth and complicated to me :D You explained it well with your in-script notes. lol you make me think of Autoit like math.. there's several different ways to write something or do a problem.

Assuming you really do want to learn and not take the easy way out . . . (there's nothing wrong with needing help. -I still have atleast a question or two a month.)

Get a great tutorial here . . .

http://www.autoitscript.com/forum/index.php?showtopic=21048

I really do want to learn. I've been playing video games since I was 3, then in 5th grade got my first computer and played online games since then till now and I'm 19 and about to attend at a University. Gaming is entertainment but something like programming or scripting with Autoit can be way more productive but still addicting and fun at the same time and not everyone can do it or put the time or effort into learning it. I want to.. i just hope i don't get discouraged or give up. I keep learning more and more with every attempt i make. But the hard part for me is I can't find interesting projects to make.. I wanted my big goal to be a bot for diablo 2 but the pathing is too hard and it'd be too advanced and like they say it's harder to get support for a gamebot haha.

Oh and I tried to get Autoit 1-2-3 to work.. and when i try to use the example scripts i always get errors and stuff.. every time i've downloaded it.. so i just gave up on that.

I would recommend to use http://www.autoitscript.com/fileman/users/lookfar/formdesign.html for GUI...

edited:

It has user-based interface and quite full data (or even full data) of all GUI form that can be done by Autoit

I saw the option of using Koda when i used search tool to look for simple GUI ideas but I don't think i'm going to be making extremely complex GUI's and not often so i'd rather learn the old fashion way :( Why use a program to write a program when you're trying to learn to program? Haha

Thank you for all your replies and comments and suggestions. Next i'm going to try to make this GUI work with my clickbot I made not long ago.

How can I put the URL of the flash game INSIDE the GUI?

Oh and here is my working first GUI!

#include <GuiConstants.au3>

Dim $getmess
Dim $guic, $guib
Dim $Cl = True
Dim $Ex = False

HotKeySet("{F10}","Cl")

$guic = GUICreate("My First GUI",330,220)
$guib = GuiCtrlCreateButton("Check It",50,50,100,50)

Func Cl()
    Exit
EndFunc

    
GUISetState()

Do
    $getmess = GUIGetMsg()
    
    If ($getmess = $guib) Then
        MsgBox(0,"Dun dun dun","Woot, it worked!")
    EndIf
    
Until $Ex Or ($getmess = -3)
Link to comment
Share on other sites

Slightly improved code:

#include <GuiConstants.au3>

HotKeySet("{F10}","Cl")

$guic = GUICreate("My First GUI",330,220)
$guib = GuiCtrlCreateButton("Check It",50,50,100,50)
GUISetState(@SW_SHOW)

While 1
 $msg = GuiGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then
    Exit
 EndIf
 
    If $msg = $guib Then
        MsgBox(0,"Dun dun dun","Woot, it worked!")
    EndIf
WEnd

Func Cl()
 If WinActive($guic) Then
    Exit
 Else
    HotKeySet("{F10}")
    Send("{F10}") ; to be working F10 in other applications
    HotKeySet("{F10}", "Cl")
 EndIf
EndFunc

Func OnAutoItExit()
 HotKeySet("{F10}")
EndFunc
Link to comment
Share on other sites

Better code using GUISetAccelerators() instead of HotKeySet()

Look here for more details http://www.autoitscript.com/forum/index.php?showtopic=66650

#include <GuiConstants.au3>

$guic = GUICreate("My First GUI",330,220)
$guib = GuiCtrlCreateButton("Check It",50,50,100,50)
$ExitID = GUICtrlCreateDummy()

Dim $AccelKeys[1][2]=[["{F10}", $ExitID]]
GUISetAccelerators($AccelKeys)

GUISetState(@SW_SHOW)

While 1
 $msg = GuiGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Or $msg = $ExitID Then
    Exit
 EndIf
 
    If $msg = $guib Then
        MsgBox(0,"Dun dun dun","Woot, it worked!")
    EndIf
WEnd
Edited by Zedna
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...