Jump to content

Recommended Posts

Posted

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 :)

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
Posted
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.

Posted

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! :)

Posted
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.

 

Posted

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 .. :>

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
×
×
  • Create New...