Jump to content

_GUICtrlComboBox_AutoValidate


czardas
 Share

Recommended Posts

This script is an adaptation of _GUICtrlComboBox_AutoComplete by Gary Frost. The Combo Edit control will change colour if no exact match is found. The function supports cutting the last portion of the combo edit text without automatically replacing it (which is different to the original function by Gary) and returns a value to indicate what action has been taken if any. Pretty simple, but someone might find it useful. I tried to choose a useful subject for the example.

The example is included in the same script along with the function, so you can just run it at your leisure. Undoubtedly there are other ways to do this. Any suggestions for improvememnt would be welcome. Thanks!

#include <GUIComboBox.au3>
#include <GuiConstants.au3>

; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlComboBox_AutoValidate
; Description ...: Auto completes valid input and sets the Combo Edit background colour to red when control contains invalid input.
; Syntax.........: _GUICtrlComboBox_AutoValidate($sComboHistory, $hControl)
; Parameters ....: $hControl = The control ID returned by GUICtrlCreateCombo
;                 $sComboHistory = Variable to store previous text from the Combo Edit
; Return values .: 0 = No changes have occured to the Combo Edit (Requires no action)
;                 1 = Combo Edit contains a full valid string after auto completion
;                -1 = Combo Edit does not contain a full valid string
;                 $sComboHistory is updated (ByRef) when the return value does not equal zero
; Author ........: czardas
; Remarks .......: Adapted from the original _GUICtrlComboBox_AutoComplete by Gary Frost
;                 Minimum OS: Windows XP
;                 Required Includes: GUIComboBox.au3 , Misc.au3, GuiConstants.au3
; Example .......: Yes
; ===============================================================================================================================

Func _GUICtrlComboBox_AutoValidate(ByRef $sComboHistory, $hControl)

    $hCombo = $hControl
    If Not IsHWnd($hControl) Then $hControl = GUICtrlGetHandle($hControl)
    Local $iEditBkColor = 0xFFFFFF, $iErrorColor = 0xFFA090, _
    $sEditText = _GUICtrlComboBox_GetEditText($hControl)

    If __GUICtrlComboBox_IsPressed("11") And __GUICtrlComboBox_IsPressed("5A") Then ; Ctrl+Z (Undo)
        If _GUICtrlComboBox_FindStringExact($hControl, $sEditText) = -1 Then $iEditBkColor = $iErrorColor
        $sComboHistory = $sEditText
    ElseIf Not ($sEditText == $sComboHistory) Then ; Text has changed.
        $sComboHistory = $sEditText
        If StringLen($sEditText) Then
            Local $ret = _GUICtrlComboBox_FindString($hControl, $sEditText)
            If ($ret <> $CB_ERR) Then
                If Not (__GUICtrlComboBox_IsPressed("26") Or __GUICtrlComboBox_IsPressed("28")) Then ; Up or Down arrow key always auto complete.
                    If Not (__GUICtrlComboBox_IsPressed('08') Or __GUICtrlComboBox_IsPressed("2E")) Then ; Backspace or Delete
                        Local $sInputText
                        _GUICtrlComboBox_GetLBText($hControl, $ret, $sInputText)
                        If __GUICtrlComboBox_IsPressed("11") And __GUICtrlComboBox_IsPressed("58") Then ; Ctrl+X (Cut)
                            If _GUICtrlComboBox_FindStringExact($hControl, $sEditText) = -1 Then
                                $iEditBkColor = $iErrorColor
                            Else ; Resume with auto completion
                                If $sInputText <> $sEditText Then _GUICtrlComboBox_SetEditText($hControl, $sInputText)
                                _GUICtrlComboBox_SetEditSel($hControl, StringLen($sEditText), StringLen($sInputText))
                                $sComboHistory = $sInputText
                            EndIf
                        Else ; Resume with auto completion
                            _GUICtrlComboBox_SetEditText($hControl, $sInputText)
                            _GUICtrlComboBox_SetEditSel($hControl, StringLen($sEditText), StringLen($sInputText))
                            $sComboHistory = $sInputText
                        EndIf
                    Else ; Backspace or delete were pressed
                        If _GUICtrlComboBox_FindStringExact($hControl, $sEditText) = -1 Then
                            $iEditBkColor = $iErrorColor
                        Else
                            _GUICtrlComboBox_SetCurSel($hControl, $ret) ; In the event of case disparities.
                        EndIf
                    EndIf
                ElseIf _GUICtrlComboBox_FindStringExact($hControl, $sEditText) = -1 Then ; Write errors sometimes occur when keys are held down.
                    $iEditBkColor = $iErrorColor
                EndIf
            Else ; The string was not found.
                $iEditBkColor = $iErrorColor
            EndIf
        Else ; The control contains an empty string.
            $iEditBkColor = $iErrorColor
        EndIf
    Else
        Return 0 ; No changes have occured.
    EndIf

    GUICtrlSetBkColor($hCombo, $iEditBkColor)
    GUICtrlSetState($hCombo, $GUI_SHOW)
    If $iEditBkColor = $iErrorColor Then
        Return -1 ; The combo edit does not (currently) contain a FULL valid string.
    Else
        Return 1 ; The combo edit contains a valid string.
    EndIf
EndFunc   ;==> _GUICtrlComboBox_AutoValidate

