Kovacic

Trying to make Autocomplete like Google search in a text box

18 posts in this topic

I am taking some idea from here:

'?do=embed' frameborder='0' data-embedContent>>

 

But what I am looking to accomplish is simple, I want to have an input box with a hidden input box below it. I will also have a defined list of items. When the text box has any value in it that does not directly equal an item in the pre defined list, the edit box should show. and populate suggested items based on whats being typed which I will do that part later, should be easy.

I am stuck on a simple portion which should be easy and i'm not sure why I am having trouble with it.  The way thr code below should work is, as long as there is a value in the Input box, the edit box will appear, if there is no value in the input box, the edit box should be hidden. 

here is what I have so far:

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$Input1 = GUICtrlCreateInput("", 64, 72, 313, 21)
$Edit1 = GUICtrlCreateEdit("", 64, 96, 313, 177)
GUISetState(@SW_SHOW)
GUICtrlSetState($Edit1, $GUI_HIDE)

While 1
$words = GUICtrlRead($Input1)
If $words NOT = "" then
GUICtrlSetState($Edit1, $GUI_SHOW)
else
GUICtrlSetState($Edit1, $GUI_HIDE)
endif
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

func flopdrop()
            If BitAnd($Edit1,2) AND $words = "" Then
            GUICtrlSetState($Edit1, $GUI_HIDE)
             Else
             GUICtrlSetState($Edit1, $GUI_SHOW)
            EndIf
endfunc

the problem with this is a nasty flicker when you move the mouse or do anything else. I will get rid of the scroll bars too, but thats once I solve this flicker issue. I know its happening because I have the check being performed within the While statement, but I can't think of any other way to do it.. I even tried using a timer to only check once every few seconds, but that didn't seem to work either:

If $words NOT = "" AND (@SEC = 00 OR 10 OR 20 OR 30 OR 40 OR 50) AND (@MSEC < 20)) Then
  ; Blah blah blah

endIf

Does anyone have any thoughts or has anyone been able to do this?

Thanks in advance!!


C0d3 is P0etry( ͡° ͜ʖ ͡°)

Share this post


Link to post
Share on other sites



Its flickering due to GuiCtrlSetState constantly. Best option would be to get the state and if its already shown then skip showing it.

Share this post


Link to post
Share on other sites

You could start with >this script from martin.

 

I actually did try that one, but it doesn't do what I am looking for...  I was hoping for a drop down you could click on if you see the object you want.

 

Its flickering due to GuiCtrlSetState constantly. Best option would be to get the state and if its already shown then skip showing it.

 

I did have that in an If statement, but it was still flickering.


C0d3 is P0etry( ͡° ͜ʖ ͡°)

Share this post


Link to post
Share on other sites

Im going to try combining martins script with mine, I like the idea of just using a label, because it can be easily clicked on to finish the auto complete... If it works, I'll post the final code for others to use and give Martin credit.


C0d3 is P0etry( ͡° ͜ʖ ͡°)

Share this post


Link to post
Share on other sites

I am so close I can taste it!! I now have a list box pop up under the input box with some search options, I just want to make it so if you click on the option you want, it populates... OR maybe be able to press the down arrow until you find the option you want.. 

I think a few people in the past were asking for something like this so it might be a good find if we can make it work.. 

Here is the latest and greatest (it normally pulls from SQL, but I put in a mock line to emulate results of random words):

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <ComboConstants.au3>


#cs
$conn = ObjCreate( "ADODB.Connection" )
$DSN = "All my SQL connection stuff"
$conn.Open($DSN)


$rs = ObjCreate("ADODB.RecordSet")

$rs.Open("SELECT Serial FROM tbl_Manual", $conn)
;$rs.Open("SELECT TOP 20 Serial FROM tbl_Manual", $conn)
If $RS.RecordCount Then
    While Not $RS.EOF
    local $MyVal = $MyVal & "|" & StringStripWS($rs.Fields("serial").value,8)
        $RS.MoveNext
    WEnd
EndIf

$RS.Close
$conn.close
#ce
$MyVal = "fracturing|enzygotic|bondwoman|mealtime|miketime|kimball|kiteball|unreelable|aruspices|prevoted|punt|taxis"

local $MyVal2 = $MyVal
$MyVal = StringSplit($MyVal,"|")

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

$gui = GUICreate("My GUI edit")

$IP = GUICtrlCreateInput("", 10, 18, 200, 22)
$Edit1 = GUICtrlCreateList("", 10, 40, 200, 177)
GUICtrlSetState($Edit1, $GUI_Hide)

GUISetState()


While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd



Func WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    $nNotifyCode = BitShift($wParam, 16)
    $nID = BitAND($wParam, 0x0000FFFF)
    If $nID = $IP Then
        $hCtrl = $lParam
        If $nNotifyCode = $EN_CHANGE Then
            $txt = GUICtrlRead($IP)
            For $n = 1 To UBound($MyVal) - 1
                If StringCompare(StringLeft($MyVal[$n], StringLen($txt)), $txt) = 0 Then
                    GUICtrlSetData($Edit1, $MyVal[$n])
                    if GUICtrlRead($IP) then
                    GUICtrlSetState($Edit1, $GUI_show)
                    else
                    GUICtrlSetState($Edit1, $GUI_Hide)
                    endif
                    
                    ExitLoop
                EndIf
            Next
            
        EndIf
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc  ;==>WM_COMMAND

As usual, any and all comments, hints, tips, spelling corrections, suggestions are welcome!


C0d3 is P0etry( ͡° ͜ʖ ͡°)

Share this post


Link to post
Share on other sites

I think this piece of code in callback function determines that the message came from input,

If $nID = $IP Then
        $hCtrl = $lParam
        If $nNotifyCode = $EN_CHANGE Then
            $txt = GUICtrlRead($IP)
            For $n = 1 To UBound($MyVal) - 1
                If StringCompare(StringLeft($MyVal[$n], StringLen($txt)), $txt) = 0 Then
                    GUICtrlSetData($Edit1, $MyVal[$n])
                    if GUICtrlRead($IP) then
                    GUICtrlSetState($Edit1, $GUI_show)
                    else
                    GUICtrlSetState($Edit1, $GUI_Hide)
                    endif

                    ExitLoop
                EndIf
            Next

        EndIf
    EndIf

you might have to code another condition for your list box.

1 person likes this

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

I think this piece of code in callback function determines that the message came from input,

If $nID = $IP Then
        $hCtrl = $lParam
        If $nNotifyCode = $EN_CHANGE Then
            $txt = GUICtrlRead($IP)
            For $n = 1 To UBound($MyVal) - 1
                If StringCompare(StringLeft($MyVal[$n], StringLen($txt)), $txt) = 0 Then
                    GUICtrlSetData($Edit1, $MyVal[$n])
                    if GUICtrlRead($IP) then
                    GUICtrlSetState($Edit1, $GUI_show)
                    else
                    GUICtrlSetState($Edit1, $GUI_Hide)
                    endif

                    ExitLoop
                EndIf
            Next

        EndIf
    EndIf

you might have to code another condition for your list box.

 

 

That part seems to be working, so it only shows the list box if there is something in the input box... What i'm struggling with now is the SQL query. When I do a search, and try to move the data returned by the SQL Query, only 1 or 2 records come back, but if I run the same query in SQLCMD, I get several returns... The issue seems to be in here:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <ComboConstants.au3>
#include <Array.au3>

global $MyVal

$conn = ObjCreate( "ADODB.Connection" )
$DSN = "DRIVER={SQL Server};SERVER=1.2.3.4;DATABASE=inventory;uid=inventory;pwd=MyPassWord;"
$conn.Open($DSN)
$rs = ObjCreate("ADODB.RecordSet")
;$rs.Open("SELECT Serial FROM tbl_Manual", $conn); To grab everything
$rs.Open("SELECT TOP 20 Serial FROM tbl_Manual", $conn); to grab only 20 results just for testing
While $rs.eof <> True
;ConsoleWrite($rs.Fields("Serial").Value & @CRLF); <~~ this works to bring data to the console
For $x In $rs.Fields
$MyVal = $MyVal & $x.name & "|"; <~~ This is supposed to populate $MyVal with the results with a pipe between them
Next
$x.MoveNext
Wend
$RS.Close
$conn.close
;$MyVal = "fracturing|enzygotic|bondwoman|mealtime|miketime|kimball|kiteball|unreelable|aruspices|prevoted|punt|taxis"; I only use this for demoing the input box with random word values.
$MyVal = StringSplit($MyVal,"|"); Splits the string at the pipe to make an array
local $MyVal2 = $MyVal
Msgbox(0,"MyVal", $MyVal)
_ArrayDisplay($MyVal, "2"); Just so I can see what comes back, for testing only. Ill remove it on the final script


GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

$gui = GUICreate("My GUI edit")

$IP = GUICtrlCreateInput("", 10, 18, 200, 22)
$Edit1 = GUICtrlCreateList("", 10, 40, 200, 177)
GUICtrlSetLimit(-1, 20)
GUICtrlSetState($Edit1, $GUI_Hide)

GUISetState()


While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd



Func WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    $nNotifyCode = BitShift($wParam, 16)
    $nID = BitAND($wParam, 0x0000FFFF)
    If $nID = $IP Then
        $hCtrl = $lParam
        If $nNotifyCode = $EN_CHANGE Then
            $txt = GUICtrlRead($IP)
            For $n = 1 To UBound($MyVal) - 1
            ;Msgbox(0,"Records found: " & $n, $MyVal[$n])
                If StringCompare(StringLeft($MyVal[$n], StringLen($txt)), $txt) = 0 Then
                    GUICtrlSetData($Edit1, $MyVal[$n])
                    
                    if GUICtrlRead($IP) then
                    GUICtrlSetState($Edit1, $GUI_show)
                    else
                    GUICtrlSetState($Edit1, $GUI_Hide)
                    endif
                    
                    ExitLoop
                EndIf
            Next
            
        EndIf
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc  ;==>WM_COMMAND

