Sign in to follow this  
Followers 0
Leo1906

GUIOnEventMode for only one GUI?

6 posts in this topic

I read about GUIOnEventMode while making my research and I found out that you can't use 

Opt("GUIOnEventMode", 1)

and

$msg = GUIGetMsg()

at the same time. So far so good.
In my script I am spawning a few child GUIs and only for the main GUI I need interaction with buttons etc.
My question now is, is it possible to set those flags specifically for a single GUI? Can I somehow pass the handle to a GUI this option should affect? And for the main GUI I use GuiGetMsg?

I hope you can understand what I'm trying to do .. :D

 

Thanks for your help :)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You can't use both at the same time but you can do it successively by switching the option  :)

#include <GUIConstantsEx.au3>

$gui1 = GUICreate("gui1", -1, -1, 100, 100)
$btn1 = GuiCtrlCreateButton("button 1", 20, 20, 80, 30)
GUISetState()

$gui2 = GUICreate("gui2", -1, -1, 150, 150)
$btn2 = GuiCtrlCreateButton("button 2", 20, 20, 80, 30)
GUISetState()

While 1
  If WinActive($gui2) Then
     Opt("GUIOnEventMode", 1)
     GUISetOnEvent($GUI_EVENT_CLOSE, "_events")
     GUICtrlSetOnEvent($btn2, "_events")
  Else
     Opt("GUIOnEventMode", 0)
     Switch GuiGetMsg()
         Case $GUI_EVENT_CLOSE 
            Exit Msgbox(0,"", "exit guigetmsg")
         Case $btn1 
            Msgbox(0,"", "button 1 pressed")
      EndSwitch
  EndIf
  Sleep(10)
WEnd

Func _events()
     Switch @GUI_CtrlId
         Case $GUI_EVENT_CLOSE 
              GuiDelete(@GUI_WinHandle)
              Msgbox(0,"", "exit onevent")
         Case $btn2 
              Msgbox(0,"", "button 2 pressed")
      EndSwitch
EndFunc

But it's a strange idea. Why not use the same mode for all gui ? 

BTW _ArrayDisplay is an example of this switching, it uses internally GuiGetMsg regardless of the mode used in the main script

Edited by mikell

Share this post


Link to post
Share on other sites
10 hours ago, Leo1906 said:

I read about GUIOnEventMode while making my research and I found out that you can't use 

Opt("GUIOnEventMode", 1)

and

$msg = GUIGetMsg()

at the same time

At same time isn't possible:

  • When GUIOnEventMode is active, only GUICtrlSetOnEvent functions are working, GuiGetMsg works not
  • When GUIOnEventMode is disabled, GUICtrlSetOnEvent functions are not working, GuiGetMsg works

But it is correct you can mix both in one script, but i think this not a good idea for newbe like you.

Share this post


Link to post
Share on other sites

Ah ok I understand now. Didn't knew it was that simple to switch the mode.
I'll figure it out how to use and switch those modes .. :D

Thanks guys! :)

Share this post


Link to post
Share on other sites
3 hours ago, Leo1906 said:

I'll figure it out how to use and switch those modes .. :D

why? there is no need to do this:

17 hours ago, Leo1906 said:

In my script I am spawning a few child GUIs and only for the main GUI I need interaction with buttons etc.

 

Share this post


Link to post
Share on other sites

Yeah I now noticed that there is no need for it. You were right.
I thought it would be necessary to register functions like WM_NCHITTEST and others and I wasn't sure about how to make my buttons etc usable at the same time, but the script that mikell postet shows a solution to this.

But to use WM_NCHITTEST it's not requiered to use  Opt("GUIOnEventMode", 1)  so the question was unnecessary .. :/