; ===============================================================================================================================

; EXAMPLE

; Don't forget the includes required by the function _GUICtrlComboBox_AutoValidate (SEE DESCRIPTION)

#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>

_Main()

Func _Main()
    Local $hGUI = GUICreate("Color Combo Test", 280, 250)
    Local $hInputControl = _CreateCombo(), $sValidated = "" ; These vatiables are passed to the function.
    Local $hColorLabel = GUICtrlCreateLabel("", 10, 50, 260, 145, BitOR($SS_NOTIFY ,$SS_CENTER, $SS_SUNKEN))
    GUICtrlSetFont(-1, 15, 500)
    Local $hEdit = GUICtrlCreateEdit("", 100, 210, 80, 22, $ES_READONLY)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    GUICtrlSetFont(-1, 11, 500)
    GUISetState()

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

        $iRet = _GUICtrlComboBox_AutoValidate($sValidated, $hInputControl)
        If $iRet = 1 Then
            _UpdateColorLabel($hInputControl, $hColorLabel, $sValidated)
            _UpdateEdit($hInputControl, $hEdit, $sValidated)
        ElseIf $iRet = -1 Then
            GUICtrlSetBkColor($hColorLabel, 0xD0D0D0)
            GUICtrlSetData($hColorLabel, @LF & @LF & "No Preview Available")
            GUICtrlSetData($hEdit, "#??????")
        EndIf
    WEnd
EndFunc

