Jump to content

Recommended Posts

Posted

I am still trying to figure out how to deal with buttons and the onclick event. I assume it has something to do with GUIRecvMsg and GUISendMsg.

Say I have a button with the handle "butOpenNotepad" and one called "butClose" (hee hee)

I want "notepad.exe" to run whenever I press the button "butOpenNotepad"..

I want the whole script to exit when I press "butClose".

So far whenever I play with a button it only closes the whole script.

Anyone?

  • Developers
Posted (edited)

I am still trying to figure out how to deal with buttons and the onclick event. I assume it has something to do with GUIRecvMsg and GUISendMsg.

Say I have a button with the handle "butOpenNotepad" and one called "butClose" (hee hee)

I want "notepad.exe" to run whenever I press the button "butOpenNotepad"..

I want the whole script to exit when I press "butClose".

So far whenever I play with a button it only closes the whole script.

Anyone?

Its easier when you post what you have so we can shoot at it :postal: :D Edited by JdeB

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

Its easier when you post what you have so we can shoot at it  :postal:  :huh2:

I was afraid you were going to say that :D

My current script is very long, so I will whip up a new script just as a test. I'll post it here in a few minutes.

Posted (edited)

#include <GUIConstants.au3>

Dim $GUI

Dim $butNotepad

Dim $buutClose

$GUI = GUICreate('My Test Button GUI')

;I would like it so that when I press this button, it'll perform the following action:

;Run ( 'notepad.exe' )

;Or better yet, execute a Functionn/Subroutine, say openNotepad()

$butNotepad = GUISetControl('button', 'Open Notepad', 5, 5 )

GUISetControlNotify()

$butClose = GUISetControl('button', 'Close this script', 5, 45)

GuiWaitClose ()

Exit

Edited by mlazovjp
  • Developers
Posted

Dim $GUI
Dim $BUTNOTEPAD
Dim $BUUTCLOSE

$GUI = GUICreate('My Test Button GUI')
;I would like it so that when I press this button, it'll perform the following action:
;Run ( 'notepad.exe' )
;Or better yet, execute a Functionn/Subroutine, say openNotepad()
$BUTNOTEPAD = GUISetControl('button', 'Open Notepad', 5, 5)
$BUTCLOSE = GUISetControl('button', 'Close this script', 5, 45)
GUIWaitClose()
if GUIRead() = $BUTNOTEPAD then Run("notepad")
Exit

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

@JdeB

Your code worked when I compiled it. Thanks!

Unfortunately, not having much luck to get it to work with my script.

Am I reading your code correctly - the GUIRead() only occurs once the GUI closes?

I am basically trying to create something similar to the control panel ... making a main window which stays open but will execute other scripts or routines when the appropriate buttons are pressed.

At the moment when I press my test button, the GUI does not go away but it doesn't actually do anything.

I could send you my script if you would be willing to take a look at it.

Posted

What do you have to do in order to keep the GUI open and to still have the ReadMsg() work and execute the proper function/subroutine on a Buttonclick() event??

Posted (edited)

Here is an example that you might find helpfull (I don't know how much you've already recieved in PM's, so I apologize if this overlaps at all.) This script opens a GUI, and will let the user enter text, and click a button. It will exit the script when the proper text is entered into the input box.

GuiCreate("GUI Read Example", 200, 75)
  GuiSetControl("label", 'Enter the text "exit" to quit', 0, 0, 200, 20)
  $input = GuiSetControl("input", "", 0, 25, 200, 20)
  $button = GuiSetControl("button", "Help Button", 0, 50, 100, 20)
    GuiSetControlNotify();create a notify message instead of killing the GUI
GuiShow()

While 1
  Sleep(50);save the CPU from running this more than 20 times a second
  If GuiRead($input) = "exit" Then
    MsgBox(0, "Success", "You exited the script")
    Exit
  EndIf
  $msg = GuiMsg(0)
  If $msg = -3 Then
    MsgBox(0, "Failure", "You did not enter exit, but pressed the red X button")
    Exit
  ElseIf $msg = $button Then
    MsgBox(0, "Example Help", 'Type "exit" into the box to exit the script')
  EndIf
WEnd

Edited to include the Sleep() command inside the loop

Edited by pekster

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Posted

GuiCreate("GUI Read Example", 200, 75)
  GuiSetControl("label", 'Enter the text "exit" to quit', 0, 0, 200, 20)
  $input = GuiSetControl("input", "", 0, 25, 200, 20)
  $button = GuiSetControl("button", "Help Button", 0, 50, 100, 20)
    GuiSetControlNotify();create a notify message instead of killing the GUI
GuiShow()

While 1
  Sleep(50);save the CPU from running this more than 20 times a second
  If GuiRead($input) = "exit" Then
    MsgBox(0, "Success", "You exited the script")
    Exit
  EndIf
  $msg = GuiMsg(0)
  If $msg = -3 Then
    MsgBox(0, "Failure", "You did not enter exit, but pressed the red X button")
    Exit
  ElseIf $msg = $button Then
    MsgBox(0, "Example Help", 'Type "exit" into the box to exit the script')
  EndIf
WEnd

Edited to include the Sleep() command inside the loop

Every example helps. Thank you!

I am beginning to suspect part of my problem was not properly using GuiSetControlNotify().

Assume I have multiple buttons (e.g. butA, butB, butExit), and I only want butExit to close the script.

Do I use GuiSetControlNotify() after the creation of each button or control for which I wish an action to occur upon a state change?

Would I want to use:

AutoItSetOption ( 'GUINotifyMode', 1)

in my situation?

Normally I am one of the people who contributes the help ... I appreciate everyone helping me get a better grasp of the GUI stuff.

Posted (edited)

I am beginning to suspect part of my problem was not properly using GuiSetControlNotify().

OK, after playing around with my code for a few minutes, I see that thee were two key things I was not doing correctly:

1.) Using GuiSetNotify() correctly (I have since added this code after the creation of each button control)

2.) Using GuiMsg(0) to determine which control state has changed. I kept using GuiRead() when I should have been using GuiMsg()!

I have a slightly different problem that I noticed now, and it sounds kinda weird to even be typing it. My script is basically a window with a tab control and four ab items.

The first tab item, 'User Data', has a 'Start' button and a checkbox at the bottom.

The second tab,'Phase One' has a couple of buttons on it.

It looks like I cannot press any of the buttons on the 'Phase One' tab ... they just stay raised and don't click. Sometimes if I go back to the 'User Data' tab and I press the Start button then I can press a button on the 'Phase One' tab.

Edited 05:54 AM

OK, I bumped the Sleep(50 to Sleep(100) and I was able to click on one of the buttons on the 'Phase One' tab right away. After a couple of seconds, though, it was broken again. At least now I have an idea what to screw with.

Edited 05:55 AM

OK, I lied, that doesn't seem to fix it :D

Edited by mlazovjp
Posted

Thanks for all of the suggestions people. I learned a lot from my mistakes :huh2:

For those who are curious, it looks like JdeB here helped me figure out the last problem I was having (namely, I couldn't press some of the buttons at seemingly random times).

The problem ended up being an overlap of controls on one of my tab items. Basically, I had a text label overlap part of the button, so when I tried to click on the button, I was ctually clicking on part of the label! :D

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...