C0d3 is P0etry( ͡° ͜ʖ ͡°)

Share this post


Link to post
Share on other sites

Kovacic,

Does this help at all? :huh:

#include <GUIConstantsEx.au3>
#include <Array.au3>
#Include <GuiListBox.au3>

Global $hGUI, $hInput, $hList, $sPartialData, $asKeyWords[100]

; Create list full of random 5 character "words"
Keywords()

$hGUI = GUICreate("Example", 200, 400)
$hInput = GUICtrlCreateInput("", 5, 5, 190, 20)
$hList = GUICtrlCreateList("", 5, 30, 190, 325, BitOR(0x00100000, 0x00200000))
$hButton = GUICtrlCreateButton("Read", 60, 360, 80, 30)
$hUP = GUICtrlCreateDummy()
$hDOWN = GUICtrlCreateDummy()
$hENTER = GUICtrlCreateDummy()
GUISetState(@SW_SHOW, $hGUI)

; Set accelerators for Cursor up/down and Enter
Dim $AccelKeys[3][2]=[["{UP}", $hUP], ["{DOWN}", $hDOWN], ["{ENTER}", $hENTER]]
GUISetAccelerators($AccelKeys)

$sCurr_Input = ""
$iCurrIndex = -1

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hList
            $sChosen = GUICtrlRead($hList)
            If $sChosen <> "" Then GUICtrlSetData($hInput, $sChosen)
        Case $hButton
            If $sPartialData <> "" Then
                $sFinal = GUICtrlRead($hInput)
                If _ArraySearch($asKeyWords, $sFinal) > 0 Then
                    MsgBox(0, "Chosen", $sFinal)
                EndIf
            EndIf
        Case $hUP
            If $sPartialData <> "" Then
                $iCurrIndex -= 1
                If $iCurrIndex < 0 Then $iCurrIndex = 0
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
        Case $hDOWN
            If $sPartialData <> "" Then
                $iTotal = _GUICtrlListBox_GetCount($hList)
                $iCurrIndex += 1
                If $iCurrIndex > $iTotal - 1 Then $iCurrIndex = $iTotal - 1
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
        Case $hENTER
            If $iCurrIndex <> -1 Then
                $sText = _GUICtrlListBox_GetText($hList, $iCurrIndex)
                GUICtrlSetData($hInput, $sText)
                $iCurrIndex = -1
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
    EndSwitch

    ; If input has changed, refill list with matching items
    If GUICtrlRead($hInput) <> $sCurr_Input Then
        CheckInputText()
        $sCurr_Input = GUICtrlRead($hInput)
    EndIf

WEnd

Func CheckInputText()

    $sPartialData = "|" ; Start with delimiter so new data always replaces old
    Local $sInput = GUICtrlRead($hInput)
    If $sInput <> "" Then
        For $i = 0 To 99
            If StringInStr($asKeyWords[$i], $sInput) <> 0 Then $sPartialData &= $asKeyWords[$i] & "|"
        Next
        GUICtrlSetData($hList, $sPartialData)
    EndIf
EndFunc   ;==>CheckInputText

Func Keywords()

    Local $sData
    For $i = 0 To 99
        $asKeyWords[$i] = Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1))
        $sData &= $asKeyWords[$i] & "|"
    Next
    GUICtrlSetData($hList, $sData)
    $iCurrIndex = -1
    _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)

EndFunc   ;==>Keywords
Please ask if anything is unclear. :)

M23

1 person likes this

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

Kovacic,

Does this help at all? :huh:

#include <GUIConstantsEx.au3>
#include <Array.au3>
#Include <GuiListBox.au3>

Global $hGUI, $hInput, $hList, $sPartialData, $asKeyWords[100]

; Create list full of random 5 character "words"
Keywords()

$hGUI = GUICreate("Example", 200, 400)
$hInput = GUICtrlCreateInput("", 5, 5, 190, 20)
$hList = GUICtrlCreateList("", 5, 30, 190, 325, BitOR(0x00100000, 0x00200000))
$hButton = GUICtrlCreateButton("Read", 60, 360, 80, 30)
$hUP = GUICtrlCreateDummy()
$hDOWN = GUICtrlCreateDummy()
$hENTER = GUICtrlCreateDummy()
GUISetState(@SW_SHOW, $hGUI)

; Set accelerators for Cursor up/down and Enter
Dim $AccelKeys[3][2]=[["{UP}", $hUP], ["{DOWN}", $hDOWN], ["{ENTER}", $hENTER]]
GUISetAccelerators($AccelKeys)

