Subz

Input/ComboBoxEx AutoComplete function

1 post in this topic

#1 ·  Posted (edited)

Wanted to create an AutoComplete function like "Start » Run" functionality for both Urls and Files using SHAutoComplete function,  Unfortunately my knowledge is quite limited and so put the following together based on existing functions and snippets online.  While everything works fine, I'm not sure if I've written the function correctly and was hoping someone with more experience with WinAPI could look it over and let me know if I've missed anything.

Thanks in advance.

#include <GuiComboBoxEx.au3>
#include <GUIConstantsEx.au3>

Global Const $SHACF_AUTOAPPEND_FORCE_OFF = 0x80000000
Global Const $SHACF_AUTOAPPEND_FORCE_ON = 0x40000000
Global Const $SHACF_AUTOSUGGEST_FORCE_OFF = 0x20000000
Global Const $SHACF_AUTOSUGGEST_FORCE_ON = 0x10000000
Global Const $SHACF_DEFAULT = 0x00000000
Global Const $SHACF_FILESYS_ONLY = 0x00000010
Global Const $SHACF_FILESYS_DIRS = 0x00000020
Global Const $SHACF_FILESYSTEM = 0x00000001
Global Const $SHACF_URLHISTORY = 0x00000002
Global Const $SHACF_URLMRU = 0x00000004
Global Const $SHACF_USETAB = 0x00000008
Global Const $SHACF_URLALL = BitOR($SHACF_URLHISTORY, $SHACF_URLMRU)
Global Const $SHACF_VIRTUAL_NAMESPACE = 0x00000040
; #FUNCTION# ===========================================================================================================
; Name...........: __WinAPI_SHAutoComplete
; Description ...: Instructs system edit controls to use AutoComplete to help complete URLs or file system paths in a
;                  Input or ComboBoxEx control.
; Syntax.........: __WinAPI_SHAutoComplete ( $hWnd [, $dwFlag = $SHACF_DEFAULT] )
; Parameters ....: $hWnd        - Handle of parent window
;                  $dwFlags     - The flags to control the operation of SHAutoComplete:
;                  | $SHACF_AUTOAPPEND_FORCE_OFF    - Ignore the registry default and force the AutoAppend feature off.
;                                                     This flag must be used in combination with one or more of the
;                                                     SHACF_FILESYS* or SHACF_URL* flags.
;                  | $SHACF_AUTOAPPEND_FORCE_ON     - Ignore the registry value and force the AutoAppend feature on. The
;                                                     completed string will be displayed in the edit box with the added
;                                                     characters highlighted. This flag must be used in combination with
;                                                     one or more of the SHACF_FILESYS* or SHACF_URL* flags.
;                  |$SHACF_AUTOSUGGEST_FORCE_OFF    - Ignore the registry default and force the AutoSuggest feature off.
;                                                     This flag must be used in combination with one or more of the
;                                                     SHACF_FILESYS* or SHACF_URL* flags.
;                  |$SHACF_AUTOSUGGEST_FORCE_ON     - Ignore the registry value and force the AutoSuggest feature on. A
;                                                     selection of possible completed strings will be displayed as a
;                                                     drop-down list, below the edit box.
;                                                     This flag must be used in combination with one or more of the
;                                                     SHACF_FILESYS* or SHACF_URL* flags.
;                  |$SHACF_DEFAULT                  - The default setting, equivalent to SHACF_FILESYSTEM + SHACF_URLALL.
;                                                     SHACF_DEFAULT cannot be combined with any other flags.
;                  |$SHACF_FILESYS_ONLY             - Include the file system only.
;                  |$SHACF_FILESYS_DIRS             - Include the file system and directories, UNC servers, and UNC server
;                                                     shares.
;                  |$SHACF_FILESYSTEM               - Include the file system and the rest of the Shell (Desktop, Computer,
;                                                     and Control Panel, for example).
;                  |$SHACF_URLHISTORY               - Include the URLs in the user's History list.
;                  |$SHACF_URLMRU                   - Include the URLs in the user's Recently Used list.
;                  |$SHACF_USETAB                   - Allow the user to select from the autosuggest list by pressing the
;                                                     TAB key. If this flag is not set, pressing the TAB key will shift
;                                                     focus to the next control and close the autosuggest list. If
;                                                     SHACF_USETAB is set, pressing the TAB key will select the first item
;                                                     in the list. Pressing TAB again will select the next item in the list,
;                                                     and so on. When the user reaches the end of the list, the next TAB key
;                                                     press will cycle the focus back to the edit control. This flag must be
;                                                     used in combination with one or more of the SHACF_FILESYS* or
;                                                     SHACF_URL* flags listed on this page.
;                  |$SHACF_URLALL                   - Include the URLs in the users History and Recently Used lists.
;                                                     Equivalent to SHACF_URLHISTORY + SHACF_URLMRU.
;                  |$SHACF_VIRTUAL_NAMESPACE
; Author ........: Subz
; Remarks .......: The first four flags are used to override the Internet Explorer registry settings. The user can change these 
;                  settings manually by launching the Internet Options property sheet from the Tools menu and clicking the 
;                  Advanced tab.
;                  https://msdn.microsoft.com/en-us/library/windows/desktop/bb759862(v=vs.85).aspx
; ===============================================================================================================================
Func __WinAPI_SHAutoComplete($hWnd, $dwFlags = $SHACF_DEFAULT)
    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
    Local $hWndEdit, $aResult
    Switch _WinAPI_GetClassName($hWnd)
        Case 'ComboBoxEx32'
            $hWndEdit = _GUICtrlComboBoxEx_GetEditControl($hWnd)
        Case 'Edit'
            $hWndEdit = $hWnd
        Case Else
            Return
    EndSwitch
    $aResult = DllCall('shlwapi.dll', 'long', 'SHAutoComplete', 'hwnd', $hWndEdit, 'int', $dwFlags)
    If @error Or Not $aResult[0] Then Return SetError(@error, @extended, '')
    Return SetExtended($aResult[0], $aResult[2])
