Zedna Posted May 15, 2012 Share Posted May 15, 2012 (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. expandcollapse popup#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 May 15, 2012 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 15, 2012 Moderators Share Posted May 15, 2012 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:asdYou 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Zedna Posted May 15, 2012 Author Share Posted May 15, 2012 (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 May 15, 2012 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 15, 2012 Moderators Share Posted May 15, 2012 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Zedna Posted May 15, 2012 Author Share Posted May 15, 2012 @MelbaWhen you comment/remove GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")then "Msg event edit" is fired only after EnterSo I expected that Case $edit should react/be fired only by Enterand not after each character change. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 15, 2012 Moderators Share Posted May 15, 2012 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Zedna Posted May 15, 2012 Author Share Posted May 15, 2012 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. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Zedna Posted May 15, 2012 Author Share Posted May 15, 2012 (edited) I discovered simple workaround using global boolean variable $ib_en_changewhich is set to True only for time GUICtrlSendToDummy() and related time consuming function to finish.In Case $edit there isif Not $ib_en_change Then ConsoleWrite ("Msg event edit:" & GUICtrlRead($edit) & @CRLF)to avoid invoking this event when Dummy control event is in progressexpandcollapse popup#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 May 15, 2012 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
UEZ Posted May 15, 2012 Share Posted May 15, 2012 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
UEZ Posted May 16, 2012 Share Posted May 16, 2012 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Zedna Posted May 16, 2012 Author Share Posted May 16, 2012 (edited) @UEZThanks for the tip!I saw some examples for sublassing of edit control.for example here: catch doubleclick in edit control:#738990Your 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 May 16, 2012 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now