$sCurr_Input = ""
$iCurrIndex = -1

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hList
            $sChosen = GUICtrlRead($hList)
            If $sChosen <> "" Then GUICtrlSetData($hInput, $sChosen)
        Case $hButton
            If $sPartialData <> "" Then
                $sFinal = GUICtrlRead($hInput)
                If _ArraySearch($asKeyWords, $sFinal) > 0 Then
                    MsgBox(0, "Chosen", $sFinal)
                EndIf
            EndIf
        Case $hUP
            If $sPartialData <> "" Then
                $iCurrIndex -= 1
                If $iCurrIndex < 0 Then $iCurrIndex = 0
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
        Case $hDOWN
            If $sPartialData <> "" Then
                $iTotal = _GUICtrlListBox_GetCount($hList)
                $iCurrIndex += 1
                If $iCurrIndex > $iTotal - 1 Then $iCurrIndex = $iTotal - 1
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
        Case $hENTER
            If $iCurrIndex <> -1 Then
                $sText = _GUICtrlListBox_GetText($hList, $iCurrIndex)
                GUICtrlSetData($hInput, $sText)
                $iCurrIndex = -1
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
    EndSwitch

    ; If input has changed, refill list with matching items
    If GUICtrlRead($hInput) <> $sCurr_Input Then
        CheckInputText()
        $sCurr_Input = GUICtrlRead($hInput)
    EndIf

WEnd

Func CheckInputText()

    $sPartialData = "|" ; Start with delimiter so new data always replaces old
    Local $sInput = GUICtrlRead($hInput)
    If $sInput <> "" Then
        For $i = 0 To 99
            If StringInStr($asKeyWords[$i], $sInput) <> 0 Then $sPartialData &= $asKeyWords[$i] & "|"
        Next
        GUICtrlSetData($hList, $sPartialData)
    EndIf
EndFunc   ;==>CheckInputText

Func Keywords()

    Local $sData
    For $i = 0 To 99
        $asKeyWords[$i] = Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1))
        $sData &= $asKeyWords[$i] & "|"
    Next
    GUICtrlSetData($hList, $sData)
    $iCurrIndex = -1
    _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)

EndFunc   ;==>Keywords
Please ask if anything is unclear. :)

M23

 

 

This helps very much!! Thank you!! I can use the portion where you click on the result to have it populate the input box! too awesome thanks!!

 

This SQL portion is eating me alive...  this is the spot I'm stuck with at the moment... 

...

If $RS.RecordCount Then
    While Not $RS.EOF
    local $MyVal = $MyVal & StringStripWS($rs.Fields("Serial").value,8) & "|"
        $RS.MoveNext
    WEnd
EndIf

...

Which is just a piece of the code i posted earlier.. I know I'm doing something wrong here...    when I execute the query in SQLCMD I get a nice array of data back. I am trying to now move that to an array which will essentially populate the word list. This way, once an object is chosen, its full details will come up..

when seems to be happening is, the array that is being returned is only the last record being returned from SQL... 

i.e.

SQL returns:

MyComputers

----------------------

compu1

compu2

compu3

compu4

compu5

compu6

compu7

compu8

compu9

 

when I dump the array, im getting:

[0] = "2"

[1] = "compu9"

[2] = ""

 

I have a feeling its where I dump the SQL into the variable, but all the research I have done shows it should be correct.

 

C0d3 is P0etry( ͡° ͜ʖ ͡°)

Share this post


Link to post
Share on other sites

MISSION ACCOMPLISHED!  :bike:

 

Except for the SQL stuff I took out, this has now reached awesome!

Enjoy!

:thumbsup:

#include <GUIConstantsEx.au3>
#include <Array.au3>
#Include <GuiListBox.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <ComboConstants.au3>
Global $hGUI
Global $hInput
Global $hList
Global $sPartialData
Global $output = ''
Local $conn = ObjCreate( "ADODB.Connection" )
Local $DSN = "DRIVER={SQL Server};SERVER=MyServer;DATABASE=MyDB;uid=MyUID;pwd=MyPaSsWoRd;"



SQLQuery()
$hGUI = GUICreate("Example", 200, 400)
$hInput = GUICtrlCreateInput("", 5, 5, 190, 20)
$hList = GUICtrlCreateList("", 5, 30, 190, 225, BitOR(0x00100000, 0x00200000))
GUICtrlSetLimit(-1, 20)
GUICtrlSetState($hList, $GUI_Hide)
$hButton = GUICtrlCreateButton("Read", 60, 360, 80, 30)
$hUP = GUICtrlCreateDummy()
$hDOWN = GUICtrlCreateDummy()
$hENTER = GUICtrlCreateDummy()
GUISetState(@SW_SHOW, $hGUI)
Dim $AccelKeys[3][2]=[["{UP}", $hUP], ["{DOWN}", $hDOWN], ["{ENTER}", $hENTER]]
GUISetAccelerators($AccelKeys)
$sCurr_Input = ""
$iCurrIndex = -1
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")





