gcue

detect idle time in wm_command $en_change

8 posts in this topic

#1 ·  Posted

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!!!

#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

 

Share this post


Link to post
Share on other sites



#2 ·  Posted

i've tried _Timer_GetIdleTime() but that doesnt work because WM_COMMAND runs Test() immediately so there is no idle time

Share this post


Link to post
Share on other sites

#3 ·  Posted

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._______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

#4 ·  Posted

haha - thanks

good luck with the moving around too :)

Share this post


Link to post
Share on other sites

#5 ·  Posted

gcue,

How about this:

#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._______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

#6 ·  Posted

it's beautiful... *sniff*sniff*:'(

thank you soooooooooo much!

happy new year!

Share this post


Link to post
Share on other sites

#7 ·  Posted

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._______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

#8 ·  Posted

yea i love getting rid of clutter.. feels so nice seeing boxes of stuff go away

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