Func _GetColors()
    Local $asColors[765][2] = _
    [["Air Force blue","0x5D8AA8"],["Alice blue","0xF0F8FF"],["Alizarin crimson","0xE32636"],["Almond","0xEFDECD"], _
    ["Amaranth","0xE52B50"],["Amber","0xFFBF00"],["Amber (SAE/ECE)","0xFF7E00"],["American rose","0xFF033E"], _
    ["Amethyst","0x9966CC"],["Android Green","0xA4C639"],["Anti-flash white","0xF2F3F4"],["Antique brass","0xCD9575"], _
    ["Antique fuchsia","0x915C83"],["Antique white","0xFAEBD7"],["Ao (English)","0x008000"],["Apple green","0x8DB600"], _
    ["Apricot","0xFBCEB1"],["Aqua","0x00FFFF"],["Aquamarine","0x7FFFD4"],["Army green","0x4B5320"],["Arsenic","0x3B444B"], _
    ["Arylide yellow","0xE9D66B"],["Ash grey","0xB2BEB5"],["Asparagus","0x87A96B"],["Atomic tangerine","0xFF9966"], _
    ["Auburn","0x6D351A"],["Aureolin","0xFDEE00"],["AuroMetalSaurus","0x6E7F80"],["Awesome","0xFF2052"],["Azure","0x007FFF"], _
    ["Azure mist/web","0xF0FFFF"],["Baby blue","0x89CFF0"],["Baby blue eyes","0xA1CAF1"],["Baby pink","0xF4C2C2"], _
    ["Ball Blue","0x21ABCD"],["Banana Mania","0xFAE7B5"],["Banana yellow","0xFFE135"],["Battleship grey","0x848482"], _
    ["Bazaar","0x98777B"],["Beau blue","0xBCD4E6"],["Beaver","0x9F8170"],["Beige","0xF5F5DC"],["Bisque","0xFFE4C4"], _
    ["Bistre","0x3D2B1F"],["Bittersweet","0xFE6F5E"],["Black","0x000000"],["Blanched Almond","0xFFEBCD"], _
    ["Bleu de France","0x318CE7"],["Blizzard Blue","0xACE5EE"],["Blond","0xFAF0BE"],["Blue","0x0000FF"], _
    ["Blue (Munsell)","0x0093AF"],["Blue (NCS)","0x0087BD"],["Blue (pigment)","0x333399"],["Blue (RYB)","0x0247FE"], _
    ["Blue Bell","0xA2A2D0"],["Blue Gray","0x6699CC"],["Blue-green","0x00DDDD"],["Blue-violet","0x8A2BE2"], _
    ["Blush","0xDE5D83"],["Bole","0x79443B"],["Bondi blue","0x0095B6"],["Boston University Red","0xCC0000"], _
    ["Brandeis blue","0x0070FF"],["Brass","0xB5A642"],["Brick red","0xCB4154"],["Bright cerulean","0x1DACD6"], _
    ["Bright green","0x66FF00"],["Bright lavender","0xBF94E4"],["Bright maroon","0xC32148"],["Bright pink","0xFF007F"], _
    ["Bright turquoise","0x08E8DE"],["Bright ube","0xD19FE8"],["Brilliant lavender","0xF4BBFF"],["Brilliant rose","0xFF55A3"], _
    ["Brink pink","0xFB607F"],["British racing green","0x004225"],["Bronze","0xCD7F32"],["Brown (traditional)","0x964B00"], _
    ["Brown (web)","0xA52A2A"],["Bubble gum","0xFFC1CC"],["Bubbles","0xE7FEFF"],["Buff","0xF0DC82"],["Bulgarian rose","0x480607"], _
    ["Burgundy","0x800020"],["Burlywood","0xDEB887"],["Burnt orange","0xCC5500"],["Burnt sienna","0xE97451"], _
    ["Burnt umber","0x8A3324"],["Byzantine","0xBD33A4"],["Byzantium","0x702963"],["Cadet","0x536872"],["Cadet blue","0x5F9EA0"], _
    ["Cadet grey","0x91A3B0"],["Cadmium Green","0x006B3C"],["Cadmium Orange","0xED872D"],["Cadmium Red","0xE30022"], _
    ["Cadmium Yellow","0xFFF600"],["Cal Poly Pomona green","0x1E4D2B"],["Cambridge Blue","0xA3C1AD"],["Camel","0xC19A6B"], _
    ["Camouflage green","0x78866B"],["Canary yellow","0xFFEF00"],["Candy apple red","0xFF0800"],["Candy pink","0xE4717A"], _
    ["Capri","0x00BFFF"],["Caput mortuum","0x592720"],["Cardinal","0xC41E3A"],["Caribbean green","0x00CC99"], _
    ["Carmine","0x960018"],["Carmine pink","0xEB4C42"],["Carmine red","0xFF0038"],["Carnation pink","0xFFA6C9"], _
    ["Carnelian","0xB31B1B"],["Carolina blue","0x99BADD"],["Carrot orange","0xED9121"],["Ceil","0x92A1CF"],["Celadon","0xACE1AF"], _
    ["Celestial blue","0x4997D0"],["Cerise","0xDE3163"],["Cerise pink","0xEC3B83"],["Cerulean","0x007BA7"], _
    ["Cerulean blue","0x2A52BE"],["Chamoisee","0xA0785A"],["Champagne","0xF7E7CE"],["Charcoal","0x36454F"], _
    ["Chartreuse (traditional)","0xDFFF00"],["Chartreuse (web)","0x7FFF00"],["Cherry blossom pink","0xFFB7C5"], _
    ["Chestnut","0xCD5C5C"],["Chocolate (traditional)","0x7B3F00"],["Chocolate (web)","0xD2691E"],["Chrome yellow","0xFFA700"], _
    ["Cinereous","0x98817B"],["Cinnabar","0xE34234"],["Cinnamon","0xD2691E"],["Citrine","0xE4D00A"],["Classic rose","0xFBCCE7"], _
    ["Cobalt","0x0047AB"],["Cocoa brown","0xD2691E"],["Coffee","0xC86428"],["Columbia blue","0x9BDDFF"],["Cool black","0x002E63"], _
    ["Cool grey","0x8C92AC"],["Copper","0xB87333"],["Copper rose","0x996666"],["Coquelicot","0xFF3800"],["Coral","0xFF7F50"], _
    ["Coral pink","0xF88379"],["Coral red","0xFF4040"],["Cordovan","0x893F45"],["Corn","0xFBEC5D"],["Cornell Red","0xB31B1B"], _
    ["Cornflower blue","0x6495ED"],["Cornsilk","0xFFF8DC"],["Cosmic latte","0xFFF8E7"],["Cotton candy","0xFFBCD9"], _
    ["Cream","0xFFFDD0"],["Crimson","0xDC143C"],["Crimson glory","0xBE0032"],["Cyan","0x00FFFF"],["Cyan (process)","0x00B7EB"], _
    ["Daffodil","0xFFFF31"],["Dandelion","0xF0E130"],["Dark blue","0x00008B"],["Dark brown","0x654321"], _
    ["Dark byzantium","0x5D3954"],["Dark candy apple red","0xA40000"],["Dark cerulean","0x08457E"],["Dark champagne","0xC2B280"], _
    ["Dark chestnut","0x986960"],["Dark coral","0xCD5B45"],["Dark cyan","0x008B8B"],["Dark electric blue","0x536878"], _
    ["Dark goldenrod","0xB8860B"],["Dark gray","0xA9A9A9"],["Dark green","0x013220"],["Dark jungle green","0x1A2421"], _
    ["Dark khaki","0xBDB76B"],["Dark lava","0x483C32"],["Dark lavender","0x734F96"],["Dark magenta","0x8B008B"], _
    ["Dark midnight blue","0x003366"],["Dark olive green","0x556B2F"],["Dark orange","0xFF8C00"],["Dark orchid","0x9932CC"], _
    ["Dark pastel blue","0x779ECB"],["Dark pastel green","0x03C03C"],["Dark pastel purple","0x966FD6"], _
    ["Dark pastel red","0xC23B22"],["Dark pink","0xE75480"],["Dark powder blue","0x003399"],["Dark raspberry","0x872657"], _
    ["Dark red","0x8B0000"],["Dark salmon","0xE9967A"],["Dark scarlet","0x560319"],["Dark sea green","0x8FBC8F"], _
    ["Dark sienna","0x3C1414"],["Dark slate blue","0x483D8B"],["Dark slate gray","0x2F4F4F"],["Dark spring green","0x177245"], _
    ["Dark tan","0x918151"],["Dark tangerine","0xFFA812"],["Dark taupe","0x483C32"],["Dark terra cotta","0xCC4E5C"], _
    ["Dark turquoise","0x00CED1"],["Dark violet","0x9400D3"],["Dartmouth green","0x00693E"],["Davy's grey","0x555555"], _
    ["Debian red","0xD70A53"],["Deep carmine","0xA9203E"],["Deep carmine pink","0xEF3038"],["Deep carrot orange","0xE9692C"], _
    ["Deep cerise","0xDA3287"],["Deep champagne","0xFAD6A5"],["Deep chestnut","0xB94E48"],["Deep fuchsia","0xC154C1"], _
    ["Deep jungle green","0x004B49"],["Deep lilac","0x9955BB"],["Deep magenta","0xCC00CC"],["Deep peach","0xFFCBA4"], _
    ["Deep pink","0xFF1493"],["Deep saffron","0xFF9933"],["Deep sky blue","0x00BFFF"],["Denim","0x1560BD"],["Desert","0xC19A6B"], _
    ["Desert sand","0xEDC9AF"],["Dim gray","0x696969"],["Dodger blue","0x1E90FF"],["Dogwood rose","0xD71868"], _
    ["Dollar bill","0x85BB65"],["Drab","0x967117"],["Duke blue","0x00009C"],["Earth yellow","0xE1A95F"],["Ecru","0xC2B280"], _
    ["Eggplant","0x614051"],["Eggshell","0xF0EAD6"],["Egyptian blue","0x1034A6"],["Electric blue","0x7DF9FF"], _
    ["Electric crimson","0xFF003F"],["Electric cyan","0x00FFFF"],["Electric green","0x00FF00"],["Electric indigo","0x6F00FF"], _
    ["Electric lavender","0xF4BBFF"],["Electric lime","0xCCFF00"],["Electric purple","0xBF00FF"],["Electric ultramarine","0x3F00FF"], _
    ["Electric violet","0x8F00FF"],["Electric yellow","0xFFFF00"],["Emerald","0x50C878"],["Eton blue","0x96C8A2"], _
    ["Fallow","0xC19A6B"],["Falu red","0x801818"],["Fandango","0xB53389"],["Fashion fuchsia","0xF400A1"],["Fawn","0xE5AA70"], _
    ["Feldgrau","0x4D5D53"],["Fern green","0x4F7942"],["Ferrari Red","0xFF2800"],["Field drab","0x6C541E"],["Firebrick","0xB22222"], _
    ["Fire engine red","0xCE2029"],["Flame","0xE25822"],["Flamingo pink","0xFC8EAC"],["Flavescent","0xF7E98E"],["Flax","0xEEDC82"], _
    ["Floral white","0xFFFAF0"],["Fluorescent orange","0xFFBF00"],["Fluorescent pink","0xFF1493"],["Fluorescent yellow","0xCCFF00"], _
    ["Folly","0xFF004F"],["Forest green (traditional)","0x014421"],["Forest green (web)","0x228B22"],["French beige","0xA67B5B"], _
    ["French blue","0x0072BB"],["French lilac","0x86608E"],["French rose","0xF64A8A"],["Fuchsia","0xFF00FF"], _
    ["Fuchsia pink","0xFF77FF"],["Fulvous","0xE48400"],["Fuzzy Wuzzy","0xCC6666"],["Gainsboro","0xDCDCDC"],["Gamboge","0xE49B0F"], _
    ["Ghost white","0xF8F8FF"],["Ginger","0xB06500"],["Glaucous","0x6082B6"],["Gold (metallic)","0xD4AF37"], _
    ["Gold (web) (Golden)","0xFFD700"],["Golden brown","0x996515"],["Golden poppy","0xFCC200"],["Golden yellow","0xFFDF00"], _
    ["Goldenrod","0xDAA520"],["Granny Smith Apple","0xA8E4A0"],["Gray","0x808080"],["Gray (HTML/CSS gray)","0x7F7F7F"], _
    ["Gray (X11 gray)","0xBEBEBE"],["Gray-asparagus","0x465945"],["Green (color wheel) (X11 green)","0x00FF00"], _
    ["Green (HTML/CSS green)","0x008000"],["Green (Munsell)","0x00A877"],["Green (NCS)","0x009F6B"],["Green (pigment)","0x00A550"], _
    ["Green (RYB)","0x66B032"],["Green-yellow","0xADFF2F"],["Grullo","0xA99A86"],["Guppie green","0x00FF7F"], _
    ["Halaya ube","0x663854"],["Han blue","0x446CCF"],["Han purple","0x5218FA"],["Hansa yellow","0xE9D66B"],["Harlequin","0x3FFF00"], _
    ["Harvard crimson","0xC90016"],["Harvest Gold","0xDA9100"],["Heart Gold","0x808000"],["Heliotrope","0xDF73FF"], _
    ["Hollywood cerise","0xF400A1"],["Honeydew","0xF0FFF0"],["Hooker's green","0x007000"],["Hot magenta","0xFF1DCE"], _
    ["Hot pink","0xFF69B4"],["Hunter green","0x355E3B"],["Iceberg","0x71A6D2"],["Icterine","0xFCF75E"],["Inchworm","0xB2EC5D"], _
    ["India green","0x138808"],["Indian red","0xCD5C5C"],["Indian yellow","0xE3A857"],["Indigo (dye)","0x00416A"], _
    ["Indigo (web)","0x4B0082"],["International Klein Blue","0x002FA7"],["International orange","0xFF4F00"],["Iris","0x5A4FCF"], _
    ["Isabelline","0xF4F0EC"],["Islamic green","0x009000"],["Ivory","0xFFFFF0"],["Jade","0x00A86B"],["Jasper","0xD73B3E"], _
    ["Jasmine","0xF8DE7E"],["Jazzberry jam","0xA50B5E"],["Jonquil","0xFADA5E"],["June bud","0xBDDA57"],["Jungle green","0x29AB87"], _
    ["Kelly green","0x4CBB17"],["Khaki (HTML/CSS) (Khaki)","0xC3B091"],["Khaki (X11) (Light khaki)","0xF0E68C"], _
    ["KU Crimson","0xE8000D"],["La Salle Green","0x087830"],["Languid lavender","0xD6CADD"],["Lapis lazuli","0x26619C"], _
    ["Laser Lemon","0xFEFE22"],["Lava","0xCF1020"],["Lavender (floral)","0xB57EDC"],["Lavender (web)","0xE6E6FA"], _
    ["Lavender blue","0xCCCCFF"],["Lavender blush","0xFFF0F5"],["Lavender gray","0xC4C3D0"],["Lavender indigo","0x9457EB"], _
    ["Lavender magenta","0xEE82EE"],["Lavender mist","0xE6E6FA"],["Lavender pink","0xFBAED2"],["Lavender purple","0x967BB6"], _
    ["Lavender rose","0xFBA0E3"],["Lawn green","0x7CFC00"],["Lemon","0xFFF700"],["Lemon chiffon","0xFFFACD"], _
    ["Light apricot","0xFDD5B1"],["Light blue","0xADD8E6"],["Light brown","0xB5651D"],["Light carmine pink","0xE66771"], _
    ["Light coral","0xF08080"],["Light cornflower blue","0x93CCEA"],["Light Crimson","0xF56991"],["Light cyan","0xE0FFFF"], _
    ["Light fuchsia pink","0xF984EF"],["Light goldenrod yellow","0xFAFAD2"],["Light gray","0xD3D3D3"],["Light green","0x90EE90"], _
    ["Light khaki","0xF0E68C"],["Light mauve","0xDCD0FF"],["Light pastel purple","0xB19CD9"],["Light pink","0xFFB6C1"], _
    ["Light salmon","0xFFA07A"],["Light salmon pink","0xFF9999"],["Light sea green","0x20B2AA"],["Light sky blue","0x87CEEB"], _
    ["Light slate gray","0x778899"],["Light taupe","0xB38B6D"],["Light Thulian pink","0xE68FAC"],["Light yellow","0xFFFFED"], _
    ["Lilac","0xC8A2C8"],["Lime (color wheel)","0xBFFF00"],["Lime (web) (X11 green)","0x00FF00"],["Lime green","0x32CD32"], _
    ["Lincoln green","0x195905"],["Linen","0xFAF0E6"],["Liver","0x534B4F"],["Lust","0xE62020"],["Macaroni and Cheese","0xFFBD88"], _
    ["Magenta","0xFF00FF"],["Magenta (dye)","0xCA1F7B"],["Magenta (process)","0xFF0090"],["Magic mint","0xAAF0D1"], _
    ["Magnolia","0xF8F4FF"],["Mahogany","0xC04000"],["Maize","0xFBEC5D"],["Majorelle Blue","0x6050DC"],["Malachite","0x0BDA51"], _
    ["Manatee","0x979AAA"],["Mango Tango","0xFF8243"],["Maroon (HTML/CSS)","0x800000"],["Maroon (X11)","0xB03060"], _
    ["Mauve","0xE0B0FF"],["Mauve taupe","0x915F6D"],["Mauvelous","0xEF98AA"],["Maya blue","0x73C2FB"],["Meat brown","0xE5B73B"], _
    ["Medium aquamarine","0x66DDAA"],["Medium blue","0x0000CD"],["Medium candy apple red","0xE2062C"], _
    ["Medium carmine","0xAF4035"],["Medium champagne","0xF3E5AB"],["Medium electric blue","0x035096"], _
    ["Medium jungle green","0x1C352D"],["Medium lavender magenta","0xDDA0DD"],["Medium orchid","0xBA55D3"], _
    ["Medium Persian blue","0x0067A5"],["Medium purple","0x9370DB"],["Medium red-violet","0xBB3385"], _
    ["Medium sea green","0x3CB371"],["Medium slate blue","0x7B68EE"],["Medium spring bud","0xC9DC87"], _
    ["Medium spring green","0x00FA9A"],["Medium taupe","0x674C47"],["Medium teal blue","0x0054B4"], _
    ["Medium turquoise","0x48D1CC"],["Medium violet-red","0xC71585"],["Melon","0xFDBCB4"],["Midnight blue","0x191970"], _
    ["Midnight green (eagle green)","0x004953"],["Mikado yellow","0xFFC40C"],["Mint","0x3EB489"],["Mint cream","0xF5FFFA"], _
    ["Mint green","0x98FF98"],["Misty rose","0xFFE4E1"],["Moccasin","0xFAEBD7"],["Mode beige","0x967117"], _
    ["Moonstone blue","0x73A9C2"],["Mordant red 19","0xAE0C00"],["Moss green","0xADDFAD"],["Mountain Meadow","0x30BA8F"], _
    ["Mountbatten pink","0x997A8D"],["Mulberry","0xC54B8C"],["Mustard","0xFFDB58"],["Myrtle","0x21421E"], _
    ["MSU Green","0x18453B"],["Nadeshiko pink","0xF6ADC6"],["Napier green","0x2A8000"],["Naples yellow","0xFADA5E"], _
    ["Navajo white","0xFFDEAD"],["Navy blue","0x000080"],["Neon Carrot","0xFFA343"],["Neon fuchsia","0xFE59C2"], _
    ["Neon green","0x39FF14"],["Non-photo blue","0xA4DDED"],["Ocean Boat Blue","0x0077BE"],["Ochre","0xCC7722"], _
    ["Office green","0x008000"],["Old gold","0xCFB53B"],["Old lace","0xFDF5E6"],["Old lavender","0x796878"], _
    ["Old mauve","0x673147"],["Old rose","0xC08081"],["Olive","0x808000"],["Olive Drab (web) (Olive Drab #3)","0x6B8E23"], _
    ["Olive Drab #7","0x3C341F"],["Olivine","0x9AB973"],["Onyx","0x0F0F0F"],["Opera mauve","0xB784A7"], _
    ["Orange (color wheel)","0xFF7F00"],["Orange (RYB)","0xFB9902"],["Orange (web color)","0xFFA500"], _
    ["Orange peel","0xFF9F00"],["Orange-red","0xFF4500"],["Orchid","0xDA70D6"],["Otter brown","0x654321"], _
    ["Outer Space","0x414A4C"],["Outrageous Orange","0xFF6E4A"],["Oxford Blue","0x002147"],["OU Crimson Red","0x990000"], _
    ["Pakistan green","0x006600"],["Palatinate blue","0x273BE2"],["Palatinate purple","0x682860"],["Pale aqua","0xBCD4E6"], _
    ["Pale blue","0xAFEEEE"],["Pale brown","0x987654"],["Pale carmine","0xAF4035"],["Pale cerulean","0x9BC4E2"], _
    ["Pale chestnut","0xDDADAF"],["Pale copper","0xDA8A67"],["Pale cornflower blue","0xABCDEF"],["Pale gold","0xE6BE8A"], _
    ["Pale goldenrod","0xEEE8AA"],["Pale green","0x98FB98"],["Pale magenta","0xF984E5"],["Pale pink","0xFADADD"], _
    ["Pale plum","0xDDA0DD"],["Pale red-violet","0xDB7093"],["Pale robin egg blue","0x96DED1"],["Pale silver","0xC9C0BB"], _
    ["Pale spring bud","0xECEBBD"],["Pale taupe","0xBC987E"],["Pale violet-red","0xDB7093"],["Pansy purple","0x78184A"], _
    ["Papaya whip","0xFFEFD5"],["Paris Green","0x50C878"],["Pastel blue","0xAEC6CF"],["Pastel brown","0x836953"], _
    ["Pastel gray","0xCFCFC4"],["Pastel green","0x77DD77"],["Pastel magenta","0xF49AC2"],["Pastel orange","0xFFB347"], _
    ["Pastel pink","0xFFD1DC"],["Pastel purple","0xB39EB5"],["Pastel red","0xFF6961"],["Pastel violet","0xCB99C9"], _
    ["Pastel yellow","0xFDFD96"],["Patriarch","0x800080"],["Payne's grey","0x40404F"],["Peach","0xFFE5B4"], _
    ["Peach-orange","0xFFCC99"],["Peach puff","0xFFDAB9"],["Peach-yellow","0xFADFAD"],["Pear","0xD1E231"],["Pearl","0xF0EAD6"], _
    ["Pearl Aqua","0x88D8C0"],["Peridot","0xE6E200"],["Periwinkle","0xCCCCFF"],["Persian blue","0x1C39BB"], _
    ["Persian green","0x00A693"],["Persian indigo","0x32127A"],["Persian orange","0xD99058"],["Persian pink","0xF77FBE"], _
    ["Persian plum","0x701C1C"],["Persian red","0xCC3333"],["Persian rose","0xFE28A2"],["Persimmon","0xEC5800"], _
    ["Phlox","0xDF00FF"],["Phthalo blue","0x000F89"],["Phthalo green","0x123524"],["Piggy pink","0xFDDDE6"], _
    ["Pine green","0x01796F"],["Pink","0xFFC0CB"],["Pink-orange","0xFF9966"],["Pink pearl","0xE7ACCF"],["Pink Sherbet","0xF78FA7"], _
    ["Pistachio","0x93C572"],["Platinum","0xE5E4E2"],["Plum (traditional)","0x8E4585"],["Plum (web)","0xDDA0DD"], _
    ["Portland Orange","0xFF5A36"],["Powder blue (web)","0xB0E0E6"],["Princeton orange","0xFF8F00"],["Prune","0x701C1C"], _
    ["Prussian blue","0x003153"],["Psychedelic purple","0xDF00FF"],["Puce","0xCC8899"],["Pumpkin","0xFF7518"], _
    ["Purple (HTML/CSS)","0x800080"],["Purple (Munsell)","0x9F00C5"],["Purple (X11)","0xA020F0"],["Purple Heart","0x69359C"], _
    ["Purple mountain majesty","0x9678B6"],["Purple pizzazz","0xFE4EDA"],["Purple taupe","0x50404D"],["Radical Red","0xFF355E"], _
    ["Raspberry","0xE30B5D"],["Raspberry glace","0x915F6D"],["Raspberry pink","0xE25098"],["Raspberry rose","0xB3446C"], _
    ["Raw umber","0x826644"],["Razzle dazzle rose","0xFF33CC"],["Razzmatazz","0xE3256B"],["Red","0xFF0000"], _
    ["Red (Munsell)","0xF2003C"],["Red (NCS)","0xC40233"],["Red (pigment)","0xED1C24"],["Red (RYB)","0xFE2712"], _
    ["Red-brown","0xA52A2A"],["Red-violet","0xC71585"],["Redwood","0xAB4E52"],["Regalia","0x522D80"],["Rich black","0x004040"], _
    ["Rich brilliant lavender","0xF1A7FE"],["Rich carmine","0xD70040"],["Rich electric blue","0x0892D0"], _
    ["Rich lavender","0xA76BCF"],["Rich lilac","0xB666D2"],["Rich maroon","0xB03060"],["Rifle green","0x414833"], _
    ["Robin egg blue","0x00CCCC"],["Rose","0xFF007F"],["Rose bonbon","0xF9429E"],["Rose ebony","0x674846"], _
    ["Rose gold","0xB76E79"],["Rose madder","0xE32636"],["Rose pink","0xFF66CC"],["Rose quartz","0xAA98A9"], _
    ["Rose taupe","0x905D5D"],["Rose vale","0xAB4E52"],["Rosewood","0x65000B"],["Rosso corsa","0xD40000"], _
    ["Rosy brown","0xBC8F8F"],["Royal azure","0x0038A8"],["Royal blue (traditional)","0x002366"],["Royal blue (web)","0x4169E1"], _
    ["Royal fuchsia","0xCA2C92"],["Royal purple","0x7851A9"],["Ruby","0xE0115F"],["Ruddy","0xFF0028"],["Ruddy brown","0xBB6528"], _
    ["Ruddy pink","0xE18E96"],["Rufous","0xA81C07"],["Russet","0x80461B"],["Rust","0xB7410E"],["Sacramento State green","0x00563F"], _
    ["Saddle brown","0x8B4513"],["Safety orange (blaze orange)","0xFF6700"],["Saffron","0xF4C430"],["St. Patrick's blue","0x23297A"], _
    ["Salmon","0xFF8C69"],["Salmon pink","0xFF91A4"],["Sand","0xC2B280"],["Sand dune","0x967117"],["Sandstorm","0xECD540"], _
    ["Sandy brown","0xF4A460"],["Sandy taupe","0x967117"],["Sangria","0x92000A"],["Sap green","0x507D2A"],["Sapphire","0x082567"], _
    ["Satin sheen gold","0xCBA135"],["Scarlet","0xFF2400"],["School bus yellow","0xFFD800"],["Screamin' Green","0x76FF7A"], _
    ["Sea green","0x2E8B57"],["Seal brown","0x321414"],["Seashell","0xFFF5EE"],["Selective yellow","0xFFBA00"],["Sepia","0x704214"], _
    ["Shadow","0x8A795D"],["Shamrock green","0x009E60"],["Shocking pink","0xFC0FC0"],["Sienna","0x882D17"],["Silver","0xC0C0C0"], _
    ["Sinopia","0xCB410B"],["Skobeloff","0x007474"],["Sky blue","0x87CEEB"],["Sky magenta","0xCF71AF"],["Slate blue","0x6A5ACD"], _
    ["Slate gray","0x708090"],["Smalt (Dark powder blue)","0x003399"],["Smokey topaz","0x933D41"],["Smoky black","0x100C08"], _
    ["Snow","0xFFFAFA"],["Spiro Disco Ball","0x0FC0FC"],["Splashed white","0xFEFDFF"],["Spring bud","0xA7FC00"], _
    ["Spring green","0x00FF7F"],["Steel blue","0x4682B4"],["Stil de grain yellow","0xFADA5E"],["Stizza","0x990000"], _
    ["Straw","0xE4D96F"],["Sunglow","0xFFCC33"],["Sunset","0xFAD6A5"],["Tan","0xD2B48C"],["Tangelo","0xF94D00"],["Tangerine","0xF28500"], _
    ["Tangerine yellow","0xFFCC00"],["Taupe","0x483C32"],["Taupe gray","0x8B8589"],["Tea green","0xD0F0C0"], _
    ["Tea rose (orange)","0xF88379"],["Tea rose (rose)","0xF4C2C2"],["Teal","0x008080"],["Teal blue","0x367588"], _
    ["Teal green","0x006D5B"],["Tenné (Tawny)","0xCD5700"],["Terra cotta","0xE2725B"],["Thistle","0xD8BFD8"], _
    ["Thulian pink","0xDE6FA1"],["Tickle Me Pink","0xFC89AC"],["Tiffany Blue","0x0ABAB5"],["Tiger's eye","0xE08D3C"], _
    ["Timberwolf","0xDBD7D2"],["Titanium yellow","0xEEE600"],["Tomato","0xFF6347"],["Toolbox","0x746CC0"], _
    ["Tractor red","0xFD0E35"],["Trolley Grey","0x808080"],["Tropical rain forest","0x00755E"],["True Blue","0x0073CF"], _
    ["Tufts Blue","0x417DC1"],["Tumbleweed","0xDEAA88"],["Turkish rose","0xB57281"],["Turquoise","0x30D5C8"], _
    ["Turquoise blue","0x00FFEF"],["Turquoise green","0xA0D6B4"],["Tuscan red","0x823535"],["Twilight lavender","0x8A496B"], _
    ["Tyrian purple","0x66023C"],["UA blue","0x0033AA"],["UA red","0xD9004C"],["Ube","0x8878C3"],["UCLA Blue","0x536895"], _
    ["UCLA Gold","0xFFB300"],["UFO Green","0x3CD070"],["Ultramarine","0x120A8F"],["Ultramarine blue","0x4166F5"], _
    ["Ultra pink","0xFF6FFF"],["Umber","0x635147"],["United Nations blue","0x5B92E5"],["University of California Gold","0xB78727"], _
    ["Unmellow Yellow","0xFFFF66"],["UP Forest green","0x014421"],["UP Maroon","0x7B1113"],["Upsdell red","0xAE2029"], _
    ["Urobilin","0xE1AD21"],["USC Cardinal","0x990000"],["USC Gold","0xFFCC00"],["Utah Crimson","0xD3003F"],["Vanilla","0xF3E5AB"], _
    ["Vegas gold","0xC5B358"],["Venetian red","0xC80815"],["Verdigris","0x43B3AE"],["Vermilion","0xE34234"],["Veronica","0xA020F0"], _
    ["Violet","0x8F00FF"],["Violet (color wheel)","0x7F00FF"],["Violet (RYB)","0x8601AF"],["Violet (web)","0xEE82EE"], _
    ["Viridian","0x40826D"],["Vivid auburn","0x922724"],["Vivid burgundy","0x9F1D35"],["Vivid cerise","0xDA1D81"], _
    ["Vivid tangerine","0xFFA089"],["Vivid violet","0x9F00FF"],["Warm black","0x004242"],["Wenge","0x645452"],["Wheat","0xF5DEB3"], _
    ["White","0xFFFFFF"],["White smoke","0xF5F5F5"],["Wild blue yonder","0xA2ADD0"],["Wild Strawberry","0xFF43A4"], _
    ["Wild Watermelon","0xFC6C85"],["Wine","0x722F37"],["Wisteria","0xC9A0DC"],["Xanadu","0x738678"],["Yale Blue","0x0F4D92"], _
    ["Yellow","0xFFFF00"],["Yellow (Munsell)","0xEFCC00"],["Yellow (NCS)","0xFFD300"],["Yellow (process)","0xFFEF00"], _
    ["Yellow (RYB)","0xFEFE33"],["Yellow-green","0x9ACD32"],["Zaffre","0x0014A8"],["Zinnwaldite brown","0x2C1608"]]
    Return $asColors
