Sign in to follow this  
Followers 0
myxomatosii

I Am Learning Basic GUI Strategies

5 posts in this topic

#1 ·  Posted (edited)

Hey guys, I am just learning how to make GUI in AutoIt and I figured I would humble myself and just make my progress public as it may help me.

Features I want in my GUI.. (I may add more to this list.)

0: I want to make a GUI that opens the (current) user's documents folder.

1: GUI window to stay around until its closed manually.

2: Button to be relatively responsive without killing the processor (of ANY reasonable PC).

3: Scale and size of GUI to be fitting to purpose, ie: small.

I just started, working my way through errors to get it at least coming up with a GUI box, so I'll continue to post progress as I figure things out.

I AM aware of how many things I am missing.. like I said I am just learning.. so I hope you're not laughing too hard. >.<

Perhaps if you see some basic necessities I am missing you could point them out, their basic purposes are still confusing to me.

I am using Autoit Documentation on the Autoit site to figure all that I have figured out so far.

CURRENT CODE: Crashed lol, I forgot to set location of the button... duh.

Opt("GUIOnEventMode",1)

docgui()

Func docgui()
    Local $msg
    GUICreate("Document Opener")
    GUISetState(@SW_SHOW)
    GUICtrlCreateButton("Open - My Documents")
    Sleep(200)
EndFunc

CODE UPDATE 1: Window hangs around forever, size is nicer, still doesn't do anything.. infinite loop.

Opt("GUIOnEventMode", 1)

docgui()

Func docgui()
    Local $msg
    GUICreate("DocOpen", 150, 50)
    GUISetState(@SW_SHOW)
    GUICtrlCreateButton("Open - My Documents", 20, 20)
    While 1
        Sleep(2000)
    WEnd
EndFunc;==>docgui
Edited by myxomatosii

Share this post


Link to post
Share on other sites



You seem to have the part that opens My Documents already finished.

For the button, you could do GUIGetMsg() to see if it has been pressed. To save the processor, you could add a sleep(10) in the loop.

GUICreate("Document Opener", @DesktopWidth/3, @DesktopHeight/3)

$Button = GUICtrlCreateButton("Open - My Documents", 5, 5, 75, 23)

GUISetState(@SW_SHOW)

While 1

$msg = GuiGetMsg()

If $msg = $Button Then

; place script to open My Documents here

Endif

Sleep(15)

WEnd

For the size of the window, you could look up the macro @DesktopWidth and @DesktopHeight and set the size of the window to be a certain percentage of the screen.


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

Hey guys, I am just learning how to make GUI in AutoIt and I figured I would humble myself and just make my progress public as it may help me.

Features I want in my GUI.. (I may add more to this list.)

0: I want to make a GUI that opens the (current) user's documents folder.

1: GUI window to stay around until its closed manually.

2: Button to be relatively responsive without killing the processor (of ANY reasonable PC).

3: Scale and size of GUI to be fitting to purpose, ie: small.

I just started, working my way through errors to get it at least coming up with a GUI box, so I'll continue to post progress as I figure things out.

I AM aware of how many things I am missing.. like I said I am just learning.. so I hope you're not laughing too hard. >.<

Perhaps if you see some basic necessities I am missing you could point them out, their basic purposes are still confusing to me.

I am using Autoit Documentation on the Autoit site to figure all that I have figured out so far.

CURRENT CODE: Crashed lol, I forgot to set location of the button... duh.

Opt("GUIOnEventMode",1)

docgui()

Func docgui()
    Local $msg
    GUICreate("Document Opener")
    GUISetState(@SW_SHOW)
    GUICtrlCreateButton("Open - My Documents")
    Sleep(200)
EndFunc

CODE UPDATE 1: Window hangs around forever, size is nicer, still doesn't do anything.. infinite loop.

Opt("GUIOnEventMode", 1)

docgui()

Func docgui()
    Local $msg
    GUICreate("DocOpen", 150, 50)
    GUISetState(@SW_SHOW)
    GUICtrlCreateButton("Open - My Documents", 20, 20)
    While 1
        Sleep(2000)
    WEnd
EndFunc;==>docgui
You have to "watch" for actions within the GUI. Try this:

#include <GUIConstantsEx.au3>

docgui()

Func docgui()
    Local $msg
    GUICreate("DocOpen", 150, 50)
    $button1 = GUICtrlCreateButton("Open - My Documents", 20, 20)
    GUISetState(@SW_SHOW)
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $button1
                ShellExecute(@MyDocumentsDir)
        EndSelect
    WEnd
EndFunc  ;==>docgui

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

You have to "watch" for actions within the GUI. Try this:

#include <GUIConstantsEx.au3>

docgui()

Func docgui()
    Local $msg
    GUICreate("DocOpen", 150, 50)
    $button1 = GUICtrlCreateButton("Open - My Documents", 20, 20)
    GUISetState(@SW_SHOW)
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $button1
                ShellExecute(@MyDocumentsDir)
        EndSelect
    WEnd
EndFunc;==>docgui
Hey thanks everyone, I just finished my first GUI thanks to you guys =)

dantay9: thanks for the great ideas on creating proportional windows sizes ~

erik7426: i thought i may have to use the Select/Case loop but honestly i hadn't had any experience with it before so i was unsure of the format, but i think i understand it now.

now i've got to come up with something a bit more challenging... and i've got to go read up on the shellexcecute command, had never used that before.

i'm sure i'll be posting more questions soon lol, i'm just starting out x,x

if you guys don't mind me asking, why is #include so important in GUI scripts?

Working Code!

#include <GUIConstantsEx.au3>

docgui()

Func docgui()
    Local $msg
    GUICreate("DocOpen", 150, 50)
    GUISetState(@SW_SHOW)
    $button1=GUICtrlCreateButton("Open - My Documents",20,20)
    While 1
        $msg=GUIGetMsg()
        Select
            Case $msg=$gui_event_close
                ExitLoop
            Case $msg=$button1
                ShellExecute(@mydocumentsdir)
        EndSelect
    Sleep(30)
    WEnd
EndFunc  ;==>docgui
Edited by myxomatosii

Share this post


Link to post
Share on other sites

Hi there,

My first script looked excact like it, but more buttons :

I modified it so I could post it here for you, so you could make your GUI even bigger

; Sorry for my bad english, its just school's english

CODE
#include <GUIConstantsEx.au3>

Opt("MustDeclareVars", 0)

examplegui()

Func exampleGUI()

Local $button_1, $button_2, $button_3, $msg ; you can make more like this way and just put more $button_* in. * = number or text.

GUICreate ( "Opener", 111, 111)

Opt("GUICoordMode", 2)

$button_1 = GUICtrlCreateButton ( "Run SciTE", 7, 10, 100)

$button_2 = GUICtrlCreateButton ( "Run Notepad", -1, 10, 100) ; Just 3 examples given to help you on the way.

$button_3 = GUICtrlCreateBUtton ( "Exit", -1, 10, 100)

GUISetState (@SW_SHOW)

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

Case $msg = $button_1

Run ( "C:\Program Files\AutoIt3\SciTE\SciTE.exe" )

Case $msg = $button_2

Run ( "notepad.exe" )

Case $msg = $button_3

MsgBox (0, "Goodbye", "Goodbye", 1)

Exit

EndSelect

WEnd

EndFunc ;==> exampleGUI

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