But nevertheless it helped me understand how to make buttons usable when the mode is switched .. :>

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

    • shotiko
      GUIState 7 OnEvent
      By shotiko
      here I am writing simple gui with text processing capabilities.
      i have main gui, background picture, all buttons with labels over them 2 static buttons (1 present here)
      Opt("GUIOnEventMode", 1) and includes
      $main = GUICreate("Title", 961, 721); Main Window $bgpic = GUICtrlCreatePic(@WorkingDir & "\960x720.jpg", 0, 0, 960, 720); use background picture $quitBtn = GUICtrlCreateButton("Quit", 885, 685, 95, 40) GUICtrlSetOnEvent($quitBtn, "_exit"); assign quit button to function "exit" _GuiCtrlMakeTrans(-1, 1) $quitLabel = GUICtrlCreateLabel("Quit", 885, 685, 95, 40, BitOR($SS_CENTER, $BS_BOTTOM)) GUICtrlSetFont(-1, 14, 400, 0, "Tahoma") GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetColor(-1, 0x962129) GUISetState(@SW_SHOW)
      then i have the code for creating buttons dynamically from information in file
      Dim $Button[$NumberFromText] $startX = 48 $startY = 24 $fromLeft = 240 $bHeigh = 160 $bWidth = 50 Dim $1to4btn[0] For $x = 0 To _Min(UBound($Button) - 1, 3) ; creates maximum 4 button, label $Button = GUICtrlCreateButton($x, $startX, $startY, $bHeigh, $bWidth); create buttons _GuiCtrlMakeTrans(-1, 1) ; transparency 255 Solid, 0 Transparent $serverLabel = GUICtrlCreateLabel(FileReadLine($configF, $SN), _ ; read 1st line and 5 below on each iteration $startX, $startY, $bHeigh, $bWidth, BitOR($SS_CENTER, $SS_CENTERIMAGE, $WS_EX_TRANSPARENT)); GUICtrlSetFont(-1, 14, 400, 0, "Tahoma"); set font and size GUICtrlSetColor($serverLabel, 0x04A111); set color of font GUICtrlSetBkColor($serverLabel, $GUI_BKCOLOR_TRANSPARENT); make label Background transparent $SN += 5; read 5 lines below $startX = $startX + $fromLeft $btnArray=_ArrayAdd($1to4btn, GUICtrlGetHandle($Button)) Next since buttons are created under the label $Button and I couldn't conacenate $Button[$i] , I created array and place handles into it and connected static buttons with
      GUICtrlSetOnEvent($cancelBtn,"cancelFunc") and it worked
      now i tried using handles to assign functions to buttons but it fails with GUICtrlSetOnEvent()
      also tried GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "funcForFirstButton", $1to4btn[0])
      if I assign without handle it works by clicking anywhere on MainGUI
      While loop includes only sleep(10)
       
      Window starts as inactive and return code 7
      If i click dynamically created buttons, window loses focus . clicking anywhere else focuses window
       
      this is _GuiCtrlMakeTrans function (found here on forums some time ago)
      also created simple button on the same mainGUI and tried but didn't work
      $try=GUICtrlCreateButton("TRY",250,150,100,35) GUICtrlSetOnEvent(-1,"FunctionOne") ; shows messagebox and write console  
    • 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") EndFunc I'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") EndFunc This 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
    • TheAutomator
      $GUI_EVENT_CLOSE with ESC not working in new loop
      By TheAutomator
      Hi everyone,
      Does anyone know why the ESC button doesn't close my form in the second loop?
      #include <GUIConstantsEx.au3> GUICreate('test', 600, 400, -1, -1) $BTN = GUICtrlCreateButton("Press", 10, 10, 80, 30) GUISetState(@SW_SHOW) While True     Switch GUIGetMsg()         Case $GUI_EVENT_CLOSE             Exit         Case $BTN             ExitLoop     EndSwitch WEnd ConsoleWrite("Second Loop" & @CRLF) GUICtrlDelete($BTN) While True     Switch GUIGetMsg()         Case $GUI_EVENT_CLOSE             ;just hear the 'ding' sound if i press ESC...             Exit     EndSwitch WEnd Regards
      TheAutomator.
    • nitekram
      Button Not Working - Child Windows, GUIOnEventMode
      By nitekram
      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