Sign in to follow this  
Followers 0
Synix

Manually fire events registered via GUI[Ctrl]SetOnEvent()

5 posts in this topic

To cut a long story short: I want to use a single entry point for my onevent functions. Is it possible to achieve this by directly firing an event instead of my approach (see example below)?

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
GUICreate("", 220, 30)
GUISetOnEvent($GUI_EVENT_CLOSE, _GUIEventHandler)
$idStartDummy = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, _GUIEventHandler)
$idStart = GUICtrlCreateButton("Start", 5, 5, 100, 20)
GUICtrlSetOnEvent(-1, _GUIEventHandler)
$idLabel = GUICtrlCreateLabel("", 110, 5, 200, 20, $SS_CENTERIMAGE)
_FireTimedEvent()
GUISetState()

While 1
    Sleep(100)
WEnd

Func _GUIEventHandler()
    Switch @GUI_CtrlId
        Case $GUI_EVENT_CLOSE
            Exit
        Case $idStart, $idStartDummy
            _Start()
    EndSwitch
EndFunc

Func _FireTimedEvent()
    Local Static $i = 5
    GUICtrlSetData($idLabel, "Event will be fired in " & $i)
    Switch $i
        Case 5
            AdlibRegister(_FireTimedEvent, 1000)
        Case 0
            AdlibUnRegister(_FireTimedEvent)
            GUICtrlSendToDummy($idStartDummy)
            GUICtrlSetData($idLabel, "")
    EndSwitch
    $i -= 1
EndFunc

Func _Start()
    GUICtrlSetData($idStart, "Event fired!")
    ;do stuff
    Sleep(2000)
    GUICtrlSetData($idStart, "Start")
EndFunc

What I need is a routine to replace GUICtrlSendToDummy($idStartDummy) with something like _FireOnEvent($idStart), so I can completely get rid of that dummy control. Maybe some WinAPI, _Send or ControlCommand call can do this, but I had no luck in finding it out.

I know in most cases you can achieve your goals by rewriting some code and using a completely different approach (especially this script, which is nothing more than a quick example to make clear what I want), but in this case I really only want to find a way for exactly this "problem".

I couldn't find anything about it via google or the forum search :(

Share this post


Link to post
Share on other sites



Maybe utilize GUIRegisterMsg?

I use both onEvent and RegisterMsg in my GUIs personally.  But to be honest, I'm still at a loss of what exactly you're trying to accomplish, even with your pseudo code.


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Yes it's a bit hard to understand.

Basically I'm facing a problem, where a loop function blocks my main While in which I handle most of the events. Now that maybe sounds alot like im using GUIGetMsg but I'm not.

I'm using _GUICtrl_SetOnHover for most of my controls, which sets a static event id variable. In my main While I retrieve, handle and reset this event id (just like I would with GUIGetMsg).

For non OnHover enabled controls and the $GUI_EVENT_* messages I use OnEvent.

So I have these OnEvent events, which will not be blocked, and OnHover events, which may block later OnHover events (if it leads to a loop call). Now I would love to set a simple _FireOnEvent($idCtrl) call inside my OnHover handler, to transfer all that stuff into my OnEvent handler. In there I could now react to and handle all of my stuff.

Maybe I must recreate this situation in a more complex example, but I hope you get my point.

I guess GUIRegisterMsg (WM_COMMAND?) could be a solution, if it could mostly replace OnEvent and also accept _Send($idCtrl) events from my OnHover handler.

Edited by Synix

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I understand.  You need a custom event option.

Yes WM_COMMAND and some others may come in handy.

Be prepared to set globals and well maintained arrays to manage your works, conditions, and actions based on said conditions.  With these you'll be able to interact properly.  But there's no "fix-all" method.

Something similar that comes to mind (not hover mind you, but management of multi-data/event methods) is something I believe Kip did did some time ago on TCP... looking ... found here: 

Surprised I remembered that considering all I ever did was look at the code years ago :) ...

While looking for that, I saw another, no idea what it does, but they are just meant to give you an idea on structure and use anyway.

Good luck.

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thank you, I finally had time to tinker around with WM_COMMAND and wrote a function to simulate a triggered ctrl id:

Func _TriggerControl($idCtrl)
    Local $hWnd = _WinAPI_GetParent(GUICtrlGetHandle($idCtrl))
    _SendMessage($hWnd, $WM_COMMAND, _WinAPI_MakeLong($idCtrl, 0), GUICtrlGetHandle($idCtrl))
EndFunc

After setting a call for __GUICtrl_SOH_WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) in my newly registered WM_COMMAND function (because GUICtrlOnHover.au3 also handles this message) it's no big deal to implement the changes that are necessary to solve my problem.

So thanks, you can consider this problem as solved :) (although I still would love to know if there is some kind of substitute for GUICtrlSendToDummy for normal controls :D)

Edited by Synix

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