Jump to content

Unusual domand ...


Recommended Posts

Im writing a search engine that have a function like "Google Instant" that shows results as you type.

Now my script start when any letter is entered in the combobox and start to search...

But this is not the best for performance...now i want for example do a function like that :

If User Are currently Writing in ComboBox Then
Do Nothing
Else
Start To search
endiF

There is a way to make it clear to the application when the user is typing the word yet?

This is my currently code...But now it give me a check every second...and if i write a word that that need more than a second to write, the program equally starts searching.

I hope that you have understand me...it's very unusual question.

This is my current code :

#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <GUIComboBox.au3>
#include <SQLite.au3>
#include <SQLite.dll.au3>

$hGUI = GUICreate("Let's try", 477, 191, 192, 124)
$hComboBox = _GUICtrlComboBox_Create($hGUI,"", 8, 8, 145, 25)
$hListView = GUICtrlCreateListView("Name|Stream|Web|Genre|State", 0, 40, 474, 150)
GUISetState(@SW_SHOW)

Local $fComboChange = False ; Set flag for search form
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")
AdlibRegister("_Search", 200)

_SQLite_Startup("YourDataBase")
_SQLite_Open()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _Search()
    If $fComboChange Then
        $TimerInt = TimerInit()
        $fComboChange = False
        $sText = _GUICtrlComboBox_GetEditText($hComboBox)
        If $sText <> "" Then
            _UpdateListView($sText)
        Else
            _GUICtrlListView_DeleteAllItems($hListView)
        EndIf
    EndIf
EndFunc   ;==>_Search

Func _UpdateListView($sText)
    Local $aResult, $iRows, $iColumns
    _GUICtrlListView_BeginUpdate($hListView)
    _GUICtrlListView_DeleteAllItems($hListView)
    Local $hQuery, $aRow, $aNames
    $iRval = _SQLite_GetTable2d(-1, "SELECT * FROM Data WHERE Radio LIKE '%" & $sText & "%';", $aResult, $iRows, $iColumns)
    _ArrayDelete($aResult, 0) 
    If $iRval = $SQLITE_OK Then _GUICtrlListView_AddArray($hListView, $aResult)
    _GUICtrlListView_EndUpdate($hListView)
EndFunc   ;==>_UpdateListView


Func _WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    $hWndFrom = $ilParam
    $iIDFrom = BitAND($iwParam, 0xFFFF)
    $iCode = BitShift($iwParam, 16)

    Switch $hWndFrom
        Case $hComboBox
            Switch $iCode
                Case $CBN_EDITCHANGE
                    Sleep(1000)
                    $fComboChange = True
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_COMMAND

Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $I
    Global $hWndFrom, $iCode, $tNMHDR, $hWndListView, $lParam
    $hWndListView = $ListView
    $hWnd1 = $hGUI
    If Not IsHWnd($ListView) Then $hWndListView = GUICtrlGetHandle($ListView)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_ITEMACTIVATE
                    Local $nmia = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    $I = DllStructGetData($nmia, "Index")
                    $SomeVariablex = _GUICtrlListView_GetItemTextArray($ListView, $I) ; Grab Info 
                    ;With $SomeVariablex[2] i grab the streaming link and i reproduce it with Bass.dll
                    Global $SomeVariablex[2]
            EndSwitch
    EndSwitch
    Return $__LISTVIEWCONSTANT_GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY

Can be improved?

Hi!

Summary

Do 
Nothing 
Until person are writing in a combo box
Link to comment
Share on other sites

  • Moderators

StungStang,

You are asking for a function that reads the mind of the user - not a very easy thing to do! :P

I would suggest that rather than check every second to see if the Combo has something in it, you check periodically that it has something in it AND that the content has not changed for a time. Perhaps something like this: :)

#include <GUIConstantsEx.au3>

Global $sLast_Combo = ""
Global $sUsed_Combo = ""

$hGUI = GUICreate("Test", 500, 500)

$hConbo = GUICtrlCreateCombo("", 10, 10, 200, 20)

GUISetState()

AdlibRegister("Combo_Check", 500) ; Check every half second

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

Func Combo_Check()

    ; What is in the combo?
    $sCurr_Combo = GUICtrlRead($hConbo)
    ; Is there something?
    If $sCurr_Combo <> "" Then
        ; If it is the same as it was the last time and we have not used it
        If $sCurr_Combo = $sLast_Combo And $sCurr_Combo <> $sUsed_Combo Then
            ; Do whatever we need
            MsgBox(0, "Aha!", "I think you have stopped typing!" & @CRLF & @CRLF & "You typed " & $sCurr_Combo )
            ; And mark this content as used
            $sUsed_Combo = $sCurr_Combo

        Else
            ; Otherwise save this for the next comparison
            $sLast_Combo = $sCurr_Combo
        EndIf
    EndIf

EndFunc

All clear? :)

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

@StungStang

Change the Sleep() to a AdlibRegister("somefunction", 1000), and activate the search there, that way you search will start when the user hasn't typed anything for a second.

Don't forget to AdlibUnRegister() right at the top of the adlib function.

Link to comment
Share on other sites

Try

#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <GUIComboBox.au3>

Global $_TimerInit = TimerInit ( )
Global $fComboChange = False
Global $fComboChangeOld

$hGUI = GUICreate ( "Let's try", 477, 191, 192, 124 )
$hComboBox = _GUICtrlComboBox_Create ( $hGUI, "", 8, 8, 145, 25 )
$hListView = GUICtrlCreateListView ( "Name|Stream|Web|Genre|State", 0, 40, 474, 150 )
GUISetState ( @SW_SHOW )

GUIRegisterMsg ( $WM_COMMAND, "_WM_COMMAND" )

Do
    If TimerDiff ( $_TimerInit ) > 3000 Then
        $fComboChange = False
    Else
        $fComboChange = True
    EndIf
    If $fComboChange <> $fComboChangeOld Then
        ConsoleWrite ( "-->-- $fComboChange : " & $fComboChange & @Crlf )
        If $fComboChange = False Then
            AdlibRegister ( "_Search", 200 )
        Else
            AdlibUnRegister ( "_Search" )
        EndIf
        $fComboChangeOld = $fComboChange
    EndIf
Until GUIGetMsg ( ) = $GUI_EVENT_CLOSE

Func _WM_COMMAND ( $hWnd, $iMsg, $iwParam, $ilParam )
    $hWndFrom = $ilParam
    $iIDFrom = BitAND ( $iwParam, 0xFFFF )
    $iCode = BitShift ( $iwParam, 16 )
    Switch $hWndFrom
        Case $hComboBox
            Switch $iCode
                Case $CBN_EDITCHANGE
                    $_TimerInit = TimerInit ( )
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc ;==> _WM_COMMAND ( )

and set time like you want ! Posted Image

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

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