Jump to content

detect idle time in wm_command $en_change


gcue
 Share

Recommended Posts

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

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...