While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hList
            $sChosen = GUICtrlRead($hList)
            If $sChosen <> "" Then 
            GUICtrlSetData($hInput, $sChosen)
            GUICtrlSetState($hList, $GUI_Hide)
            endif
        Case $hButton
            If $sPartialData <> "" Then
                $sFinal = GUICtrlRead($hInput)
                If _ArraySearch($MyVal, $sFinal) > 0 Then
                    MsgBox(0, "Chosen", $sFinal)
                EndIf
            EndIf
        Case $hUP
            If $sPartialData <> "" Then
                $iCurrIndex -= 1
                If $iCurrIndex < 0 Then $iCurrIndex = 0
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
        Case $hDOWN
            If $sPartialData <> "" Then
                $iTotal = _GUICtrlListBox_GetCount($hList)
                $iCurrIndex += 1
                If $iCurrIndex > $iTotal - 1 Then $iCurrIndex = $iTotal - 1
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
        Case $hENTER
            If $iCurrIndex <> -1 Then
                $sText = _GUICtrlListBox_GetText($hList, $iCurrIndex)
                GUICtrlSetData($hInput, $sText)
                GUICtrlSetState($hList, $GUI_Hide)
                $iCurrIndex = -1
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
    EndSwitch
    If GUICtrlRead($hInput) <> $sCurr_Input Then
        CheckInputText()
        $sCurr_Input = GUICtrlRead($hInput)
    EndIf
WEnd

Func CheckInputText()
    $sPartialData = "|"
    Local $sInput = GUICtrlRead($hInput)
    If $sInput <> "" Then
        For $i = 0 To Ubound($MyVal) - 1
        
            If StringInStr($MyVal[$i], $sInput) <> 0 Then $sPartialData &= $MyVal[$i] & "|"
        Next
        GUICtrlSetData($hList, $sPartialData)
    EndIf
EndFunc   ;==>CheckInputText

Func WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    $nNotifyCode = BitShift($wParam, 16)
    $nID = BitAND($wParam, 0x0000FFFF)
    If $nID = $hInput Then
        $hCtrl = $lParam
        If $nNotifyCode = $EN_CHANGE Then
            $txt = GUICtrlRead($hInput)
            For $n = 1 To UBound($MyVal) - 1
            ;Msgbox(0,"Records found: " & $n, $MyVal[$n])
                If StringCompare(StringLeft($MyVal[$n], StringLen($txt)), $txt) = 0 Then
                    GUICtrlSetData($hList, $MyVal[$n])
                    
                    if GUICtrlRead($hInput) then
                    GUICtrlSetState($hList, $GUI_show)
                    else
                    GUICtrlSetState($hList, $GUI_Hide)
                    endif
                    
                    ExitLoop
                EndIf
            Next
            
        EndIf
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc  ;==>WM_COMMAND

Func SQLQuery()
$conn.Open($DSN)
$rs = ObjCreate( "ADODB.RecordSet" )
$rs.Open( "@@ PUT QUERY HERE @@", $conn )
If $RS.RecordCount Then
 While Not $RS.EOF
    $output = $output & StringStripWS($RS.Fields("@@ PUT TABLE HERE @@").Value,8) & "|" ; value of 4 columns on this line
    $RS.MoveNext
 WEnd
EndIf
global $MyVal = StringSplit($output,"|")
$conn.close
$sData = $output
    GUICtrlSetData($hList, $sData)
    $iCurrIndex = -1
    _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
EndFunc

Thank you everyone of the help! And if anyone is dealing with SQL issues and searches, go ahead and use this.  :sorcerer:

Dont forget to put the query and table at the bottom replacing the @@ signs ;)

1 person likes this

C0d3 is P0etry( ͡° ͜ʖ ͡°)

Share this post


Link to post
Share on other sites

Great stuff, works well.

Share this post


Link to post
Share on other sites

Hi everybody.

How to transform the following static list

$hList = GUICtrlCreateList("", 5, 30, 190, 325, BitOR(0x00100000, 0x00200000))

in a "popup menu" in Melba23's script ?

Thanks

Share this post


Link to post
Share on other sites
On 1/14/2014 at 7:58 AM, Melba23 said:

Kovacic,

 

Does this help at all? :huh:

 

#include <GUIConstantsEx.au3>
#include <Array.au3>
#Include <GuiListBox.au3>

Global $hGUI, $hInput, $hList, $sPartialData, $asKeyWords[100]

; Create list full of random 5 character "words"
Keywords()

$hGUI = GUICreate("Example", 200, 400)
$hInput = GUICtrlCreateInput("", 5, 5, 190, 20)
$hList = GUICtrlCreateList("", 5, 30, 190, 325, BitOR(0x00100000, 0x00200000))
$hButton = GUICtrlCreateButton("Read", 60, 360, 80, 30)
$hUP = GUICtrlCreateDummy()
$hDOWN = GUICtrlCreateDummy()
$hENTER = GUICtrlCreateDummy()
GUISetState(@SW_SHOW, $hGUI)

; Set accelerators for Cursor up/down and Enter
Dim $AccelKeys[3][2]=[["{UP}", $hUP], ["{DOWN}", $hDOWN], ["{ENTER}", $hENTER]]
GUISetAccelerators($AccelKeys)