EndFunc ;==>__WinAPI_SHAutoComplete

Global $hGui_FileSystem
Global $hGui_WebHistory
Example()

Func Example()
    ; Create GUI
    $hGui = GUICreate('Example', 600, 100)

    GUICtrlCreateLabel('Website History:', 5, 5, 150, 21)
    $hGui_WebHistory = GUICtrlCreateInput('http://', 2, 2, 380, 21)
        __WinAPI_SHAutoComplete($hGui_WebHistory, BitOR($SHACF_AUTOAPPEND_FORCE_ON, $SHACF_URLHISTORY, $SHACF_USETAB))

    $hGui_FileSystem = _GUICtrlComboBoxEx_Create($hGui, "", 2, 42, 396, 120)


    GUISetState(@SW_SHOW)

    _GUICtrlComboBoxEx_BeginUpdate($hGui_FileSystem)
    _GUICtrlComboBoxEx_AddDir($hGui_FileSystem, @WindowsDir & "\*.exe")
    _GUICtrlComboBoxEx_EndUpdate($hGui_FileSystem)
        __WinAPI_SHAutoComplete($hGui_FileSystem, BitOR($SHACF_AUTOAPPEND_FORCE_ON, $SHACF_FILESYSTEM, $SHACF_USETAB))

    Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>Example

 

Edited by Subz
Added function syntax and updated description.

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

    • Jfish
      By Jfish
      This may be a question for @Jos ... I added some user functions to Scite with the User CallTip Manager (very awesome by the way).  Everything works great.   However, I have a regrettably large list of parameters for some functions (unavoidable because it is an integration to another tech).  Because the list is so long I can't see it all in the auto-complete tooltip,  Is there a way to wrap that tooltip text?
    • RichardL
      By RichardL
      As I'm typing in comment blocks #cs #ce then autocomplete is operating.  Same on line comments.  think it didn't used to do this, i.e. only autocomplete in code, and that would be much better for me.  I've just updated to SciTE 3.6.0.
    • corgano
      By corgano
      Is it possible to have more than one combobox using _GUICtrlComboBox_AutoComplete with separate item lists? Say I wanted a GUI with two combo's, one with fruit (apple|orange|tomato) and one with vegetables (celery|Turnip|carrot) and wanted both of them to autocomplete. Is this possible? I like the way the _GUICtrlComboBox_AutoComplete example works, but I am having difficulties understanding the code :/
      http://www.autoitscript.com/autoit3/docs/libfunctions/_GUICtrlComboBox_AutoComplete.htm
      my first attempt:
      #include <GuiComboBox.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $Debug_CB = False ; Check ClassName being passed to ComboBox/ComboBoxEx functions, set to True and use a handle to another control to see it work Global $hCombo, $hCombo2 _Main() Func _Main() ; Create GUI GUICreate("ComboBox Auto Complete", 400, 296) $hCombo = GUICtrlCreateCombo("", 2, 2, 396, 296) GUICtrlSetData(-1, "Apple|Orange|Tomatoe") $hCombo2 = GUICtrlCreateCombo("", 2, 42, 396, 296) GUICtrlSetData(-1, "One|Two|Three") GUISetState() ; Add files ;~ _GUICtrlComboBox_BeginUpdate($hCombo) ;~ _GUICtrlComboBox_AddDir($hCombo, @WindowsDir & "\*.exe") ;~ _GUICtrlComboBox_EndUpdate($hCombo) GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>_Main Func _Edit_Changed($hCombo) _GUICtrlComboBox_AutoComplete($hCombo) EndFunc ;==>_Edit_Changed Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg Local $hWndFrom, $iIDFrom, $iCode, $hWndCombo, $hWndCombo2 If Not IsHWnd($hCombo) Then $hWndCombo = GUICtrlGetHandle($hCombo) If Not IsHWnd($hCombo2) Then $hWndCombo2 = GUICtrlGetHandle($hCombo2) $hWndFrom = $ilParam $iIDFrom = BitAND($iwParam, 0xFFFF) ; Low Word $iCode = BitShift($iwParam, 16) ; Hi Word Switch $hWndFrom Case $hCombo, $hWndCombo Switch $iCode Case $CBN_EDITCHANGE ; Sent after the user has taken an action that may have altered the text in the edit control portion of a combo box _Edit_Changed($hCombo) ; no return value EndSwitch Case $hCombo2, $hWndCombo Switch $iCode Case $CBN_EDITCHANGE ; Sent after the user has taken an action that may have altered the text in the edit control portion of a combo box _Edit_Changed($hCombo) ; no return value EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Func _DebugPrint($s_text, $line = @ScriptLineNumber) ConsoleWrite( _ "!===========================================================" & @LF & _ "+======================================================" & @LF & _ "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _ "+======================================================" & @LF) EndFunc ;==>_DebugPrint there must be an easier way..
    • Kinhow
      By Kinhow
      Hi guys, I reinstalled my autoit after my ssd crashed.

      But the thing is that its not autocompleting the IE.au3 functions anymore...

      how can I make it show the function as soon as I start typing "_IE" ?