gcue Posted January 6, 2017 Posted January 6, 2017 Hello I have an input control that acts as a search to a sql server. Each search takes around 2 seconds to process. However wm_command/$en_change is trying to process much faster than that so when a user types in the search input, they see a delay in their typing. So i am trying to perform the search only until the user is done typing. I know an enter button is the easiest solution because the user would simply hit enter when they are done typing - but i wanted to see if it was possible without the button. Sort of like a google search Below is a mock up that simulates the typing delay. In efforts to provide a fully working script, I replaced the actually processing function because there is a sql query to a server - which would not work on your test. Thank you in advance!!! expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <GuiEdit.au3> #include <Timers.au3> Opt("GUIOnEventMode", 1) GUICreate("test", 200, 200) $search_input = GUICtrlCreateInput("", 20, 20, 170, 20) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetState() While 1 Sleep(10) WEnd Func Test() For $x = 1 To 1000000 ConsoleWrite($x & @CRLF) Next ConsoleWrite(@CRLF) EndFunc ;==>Test Func WM_COMMAND($hwnd, $msg, $wParam, $lParam) Local $hWndFrom, $iIDFrom, $iCode, $hWndEdit If Not IsHWnd($search_input) Then $hWndEdit = GUICtrlGetHandle($search_input) $hWndFrom = $lParam $iIDFrom = _WinAPI_LoWord($wParam) $iCode = _WinAPI_HiWord($wParam) Switch $hWndFrom Case $hWndEdit $search_text = GUICtrlRead($search_input) Switch $iCode Case $EN_CHANGE Test() EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Func _Exit() Exit EndFunc ;==>_Exit
gcue Posted January 6, 2017 Author Posted January 6, 2017 i've tried _Timer_GetIdleTime() but that doesnt work because WM_COMMAND runs Test() immediately so there is no idle time
Moderators Melba23 Posted January 6, 2017 Moderators Posted January 6, 2017 gcue, Quote Each search takes around 2 seconds to process Running something that long within a Windows message handler is just asking for trouble - my rule of thumb is a maximum of 500ms, preferably much less, before you start running into problems by blocking the Windows message stream. I will have a think about how you might get around this while I am rearranging the contents of the loft this afternoon - much more interesting that checking the contents of old boxes! 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
gcue Posted January 6, 2017 Author Posted January 6, 2017 haha - thanks good luck with the moving around too
Moderators Melba23 Posted January 6, 2017 Moderators Posted January 6, 2017 gcue, How about this: expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <GuiEdit.au3> #include <Timers.au3> Opt("GUIOnEventMode", 1) ; A flag to indicate the time the last edit was made Global $nTimeStamp = 0 GUICreate("test", 200, 200) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $search_input = GUICtrlCreateInput("", 20, 20, 170, 20) GUISetState() GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") While 1 Sleep(10) ; Check if a timestamp has been set (edit altered) and at least a second has gone by since the last change If $nTimeStamp And TimerDiff($nTimeStamp) > 1000 Then ; Reset the flag $nTimeStamp = 0 ; Now run your search _Run() EndIf WEnd Func _Run() MsgBox($MB_SYSTEMMODAL, "Hi", "I think you have finished typing" & @CRLF & @CRLF & "Search beginning using:" & @CRLF & @CRLF & GUICtrlRead($search_input)) EndFunc Func WM_COMMAND($hwnd, $msg, $wParam, $lParam) Local $hWndFrom, $iIDFrom, $iCode, $hWndEdit If Not IsHWnd($search_input) Then $hWndEdit = GUICtrlGetHandle($search_input) $hWndFrom = $lParam $iIDFrom = _WinAPI_LoWord($wParam) $iCode = _WinAPI_HiWord($wParam) Switch $hWndFrom Case $hWndEdit $search_text = GUICtrlRead($search_input) Switch $iCode Case $EN_CHANGE $nTimeStamp = TimerInit() EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Func _Exit() Exit EndFunc ;==>_Exit Now off to the loft!! 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
gcue Posted January 6, 2017 Author Posted January 6, 2017 it's beautiful... *sniff*sniff* thank you soooooooooo much! happy new year!
Moderators Melba23 Posted January 6, 2017 Moderators Posted January 6, 2017 gcue, Back down from the loft - but with 2 huge piles of stuff to get rid off tomorrow. Amazing what you keep in a loft over a 10 year period. Glad you like the code - and a Happy New Year to you too. 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
gcue Posted January 6, 2017 Author Posted January 6, 2017 yea i love getting rid of clutter.. feels so nice seeing boxes of stuff go away
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