EndFunc

Func _CreateCombo()
    $hInputControl = GUICtrlCreateCombo("", 10, 10, 260, 22, BitOR($CBS_DROPDOWN, $CBS_DISABLENOSCROLL, $WS_VSCROLL))
    GUICtrlSetFont(-1, 11, 500, -1, "Arial")
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    _GUICtrlComboBox_SetMinVisible(-1, 10)
    $aArray = _GetColors()
    For $i = 0 To UBound($aArray) -1
        _GUICtrlComboBox_AddString($hInputControl, $aArray[$i][0])
    Next
    _GUICtrlComboBox_SetEditText($hInputControl, $aArray[0][0])
    Return $hInputControl
EndFunc

Func _UpdateEdit($hControl, $hEdit, $sValidated)
    Local $iIndex = _GUICtrlComboBox_FindStringExact($hControl, $sValidated)
    If $iIndex = -1 Then Return SetError(1)
    Local $aArray = _GetColors()
    GUICtrlSetData($hEdit, StringReplace($aArray[$iIndex][1], "0x", "#"))
EndFunc

Func _UpdateColorLabel($hControl, $hColorLabel, $sValidated)
    Local $iIndex = _GUICtrlComboBox_FindStringExact($hControl, $sValidated)
    If $iIndex = -1 Then Return SetError(1)
    GUICtrlSetData($hColorLabel, "")
    Local $aArray = _GetColors()
    GUICtrlSetBkColor($hColorLabel, $aArray[$iIndex][1])
EndFunc

Notes

Auto-complete only kicks in when a change occurs to the combo edit text. Auto complete does not occur after a cut opperation, or after pressing backspace or delete. The control's background colour turns red when the edit text is either incomplete or incorrect, otherwise the control's background will be white. Of course, you can change the error colour - $iErrorColor - to any value you like.

Edited by czardas
Link to comment
Share on other sites

I have made one or two small improvements to the code for this function, and fixed an issue with undo (Ctrl+Z). This allows you to undo any changes without activating auto complete. Auto compltion only kicks in when you add something to the text in the control: so cut, backspace and undo will be ignored. I'm not saying this behaviour is better than default behaviour. I think it's a matter of personal preference to some degree. As long as the person using it feels comfortable with it, that's what matters at the end of the day IMO.

The colours in the example were taken from wikipedia. There are some funny names in there, many of which I never heard of before: Fuzzy Wuzzy, Wild blue yonder, Hooker's green, Cosmic latte, Tickle Me Pink :huh2:

Oops I introduced a new bug. It crashes when you hold down Ctrl+Z Sorry (I need to think about this) RESOLVED.

Edited by czardas
Link to comment
Share on other sites

  • 2 weeks later...

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