Sign in to follow this  
Followers 0
nitekram

Button Not Working - Child Windows, GUIOnEventMode

7 posts in this topic

#1 ·  Posted (edited)

I have the following code: I cannot get the last button in the third GUI to do anything. Can a NEW pair of eys check it out and see what I did wrong?

#include <GUIConstantsEx.au3>

Global $_GuiAir, $_Button666, $bPassed = False, $_GuiName

Example()

Func Example()
Opt("GUIOnEventMode", 1)

GUICreate("Parent1")
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")

GUICtrlCreateButton("New Gui", 10, 60, 50)
GUICtrlSetOnEvent(-1, "_Air")

GUISetState(@SW_SHOW)

; Just idle around
While 1
Sleep(10)
WEnd

EndFunc ;==>Example

Func _Air()
$_GuiAir = GUICreate('Air Call')
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
$_Button666 = GUICtrlCreateButton('TestIT', 0, 0)
GUICtrlSetOnEvent($_Button666, "__AirCall")

GUISetState(@SW_SHOW, $_GuiAir)
EndFunc ;==>_Air

Func __AirCall()
Switch @GUI_CtrlId
Case $_Button666
;MsgBox('', '', 'pop')
Name('name')
If $bPassed Then
GUISetState(@SW_HIDE, $_GuiName)
GUIDelete($_GuiName)

GUISetState(@SW_HIDE, $_GuiAir)
GUIDelete($_GuiAir)
$bPassed = False
EndIf

EndSwitch
EndFunc ;==>__AirCall

Func Name($sName)
Local $font = "Comic Sans MS"
$sAnswer = $sName

$_GuiName = GUICreate('Air Check' & $sName, 400, 200)
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")

;GUICtrlCreateLabel($sName, 50, 5, 200, 50)
;GUICtrlSetFont(-1, 20, 400, 1, $font)

;$_InputCheck = GUICtrlCreateInput('', 50, 100, 200, 50)
;GUICtrlSetFont(-1, 20, 400, 1, $font)

$_ButtonCheck = GUICtrlCreateButton('CHECK', 20, 150, 50, 30)
GUISetOnEvent($_ButtonCheck, 'test')

GUISetState(@SW_HIDE, $_GuiAir)
GUIDelete($_GuiAir)

GUISetState(@SW_SHOW, $_GuiName)
EndFunc ;==>Name


Func test()

MsgBox('', '', 'button pressed')
EndFunc ;==>test