$sCurr_Input = ""
$iCurrIndex = -1

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hList
            $sChosen = GUICtrlRead($hList)
            If $sChosen <> "" Then GUICtrlSetData($hInput, $sChosen)
        Case $hButton
            If $sPartialData <> "" Then
                $sFinal = GUICtrlRead($hInput)
                If _ArraySearch($asKeyWords, $sFinal) > 0 Then
                    MsgBox(0, "Chosen", $sFinal)
                EndIf
            EndIf
        Case $hUP
            If $sPartialData <> "" Then
                $iCurrIndex -= 1
                If $iCurrIndex < 0 Then $iCurrIndex = 0
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
        Case $hDOWN
            If $sPartialData <> "" Then
                $iTotal = _GUICtrlListBox_GetCount($hList)
                $iCurrIndex += 1
                If $iCurrIndex > $iTotal - 1 Then $iCurrIndex = $iTotal - 1
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
        Case $hENTER
            If $iCurrIndex <> -1 Then
                $sText = _GUICtrlListBox_GetText($hList, $iCurrIndex)
                GUICtrlSetData($hInput, $sText)
                $iCurrIndex = -1
                _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)
            EndIf
    EndSwitch

    ; If input has changed, refill list with matching items
    If GUICtrlRead($hInput) <> $sCurr_Input Then
        CheckInputText()
        $sCurr_Input = GUICtrlRead($hInput)
    EndIf

WEnd

Func CheckInputText()

    $sPartialData = "|" ; Start with delimiter so new data always replaces old
    Local $sInput = GUICtrlRead($hInput)
    If $sInput <> "" Then
        For $i = 0 To 99
            If StringInStr($asKeyWords[$i], $sInput) <> 0 Then $sPartialData &= $asKeyWords[$i] & "|"
        Next
        GUICtrlSetData($hList, $sPartialData)
    EndIf
EndFunc   ;==>CheckInputText

Func Keywords()

    Local $sData
    For $i = 0 To 99
        $asKeyWords[$i] = Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1))
        $sData &= $asKeyWords[$i] & "|"
    Next
    GUICtrlSetData($hList, $sData)
    $iCurrIndex = -1
    _GUICtrlListBox_SetCurSel($hList, $iCurrIndex)

EndFunc   ;==>Keywords

Please ask if anything is unclear. :)

 

M23

thank you Melba for this awesome script.  works great, except would it be possible to stay out of the while loop and do it instead with wm_notify?  i was also thinking of doing it in a combo box to simulate the searches in google.com

thanks again

Share this post


Link to post
Share on other sites

nvm i think i found another example

thanks anyway.. happy holidays

Share this post


Link to post
Share on other sites

gcue,

Quote

would it be possible to stay out of the while loop and do it instead with wm_notify?

You actually need WM_COMMAND:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <Array.au3>
#Include <GuiListBox.au3>

Global $hGUI, $cInput, $cList, $sPartialData, $asKeyWords[100]

; Create list full of random 5 character "words"
Keywords()

$hGUI = GUICreate("Example", 200, 400)

$cInput = GUICtrlCreateInput("", 5, 5, 190, 20)
$cList = GUICtrlCreateList("", 5, 30, 190, 325, BitOR(0x00100000, 0x00200000))
$cButton = GUICtrlCreateButton("Read", 60, 360, 80, 30)
$cUP = GUICtrlCreateDummy()
$cDOWN = GUICtrlCreateDummy()
$cENTER = GUICtrlCreateDummy()
GUISetState(@SW_SHOW, $hGUI)

; Set accelerators for Cursor up/down and Enter
Dim $AccelKeys[3][2]=[["{UP}", $cUP], ["{DOWN}", $cDOWN], ["{ENTER}", $cENTER]]
GUISetAccelerators($AccelKeys)

$iCurrIndex = -1

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cList
            $sChosen = GUICtrlRead($cList)
            If $sChosen <> "" Then GUICtrlSetData($cInput, $sChosen)
        Case $cButton
            If $sPartialData <> "" Then
                $sFinal = GUICtrlRead($cInput)
                If _ArraySearch($asKeyWords, $sFinal) > 0 Then
                    MsgBox(0, "Chosen", $sFinal)
                EndIf
            EndIf
        Case $cUP
            If $sPartialData <> "" Then
                $iCurrIndex -= 1
                If $iCurrIndex < 0 Then $iCurrIndex = 0
                _GUICtrlListBox_SetCurSel($cList, $iCurrIndex)
            EndIf
        Case $cDOWN
            If $sPartialData <> "" Then
                $iTotal = _GUICtrlListBox_GetCount($cList)
                $iCurrIndex += 1
                If $iCurrIndex > $iTotal - 1 Then $iCurrIndex = $iTotal - 1
                _GUICtrlListBox_SetCurSel($cList, $iCurrIndex)
            EndIf
        Case $cENTER
            If $iCurrIndex <> -1 Then
                $sText = _GUICtrlListBox_GetText($cList, $iCurrIndex)
                GUICtrlSetData($cInput, $sText)
                $iCurrIndex = -1
                _GUICtrlListBox_SetCurSel($cList, $iCurrIndex)
            EndIf
    EndSwitch

