Jump to content
Sign in to follow this  

Feature request?

Recommended Posts


I'd posted once a month or two ago that I thought changing a few lines in _GUICtrlComboBox_AutoComplete made it a little more functional, and possibly improved it's appearance. I got zero comments, so I'll make life easy and include a stand-alone side-by-side comparison script. The changes basically make the autocomplete driven by cursor position, rather than maintaining a portion of the string as highlighted and using that to drive the function. This changes the appearance of strings in the autocomplete, I think making them somewhat easier to read, but the main change is that basing off of cursor position allows one to process the delete and backspace characters, rather than having to ignore them.

I loaded up quite a few "A" strings for testing in the array, but feel free to play.

Ok, I have my body armor on... Comments?

#include <WindowsConstants.au3>
#include <GuiConstants.au3>
#include <GuiComboBox.au3>

$list = "Aaron|Ada|Adams|Adamsville|Adell|Adelman|Adenson|Akron|Appleton|Bannock|Bear Lake|Benewah|Bingham|Blaine|Boise|Bonner|Bonneville|" & _

ooding|Idaho|Jefferson|Jerome|" & _

win Falls|Valley|Washington"
GUICreate("_GUICtrlComboBox_AutoComplete comparison",430,180)
GUICtrlCreateLabel(StringReplace($list,"|","   "), 10, 10, 400, 100)
GUICtrlCreateLabel("CURRENT VERSION", 10, 110, 200)
$Ctrl_Combo1 = GUICtrlCreateCombo("", 10, 130, 200)
GUICtrlSetData($Ctrl_Combo1, $list)

GUICtrlCreateLabel("MODIFIED VERSION", 220, 110, 200)
$Ctrl_Combo2 = GUICtrlCreateCombo("", 220, 130, 200)
GUICtrlSetData($Ctrl_Combo2, $list)

GUICtrlCreateLabel("The delete and backspace keys are functional only in the modified version.", 10, 160, 400)

While 1 
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit


Func _GUICtrlComboBox_AutoComplete2($hWnd)
    Local $ret, $sInputText, $sEditText, $sEditSel
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)   
    $sEditSel = _GUICtrlComboBox_GetEditSel($hWnd)
    If IsArray($sEditSel) Then 
        $sEditSel = $sEditSel[0]
    $sEditText = StringLeft(_GUICtrlComboBox_GetEditText($hWnd), $sEditSel)
    _GUICtrlComboBox_SetEditText($hWnd, $sEditText)
    If StringLen($sEditText) Then
        $ret = _GUICtrlComboBox_FindString($hWnd, $sEditText)
        If ($ret <> $CB_ERR) Then
            _GUICtrlComboBox_SetCurSel($hWnd, $ret)
        _GUICtrlComboBox_SetEditSel($hWnd, $sEditSel, $sEditSel)
EndFunc ;==>_GUICtrlComboBox_AutoComplete2

Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    $nNotifyCode    = BitShift($wParam, 16)   ;HiWord
    $nID            = BitAnd($wParam, 0x0000FFFF);LoWord
    If $nID = $Ctrl_Combo1 Then
            Switch $nNotifyCode
                Case $CBN_EDITCHANGE
    If $nID = $Ctrl_Combo2 Then
            Switch $nNotifyCode
                Case $CBN_EDITCHANGE

Share this post

Link to post
Share on other sites

Does seem a little nicer IMO, maybe have both versions in the same function, and add an option parameter as a switch to set which? My 2 cents :)



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
Sign in to follow this