Sign in to follow this  
Followers 0
brett

Where Is Helloworld

17 posts in this topic

i saw this as an example for the GUI, but can't find it anywhere.


-Brett

Share this post


Link to post
Share on other sites



Brett, every function has a example below. :huh2:

Generally, the examples are simples. For easy understanding.

"Hello World" example, is a way to mention a script for start to learn. (If you sayed for this post)

:D

Share this post


Link to post
Share on other sites

; a basic GUI equivalent to $input= InputBox ("Hello World", "Name?")

GuiCreate ("Hello World") ; start the definition 
    
GuiSetControl ("label", 'Name?', 10,10); add prompt info 
$nInput = GuiSetControl ("input", "", 10,30,200) ; add the input area 
$nOk    = GUISetControl ("button", "OK", 20,70); add the button that will close the GUI 
    
GuiWaitClose (); to display the dialog box 
    
if $nOK= GuiRead () then; to verify if OK was click 
  $input = GuiRead ($nInput); get the type value 
  msgbox(0,"Greeting","Hello " & $input); will display the typed value 
endif

ok, a bit more complex than most hello world starters.


AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

; a basic GUI equivalent to $input= InputBox ("Hello World", "Name?")

GuiCreate ("Hello World"); start the definition 
    
GuiSetControl ("label", 'Name?', 10,10); add prompt info 
$nInput = GuiSetControl ("input", "", 10,30,200); add the input area 
$nOk    = GUISetControl ("button", "OK", 20,70); add the button that will close the GUI 
    
GuiWaitClose (); to display the dialog box 
    
if $nOK= GuiRead () then; to verify if OK was click 
  $input = GuiRead ($nInput); get the type value 
  msgbox(0,"Greeting","Hello " & $input); will display the typed value 
endif

ok, a bit more complex than most hello world starters.

I've not used the gui code yet (too busy implementing...) but how can I modify this script so that pressing enter clicks OK, and can you add an accelerator to OK (Alt+O for example for the label &OK)?

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Jon, simply adding an ampersand before the letter you want the accelerator to be. In that example's case, just make the button text "&Ok".

As for your second request (Well, first, really...), I don't know how to do that short of trapping enter with a hotkey and translating that to what button should be pressed if the GUI has focus or letting it fall back through to any other window. That's not possible with that simple GUI, though. WinWaitClose() is a blocking call like MsgBox() or InputBox() so hotkeys don't work. It would require a polling message pump to implement. Something like this (This is a little buggy with the message box because Enter won't work in it, but it's easy to fix):

Opt("GuiNotifyMode", 1)
GuiCreate ("Hello World"); start the definition 
   
GuiSetControl ("label", 'Name?', 10,10); add prompt info 
$nInput = GuiSetControl ("input", "", 10,30,200); add the input area 
$nOk    = GUISetControl ("button", "&OK", 20,70); add the button that will close the GUI 

GuiShow()

HotKeySet("{ENTER}", "Callback")

While WinExists("Hello World")
    $msg = GuiMsg(0)
    If $msg = -3 Then
        GuiDelete(); Force exit from While loop
    ElseIf $msg = $nOk Then
        $input = GuiRead ($nInput); get the type value 
        msgbox(0,"Greeting","Hello " & $input)
    EndIf
Wend

Func Callback()
    If WinActive("Hello World") Then 
        ControlClick("Hello World", "", "&OK")
    Else
        HotKeySet("{ENTER}")
        Send("{ENTER}")
        HotKeySet("{ENTER}", "Callback")
    EndIf
EndFunc
Edited by Valik

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Jon, simply adding an ampersand before the letter you want the accelerator to be.  In that example's case, just make the button text "&Ok". 

I tried that and it changed the label but ignored the key press. I'll try again.

Edit: Still no joy.

Edited by Jon

Share this post


Link to post
Share on other sites

I tried that and it changed the label but ignored the key press.  I'll try again.

Edit: Still no joy.

An OS thing, perhaps? In that code I posted, I can press Alt+O to activate the okay button.

Share this post


Link to post
Share on other sites

works for me:

Opt("GuiNotifyMode", 1)
GuiCreate ("Hello World"); start the definition
 
GuiSetControl ("label", 'Name?', 10,10); add prompt info
$nOk    = GUISetControl ("button", "&OK", 20,70); add the button that will close the GUI
$nInput = GuiSetControl ("input", "", 10,30,200); add the input area

GuiShow()

HotKeySet("{ENTER}", "Callback")

While WinExists("Hello World")
   $msg = GuiMsg(0)
   If $msg = -3 Then
       GuiDelete(); Force exit from While loop
   ElseIf $msg = $nOk Then
       $input = GuiRead ($nInput); get the type value
       GuiDelete(); Force exit from While loop
       msgbox(0,"Greeting","Hello " & $input)
   EndIf
Wend

Func Callback()
   If WinActive("Hello World") Then
       ControlClick("Hello World", "", "&OK")
   Else
       HotKeySet("{ENTER}")
       Send("{ENTER}")
       HotKeySet("{ENTER}", "Callback")
   EndIf
EndFunc

AutoIt3, the MACGYVER Pocket Knife for computers.

Share this post


Link to post
Share on other sites

Something really screwy here, if I run it 20 times it will sort of work 5 times and do nothing the other times. Sometimes tab works and sometimes not. Sometimes ALT+O will work, but only if focus is not in the edit field...and then not always..

Share this post


Link to post
Share on other sites

Jon, take a look at this post for some info....

I took the HotKeySet out and I still get it.

This seems to work everytime:

GUICreate("My GUI")
GUISetControl("button", "Boo", 0,50)
GUISetControl("button", "&OK", 100,50)

While GuiMsg () > 0     
  MsgBox(0,"", "OK Clicked",2)
Wend

But the code in this thread doesn't...

Share this post


Link to post
Share on other sites

I get the same behavior as Jon now. I must of tested with the orginal snippet posted, as my modified message pump version doesn't work.

Share this post


Link to post
Share on other sites

GuiMsg([timeout]) and GuiMsg() block everything until a message is received. GuiMsg(0) polls for new messages, but leaves the thread active. I bet there is some different way going on behind the scenes that is causing these issues with how JP has these various ways of getting messages set up.

Share this post


Link to post
Share on other sites

why will this not work? i want to press enter to finish the gui, like jon said.

$nOk    = GUISetControl ("button", "&Start", 20,200)

-Brett

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