WEnd

Func CheckInputText()

    $sPartialData = "|" ; Start with delimiter so new data always replaces old
    Local $sInput = GUICtrlRead($cInput)
    If $sInput <> "" Then
        For $i = 0 To 99
            If StringInStr($asKeyWords[$i], $sInput) <> 0 Then $sPartialData &= $asKeyWords[$i] & "|"
        Next
        GUICtrlSetData($cList, $sPartialData)
    EndIf
EndFunc   ;==>CheckInputText

Func Keywords()

    Local $sData
    For $i = 0 To 99
        $asKeyWords[$i] = Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1)) & Chr(Random(65, 90, 1))
        $sData &= $asKeyWords[$i] & "|"
    Next
    GUICtrlSetData($cList, $sData)
    $iCurrIndex = -1
    _GUICtrlListBox_SetCurSel($cList, $iCurrIndex)

EndFunc   ;==>Keywords

Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)

     ; If it was an update message from our input
    If _WinAPI_HiWord($wParam) = $EN_CHANGE And _WinAPI_LoWord($wParam) = $cInput Then
       CheckInputText()
    EndIf

EndFunc

And if you want to do something similar with a combo, I suggest looking at _GUICtrlComboBox_AutoComplete in the Help file.

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

right thats what i meant... wm_command :)

