Sign in to follow this  
Followers 0
Zedna

Bug? EN_CHANGE & GUICtrlSendToDummy & multiple events

11 posts in this topic

#1 ·  Posted (edited)

I have problem with multiple events fired on Edit control when using GUICtrlSendToDummy from EN_CHANGE.

Edit control fires event implicitly only after Enter is pressed and not after each character.

I added catching EN_CHANGE WM_COMMAND to achieve reaction on each character.

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>

$GUI = GuiCreate("Bug", 400, 300)
$edit = GUICtrlCreateInput('', 150, 220, 100, 25)
$DUM = GuiCtrlCreateDummy()
GuiSetState()

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

while 1
    $MSG = GuiGetMsg()
    switch $MSG
        case $GUI_EVENT_CLOSE
            exit
;~       case $DUM, $edit
;~       ConsoleWrite ("Msg event:" & GUICtrlRead($edit) & @CRLF)
     case $edit
            ConsoleWrite ("Msg event edit:" & GUICtrlRead($edit) & @CRLF)
        case $DUM
         ConsoleWrite ("Msg event dummy:" & GUICtrlRead($edit) & @CRLF)
    endswitch
wend

Func WM_COMMAND($hWnd, $MsgID, $wParam, $lParam)
    Local $nID = BitAND($wParam, 0xFFFF)
    Local $nNotifyCode = BitShift($wParam, 16)

    If $nNotifyCode = $EN_CHANGE Then
        If $nID = $edit Then
            GUICtrlSendToDummy($DUM)
            ConsoleWrite ("Edit Changed:" & GUICtrlRead($edit) & @CRLF)
        EndIf
    EndIf

    Return $GUI_RUNDEFMSG
EndFunc

When I type asd, result is:

Edit Changed:a

Msg event dummy:a

Edit Changed:as

Msg event edit:as

Msg event dummy:as

Edit Changed:asd

Msg event edit:asd

Msg event dummy:asd

As you can see after "a" is fired only Msg event dummy (which is OK)

but after another characters "asd" there is also fired Msg event edit which I think shouldn't be fired (because only Dummy message was originally sent by GUICtrlSendToDummy).

I think this may be bug in AutoIt.

Note:

There is commented version: case $DUM, $edit ...

which I use in my original script because I need to react on each character (in some cases) and also on Enter.

Problem is that event is fired twice ("Msg event edit" shouldn't be there as Enter wasn't pressed).

Edited by Zedna

Share this post


Link to post
Share on other sites



Zedna,

Edit controls need to have had something in them to fire an event - the first keystroke never produces a message. So I see nothing unusual in the returns you get:

Edit Changed:a
Msg event edit: ----- not fired as it is the first character in the edit
Msg event dummy:a

Edit Changed:as
Msg event edit:as 
Msg event dummy:as

Edit Changed:asd
Msg event edit:asd
Msg event dummy:asd

You will obviously get the "Edit Changed" and "Msg event dummy" returns each time as you action those within the handler. ;)

There are several threads around here where I have used GUISetAccelerators to fire a dummy when "Enter" is pressed on an empty input becasue of the lack of a response from the control itself in that case. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Following question:

In fact I need to do some time consuming computing as reaction on typing in edit control.

That's why I use GUICtrlSendToDummy() from WM_COMMAND (EN_CHANGE) instead of direct function invoke.

EDIT: and as result my time consuming function is fired twice!

Is it the same requirement in WM_COMMAND as it is in WM_NOTIFY to not doing time consuming operations directly and doing it through messages?

Maybe WM_COMMAND is not so sensitive as WM_NOTIFY is?

Edited by Zedna

Share this post


Link to post
Share on other sites

Zedna,

As far as I know they are all sensitive - blocking the message queue is not a good idea regardless of the particular message involved. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

@Melba

When you comment/remove GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

then "Msg event edit" is fired only after Enter

So I expected that Case $edit should react/be fired only by Enter

and not after each character change.

Share this post


Link to post
Share on other sites

Zedna,

You are quite right, I had not noticed that. How strange. ;)

It seems the edit control is firing a message because of the WM_COMMAND handler. And if you Return 0 instead of GUI_RUNDEFMSG you never get the edit firing, even if you press "ENTER". :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

It seems the edit control is firing a message because of the WM_COMMAND handler...

Maybe it's not edit control but AutoIt who is doing this ...

So that's why I think it may be bug in AutoIt.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I discovered simple workaround using global boolean variable $ib_en_change

which is set to True only for time GUICtrlSendToDummy() and related time consuming function to finish.

In Case $edit there is

if Not $ib_en_change Then ConsoleWrite ("Msg event edit:" & GUICtrlRead($edit) & @CRLF)

to avoid invoking this event when Dummy control event is in progress

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>

Global $ib_en_change = False

$GUI = GuiCreate("Bug", 400, 300)
$edit = GUICtrlCreateInput('', 150, 220, 100, 25)
$DUM = GuiCtrlCreateDummy()
GuiSetState()

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

while 1
    $MSG = GuiGetMsg()
    switch $MSG
        case $GUI_EVENT_CLOSE
            exit
        case $edit
            if Not $ib_en_change Then ConsoleWrite ("Msg event edit:" & GUICtrlRead($edit) & @CRLF)
        case $DUM
            ConsoleWrite ("Msg event dummy:" & GUICtrlRead($edit) & @CRLF)
            ; here is my time consuming function ...
            $ib_en_change = False
    endswitch
wend

Func WM_COMMAND($hWnd, $MsgID, $wParam, $lParam)
    Local $nID = BitAND($wParam, 0xFFFF)
    Local $nNotifyCode = BitShift($wParam, 16)

    If $nNotifyCode = $EN_CHANGE Then
        If $nID = $edit Then
            $ib_en_change = True
            GUICtrlSendToDummy($DUM)
            ConsoleWrite ("Edit Changed:" & GUICtrlRead($edit) & @CRLF)
        EndIf
    EndIf

    Return $GUI_RUNDEFMSG
EndFunc
Edited by Zedna

Share this post


Link to post
Share on other sites

I'm wondering why WM_KEYDOWN is not working for edit controls....

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

In case you want to capture keystroke in a edit control you can use DllCallbackRegister ("EditWndProc", "long", "hwnd;uint;wparam;lparam") call back function.

For an example look here:

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

@UEZ

Thanks for the tip!

I saw some examples for sublassing of edit control.

for example here: catch doubleclick in edit control:

#738990

Your sublassing example for catching WM_KEYDOWN in edit control is nice.

Anyway I think I would have the same problem: When I invoke GUICtrlSendToDummy() from EditWndProc() then my Case Msg will fire event twice too,

I will post this on Bug Trac as BUG later ...

Edited by Zedna

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