Func SpecialEvents()
Select
Case @GUI_CtrlId = $GUI_EVENT_CLOSE
MsgBox(0, "Close Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)
Exit

Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE
MsgBox(0, "Window Minimized", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)

Case @GUI_CtrlId = $GUI_EVENT_RESTORE
MsgBox(0, "Window Restored", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)

EndSelect
EndFunc ;==>SpecialEvents
Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites



Which one is the third GUI and which button, just so I don't have to start counting GUI functions.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

$_GuiName is the third gui - in the function Name()


All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

Change the second line:

$_ButtonCheck = GUICtrlCreateButton('CHECK', 20, 150, 50, 30)
GUICtrlSetOnEvent($_ButtonCheck, 'test') ; <<<<<<<<<<<<<<<<< Change it to this


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

I feel stupid - thanks


All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

No need to feel stupid, sometimes Scite's "intellisense" gives you options and we don't pay close enough attention. Happens to me all of the time.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

$_ButtonCheck = GUICtrlCreateButton('CHECK', 20, 150, 50, 30)
GUICtrlSetOnEvent(-1, "Buttontest") ; or you can do it like this, this way you wont get confused with a bunch of variable names

Edited by Cid

[u]My dream is to have a dream...[/u]

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

  • Similar Content

    • Kovacic
      GUIOnEventMode help needed, only 1 button seems to work
      By Kovacic
      Semi experienced developer here.. I have never fully gotten the handle of using GUIOnEventMode, so i thought I would try it with a small simple program that I can paste some text into, then have it count down, and type it out for me.. I use this for when I am iLO into a server and I cant paste. For those of you not familiar with iLO, it stands for Integrated Lights Out. in short, it lets you remote into a server even if its having BIOS issue and wont start.. more details here: http://www8.hp.com/us/en/products/servers/ilo/
       
      Anyway, when in iLO, you cant paste anything. Sometimes I need to copy bash scripting from my computer to the server, so I drop it in the little app, then use it to type out the script in the iLO screen. I have it so it does a countdown before sending the keys, and a delay between each key ( because iLO will sometimes hang up a little ). 
       
      The app I am trying to write will count down, then send whatever is in the edit box. I also have a stop button in case you want to stop the app, but that doesn't seem to do anything. I feel like I'm using GUIOnEventMode improperly. Can someone take a peek?
      #include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> ;Opt                                     ("GUICoordMode", 2) Opt                                      ("GUIResizeMode", 1) Opt                                      ("GUIOnEventMode", 1) GUISetOnEvent                            ($GUI_EVENT_CLOSE, "SpecialEvents") GUISetOnEvent                            ($GUI_EVENT_MINIMIZE, "SpecialEvents") GUISetOnEvent                            ($GUI_EVENT_RESTORE, "SpecialEvents") $Form1 = GUICreate                       ("Sender", 615, 438, 192, 124) $edit = GUICtrlCreateEdit                ("", 8, 128, 601, 305) $stop = GUICtrlCreateButton              ("STOP", 496, 60, 100, 25) GUICtrlSetOnEvent                        (-1, "stop") $SEND = GUICtrlCreateButton              ("SEND", 496, 88, 100, 25) GUICtrlSetOnEvent                        (-1, "sendit") $SecsToWaitB4Sending = GUICtrlCreateInput("10", 200, 32, 145, 25) GUICtrlCreateLabel                       ("Seconds to wait before sending", 40, 32, 153, 17) GUICtrlCreateLabel                       ("Delay between char sent in ms.", 40, 64, 152, 17) $MSBetweenLEtters = GUICtrlCreateInput   ("100", 200, 64, 145, 25) GUISetState                              (@SW_SHOW) While 1     Sleep(5) WEnd Func stop()     GUICtrlSetData($SEND, "SEND") EndFunc   ;==>stop Func sendit()     Local $h = Int(GUICtrlRead($SecsToWaitB4Sending))     GUICtrlSetData($SEND, "Waiting")     For $i = 1 To Int(GUICtrlRead($SecsToWaitB4Sending))         GUICtrlSetData($SEND, $h)         For $c = 1 To 100             Sleep(1)         Next         $h -= 1     Next     GUICtrlSetData($SEND, "Typing")     Opt("SendKeyDelay", Int(GUICtrlRead($MSBetweenLEtters)))     Send(GUICtrlRead($edit), 1)     GUICtrlSetData($SEND, "SEND") EndFunc   ;==>sendit Func SpecialEvents()     Select         Case @GUI_CtrlId = $GUI_EVENT_CLOSE             Exit         Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE             ;         Case @GUI_CtrlId = $GUI_EVENT_RESTORE             ;     EndSelect EndFunc   ;==>SpecialEvents  
       
       
      Thanks in advance!
       
       
    • 31290
      Can't figure why button not working
      By 31290
      Hi everyone, 
      I'm requesting your help over here because I can't figure something that is going to pull all of my hear and, if possible, I would like to make another ask.
      Here's the deal:
      #include <FileConstants.au3> #include <Array.au3> #include <ButtonConstants.au3> #include <ColorConstants.au3> #include <ComboConstants.au3> #Include <Constants.au3> #include <Crypt.au3> #include <Date.au3> #include <File.au3> #Include <FontConstants.au3> #include <GUIConstantsEx.au3> #include <GuiEdit.au3> #include <GuiListView.au3> #include <GuiMenu.au3> #include <Misc.au3> #include <MsgBoxConstants.au3> #include <ProgressConstants.au3> #include <ScreenCapture.au3> #include <StaticConstants.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> Global $FileChosen = "" ; Global $Images = "C:\SAC_IS\ATL_Laptop\Resources\Images\" Global $UploadSource = "" Global $UploadDest = "\\epeldol01\Automated Task List Suite\Bug Tracker\" Opt("GUIOnEventMode", 1) UploadGui() Func UploadGui() ;ADD SMALL ICON! ; e.g GUISetIcon ($Images & "\ResultsGUI.ico") Global $UploadGui = GUICreate ("Upload", 300, 300, -1, -1) ; GUICtrlCreatePic ($Images & "\SAClogo.jpg", 30, 10, 240, 80) GUISetBkColor ($Color_White) GuiCtrlCreateLabel ("-- ATLS BUG TRACKER --", 85, 100, 150, 25) GUICtrlSetFont (-1, 8.5, 700, 0) GUICtrlCreateLabel ("-Step one:", 10, 130, 100, 30) GUICtrlSetFont (-1, 8.5, 700, 0) GUICtrlCreateButton ("Choose file to upload", 90, 125, 120, 25) GUICtrlSetOnEvent (-1, "_ChooseFile") GuiCtrlCreateLabel ("-Step two:", 10, 170, 100, 30) GUICtrlSetFont (-1, 8.5, 700, 0) GUICtrlCreateButton ("Give us details", 100, 165, 100, 25) GUICtrlSetOnEvent (-1, "_Details") GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit", $UploadGui) ; GUICtrlSetOnEvent (-1, "_UploadFile") ; Global $NameOfFile = While 1 GuiSetState (@SW_SHOW) WEnd EndFunc Func _ChooseFile() ; Display an open dialog to select a file. Global $UploadSource = FileOpenDialog("Select File to Upload", @HomePath & "\", "Images (*.jpg;*.bmp)") ; If $UploadSource <> "" Then ; GUISetOnEvent EndFunc Func _UploadFile() If $UploadSource = "" Then MsgBox ($MB_SYSTEMMODAL, "", "No file was selected. Choose a file first!") Else _CopyToLdrep($UploadSource, $UploadDest) EndIf EndFunc ;Upload Function ; Func _CopyToLdrep ($fromfile, $tofile) ; Local $FOF_RESPOND_YES = 16 ; Local $FOF_SIMPLEPROGRESS = 256 ; $winShell = ObjCreate ("shell.application") ; $winShell.namespace ($tofile).CopyHere ($fromFile, $FOF_RESPOND_YES) ; EndFunc ;Details Function Func _Details() Opt("GUIOnEventMode", 1) $DetailsGui = GUICreate ("Details", 300, 400, -1, -1) ; GUICtrlCreatePic ($Images & "\SAClogo.jpg", 30, 10, 240, 80) GUISetBkColor ($Color_White) GuiCtrlCreateLabel ("-- ATLS BUG TRACKER --", 85, 100, 150, 25) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GuiCtrlCreateEdit ("Please describe the context, Date & Time, etc..." & @CRLF & "Also, provide your name and phone number just in case.", 5, 100, 290, 250) GuiCtrlCreateButton ("Submit", 125, 370, -1, -1) GuiCtrlSetOnEvent (-1, "_Submit") While 1 GuiSetState (@SW_SHOW) Wend EndFunc Func _Exit() Exit EndFunc Func _Submit() msgbox (0, "re", "re") EndFuncI'm trying to create a sort of upload module for my techs to be able to submit "bugs"... The first GUI works perfectly but when I want to "Submit" the text they entered there's no way that button is working. I can't even close the windows with the little cross. But, when isolating the function and running it like:
      #include <FileConstants.au3> #include <Array.au3> #include <ButtonConstants.au3> #include <ColorConstants.au3> #include <ComboConstants.au3> #Include <Constants.au3> #include <Crypt.au3> #include <Date.au3> #include <File.au3> #Include <FontConstants.au3> #include <GUIConstantsEx.au3> #include <GuiEdit.au3> #include <GuiListView.au3> #include <GuiMenu.au3> #include <Misc.au3> #include <MsgBoxConstants.au3> #include <ProgressConstants.au3> #include <ScreenCapture.au3> #include <StaticConstants.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> test() Func test() Opt("GUIOnEventMode", 1) $DetailsGui = GUICreate ("Details", 300, 400, -1, -1) ; GUICtrlCreatePic ($Images & "\SAClogo.jpg", 30, 10, 240, 80) GUISetBkColor ($Color_White) GuiCtrlCreateLabel ("-- ATLS BUG TRACKER --", 85, 100, 150, 25) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GuiCtrlCreateEdit ("Please describe the context, Date & Time, etc..." & @CRLF & "Also, provide your name and phone number just in case.", 5, 100, 290, 250) GuiCtrlCreateButton ("Submit", 125, 370, -1, -1) GuiCtrlSetOnEvent (-1, "_Submit") GuiSetState (@SW_SHOW) While 1 Sleep (10) Wend EndFunc Func _Exit() Exit EndFunc Func _Submit() msgbox (0, "re", "re") EndFuncThis is working nicely and my msgbox proves it.
      Second ask is that when a tech finished to choose a file and when he clicked on the "Submit" button, how can I add some "checkmark" meaning this is done and that he can perform the upload? (Indeed, both conditions must me fulfilled to send files to the server). Or maybe a disabled "Send files" button... But I can't figure that out.
      Thanks very much in advance for the help you could provide
      See ya
    • hannes08
      GUIOnEvent and Variable number of Controls
      By hannes08
      Hi Folks,

      maybe this is a stupid question, but anyway here it goes.

      I have a Script in GUI mode running on event mode.
      I also have a variable number of buttons the user may press.
      This is an example of how I'm doing it right now:

      Dim $aButtons[4] Opt("GUIOnEventMode", 1) GUICreate("MyGUI", 800, 600, -1, -1, BitOr($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_THICKFRAME, $WS_MAXIMIZEBOX)) GuiSetOnEvent($GUI_EVENT_CLOSE, "ClickClose") _CreateButtons(4) GUISetState(@SW_SHOW) While 1 Sleep(1000) WEnd Func _CreateButtons($iAmount) Local $x, $y For $i = 1 To $iAmount $aButtons[$i] = GUICtrlCreateButton("Button " & $i, 10 + $i * 50, 30 + $y, 40, 40) GuiCtrlSetOnEvent(-1, "ClickButton" & $i) If $i >= $iAmount / 2 Then $y = 70 Next EndFunc Func ClickClose() Exit EndFunc Func ClickButton1() _ClickedButton(1) EndFunc Func ClickButton2() _ClickedButton(2) EndFunc Func ClickButton3() _ClickedButton(3) EndFunc Func ClickButton4() _ClickedButton(4) EndFunc Func _clickedButton($id) ConsoleWrite("Well, now you've clicked on " & $id & @CRLF) EndFunc
      The "problem" is that I need to create a function for each button, which I believe is suboptimal.
      The amount of available buttons is configurable over an ini file, so it's not hard-coded as in the example.

      Any hint is appreciated.