Sign in to follow this  
Followers 0
KaFu

_WinAPI_SetWindowPos() + GUICtrlSetOnEvent() = Bug?

3 posts in this topic

HiHo Forum,

took me some time to figure this out. Here's a little tweaked standard help-file example showing what I mean. If you use GUISetState() the call to GUICtrlSetOnEvent() works fine. If you use _WinAPI_SetWindowPos() to show the window, the control events are not called anymore, though the GUI events still work. Start and press OK, close GUI and press OK on the second GUI and you'll see what I mean. Is this a know bug or meant to be this way?

#include <GUIConstantsEx.au3>
#include <Constants.au3>
#include <Winapi.au3>

Opt('MustDeclareVars', 1)
Global $bExit = False

Example(1)
Example(2)

Func Example($iExample)
    Local $parent1, $ok1, $cancel1

    Opt("GUICoordMode", 2)
    Opt("GUIResizeMode", 1)
    Opt("GUIOnEventMode", 1)

    $parent1 = GUICreate("Example #" & $iExample)
    GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
    GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
    GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")

    $ok1 = GUICtrlCreateButton("OK", 10, 30, 50)
    GUICtrlSetOnEvent(-1, "OKPressed")

    $cancel1 = GUICtrlCreateButton("Cancel", 0, -1)
    GUICtrlSetOnEvent(-1, "CancelPressed")

    Switch $iExample
        Case 1
            GUISetState(@SW_SHOW)
        Case Else
            _WinAPI_SetWindowPos($parent1, $HWND_TOP, 0, 0, 0, 0, BitOR($SWP_NOACTIVATE, $SWP_NOMOVE, $SWP_NOSIZE, $SWP_SHOWWINDOW))
    EndSwitch

    ; Just idle around
    While $bExit = False
        Sleep(10)
    WEnd
    GUIDelete($parent1)
    $bExit = False
EndFunc   ;==>Example

Func OKPressed()
    MsgBox(0, "OK Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle & " CtrlHandle=" & @GUI_CtrlHandle)
EndFunc   ;==>OKPressed


Func CancelPressed()
    MsgBox(0, "Cancel Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle & " CtrlHandle=" & @GUI_CtrlHandle)
EndFunc   ;==>CancelPressed


Func SpecialEvents()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            MsgBox(0, "Close Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)
            $bExit = True
        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

Regards

Share this post


Link to post
Share on other sites



I don't think it's either.

AutoIt GUI is shown/whatever with GUISetState(). Anything else may and may not work depending on internal mechanism.

In fact it may work today and not tomorrow and then work again the next day. Making conclusions based on that behavior is certainly wrong.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

In fact it may work today and not tomorrow and then work again the next day. Making conclusions based on that behavior is certainly wrong.

Makes sense... somehow :unsure: ... I guess GUICtrlSetOnEvent() somehow processes wm_command messages, and GuiSetState() might register / de-register the processing... or something completely different :>. Anyway, this way a least the issue can be found by searching. Thanks for taking a look ;).

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