thank you again for your help

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

  • Similar Content

    • DeathChicken
      By DeathChicken
      If possible please add or edit the comments to explain how this works.
       
      ;includes functions from other things
      #include <GDIPlus.au3>
      #include <ScreenCapture.au3>
      ;hotkeys
      HotKeySet("{ESC}", _exit)
      HotKeySet("{F1}", _scan)
      ;global variables
      Global $win_title                    ;name of the window
      Global $area_x                        ;
      Global $area_y                        ;
      Global $area_w                       ;
      Global $area_h                        ;
      Global $cursor                         ;
      Global $rect_file                      ;
      Global $hbmpscreen              ;
      Global $i=  1043                      ;moves the rect
      Global $ii=    378                      ;moves the rect
      Global $x=1044                        ;inner rect offset
      Global $y=501                          ;inner rect offset
      Global $hbmprect                    ;image inside rect
      Global $hscreen                        ;image whole screen
                                         
      _GDIPlus_Startup()                    ;?
      ;display hotkeys on screen
      ToolTip("Press F1 to scan | Press ESC to Exit",0,0)
                                          ;infinite loop to keep prog running
      While 1
          Sleep(100)
      WEnd
      Func _scan()
      ;~ reads your screen area:
      _read()
      ;~ converts screen captured into bmp
      _convert()
      ;~ .  Loads converted bmp to be read
      _loadBMP()
      ;~ compares the bmp of your scanned screen to the actual screen that is being displayed
      _compare()
      EndFunc
                                          ;reads screen
      Func _read()
          $hscreen = _ScreenCapture_CaptureWnd("", WinGetHandle($win_title), $area_x, $area_y, $area_x + $area_w, $area_y + $area_h, $cursor)
      EndFunc
                                          ;converts screen into bmp
      Func _convert()
          _GDIPlus_BitmapCreateFromHBITMAP($hscreen)
      EndFunc
                                          ;loads converted screen
      Func _loadBMP()
      _GDIPlus_BitmapCreateFromFile($rect_file)
      EndFunc
                                          ;compares savedBMP to current screen
      Func _compare()
      ;If(                              below code                                     ) = (                   below code           ) Then
      If _GDIPlus_BitmapGetPixel($hbmpscreen, ($i + $x) - $area_x, ($ii + $y) - $area_y) = _GDIPlus_BitmapGetPixel($hbmprect, $x, $y) Then
      ;display message box titled found with a message of found
      MsgBox("","","found")
      ;if above is not correct then
      EndIf
      EndFunc
                                          ;exit func
      Func _exit()
          Exit
      EndFunc
    • ct253704
      By ct253704
      Good morning,
      I am struggling to find a way to force a ControlClick on a particular hidden element within a Google Slides window. Using Au3Info doesn't work as the hidden text won't appear when attempting to gather the data. Using inspect element will show the class/title of the button, but using the class in the ControlClick function doesn't seem to do anything. Since this script is going to be running on multiple machines with different resolutions, MouseClick isn't a good option either. Can someone help me figure out how to click this full screen button?
      One more note - It says "Ctrl + Shift + F" for full screen, however sending that combo doesn't work - nor does actually using those keys on the keyboard. Possible conflict with AutoIT hotkeys? 
      Here's some sample code / screenshots to help:
      ControlClick($Title, "", "[CLASS:punch-viewer-icon punch-viewer-full-screen goog-inline-block]")  


    • way1000
      By way1000
      i'm trying to create a program that let's the user type a word in an input field (gui) and when a button is pressed the letters of the word are replaced by 1 word each from a list of words in a text file
      i created the gui for it but i need help to add some more code to make it work like intented

      each letter of a word should be replaced by a word from a text file
      the text file is a source for replacing letters is a file with 2 columns separated by tab that contains the entire alphabet (26 rows)
       
      please help if possible
       
      i posted an example gui screenshot

    • algiuxas
      By algiuxas
      Hello everybody, so I might found a bug in _ArraySearch:
       
      #include <Array.au3> Local $abc[2] = ["b", "b"] $h = "+---------------------------------+" & @CRLF ConsoleWrite($h) For $i = 0 To 1 $abc[0] = 0 out() $abc[0] = 1 out() $abc[0] = -1 out() $abc[0] = "Abc" out() $abc[1] = "Hello" Next Func txt() Return "$abc = [" & $abc[0] & ", " & $abc[1] & "]" & @CRLF & _ "> _ArraySearch($abc,""Hello"") = " EndFunc ;==>txt Func shouldoutput($ans) Return "_ArraySearch Should return: " & ($ans ? 1 : -1) EndFunc ;==>shouldoutput Func out() ConsoleWrite("> " & txt() & _ArraySearch($abc, "Hello") & @CRLF & "> " & shouldoutput($abc[1] == "Hello") & @CRLF & $h) EndFunc ;==>out Exit Sorry for this messy script
    • wakillon
      By wakillon
      Mp3SearchEngine v2.0.0.6

      May be some of you know Songr .
      This script do the same job, it can find more mp3 files but is not as fast as Songr.
       
       



      Sites used are music search engine Websites designed for LEGAL entertainment purposes only.
      Thanks to Brett Francis, Prog@ndy and Eukalyptus for >Bass Udf, trancex for >WinHttp Udf and the AutoIt Community for his help.

       
      Changes of v1.0.8.5
       
      Three websites replaced cause they are dead or use now js.
      All search engines updated ( not without difficulties for audiodump)
      I use RAGrid.dll for the first listview (more fast and stable, but with some inconvenients to manage the no-edit of cells)
      Input queries are saved ( the twenty latest)
      I use now an mp3 pre-Load management before playing and a double progressbar for visualize pre-load and play, where you can click for directly go play in the loaded part.
      Most includes needed are embedded and all external files are embedded in script with >BinaryToAu3Kompressor .
      Multi downloads available with embedded downloader.exe
       
      Changes of v1.0.8.8
      Search on audiodump and myfreemp3 fixed.
      New buttons.
      Added Gui Menu.
      Titles are no more editable.
      New "About" with >TaskDialog (Thanks Prog@andy)
      Query button permit now to check / uncheck all checkboxes
      And some few fixes and cleaning.
      Really more stable now.
      Changes of v1.0.9.2
      Dilandau is replaced by mp3chief and mp3ili by mp3clan 
      Search on mp3juices, baseofmp3 and soundcloud fixed.
      Soso now provide m4a (aac) instead of mp3 ( m4a can be played by MSE)
      Added possibility to encode automaticaly to mp3, aac or ogg ( at the end of download) using bassenc.dll and command line tools : lame, faac and oggenc.
       
      Changes of v1.0.9.3   mp3skull fixed mp3chief fixed myfreemp3 fixed mp3clan changed to tusmp3  mp3juices changed to emp3world baseofmp3 changed to imp3 and some minor improvements.  
      Version 2.0.0.6
      Most previous websites used are dead or have changed the way to get links, 
      so instead of try to repair the previous version, i have created a complete new version.
      The main tendency is the simplification :
      Only one website : audiodump (Up to 500 results by request)
      Script use now the little pearl created by Ward : curl.au3
      It permit to create tasks (get source and get multi mp3) in asynchronous mode.
      So now, no need to use several executables and no more gui who do not respond in case of connection problems. 
      Script use Bass.dll X86 loaded in memory for play songs.
      Result is light and fast, but don't abuse of audiodump servers who are not beasts of race.
      Warning : For avoid errors with curl.au3, you'll need to comment the line 63 : ;~ #Include <BinaryCall.au3>
      @AutoItX64 not supported and only tested on Win7X64 and Win8.1X64.
      As your browser, use Ctrl+w for remove the current Tab.(if there is no search or download running from it)
      And also Ctrl+q for set/remove Gridlines.
      Events are displayed to the bottom of the Gui.
       
      Version 2.0.1.1
      Added a Paste Button.
      Querry list is now correctly saved.
      Querry Combo is now sorted in alphabetical order
      After a 'No match', the next search will use the previous empty listview.
      Bug when removing tabs is corrected.
      Added string correction for the request that, in the previous version, was not always able to return a correct result.
       
      A big thanks to Ward for his great UDF, and Nina my favorite tester, (who between us is also my third daughter), for his precious advices .
      previous downloads : 1703
       
      As there is no more script downloads count, source and executable are available in the downloads section

      Enjoy ! 
      July 2017 Project Discontinued due to website changes