自动完成的TextBox,类似Windows的运行框

来源:互联网 发布:免费交友软件 编辑:程序博客网 时间:2024/05/17 06:11

Option Explicit On

Public Enum SHAutoCompleteFlags
    SHACF_DEFAULT = &H0
    SHACF_FILESYSTEM = &H1
    SHACF_URLHISTORY = &H2
    SHACF_URLMRU = &H4
    SHACF_USETAB = &H8
    SHACF_URLALL = (SHACF_URLHISTORY Or SHACF_URLMRU)
    SHACF_FILESYS_ONLY = &H10
    SHACF_FILESYS_DIRS = &H20
    SHACF_AUTOSUGGEST_FORCE_ON = &H10000000
    SHACF_AUTOSUGGEST_FORCE_OFF = &H20000000
    SHACF_AUTOAPPEND_FORCE_ON = &H40000000
    SHACF_AUTOAPPEND_FORCE_OFF = &H80000000
End Enum

Private Declare Function SHAutoComplete Lib "shlwapi.dll" ( _
      ByVal hwndEdit As Long, ByVal dwFlags As Long) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
      (ByVal hwndParent As Long, ByVal hwndChildAfter As Long, ByVal lpszClass As String, _
      ByVal lpszWindow As String) As Long

Private Const S_OK = 0

Public Function AutoComplete( _
            ByVal hWnd As Long, _
            ByVal eFlags As SHAutoCompleteFlags _
      )
    Dim lR As Long
    lR = SHAutoComplete(hWnd, eFlags)
    AutoComplete = (lR <> S_OK)
End Function

'Get Edit Control from ComboBox
Public Function GetComboBoxEdithWnd(ByVal hWnd As Long) As Long
    GetComboBoxEdithWnd = FindWindowEx(hWnd, 0, "EDIT", vbNullString)
End Function

'To Completed Test,you can add one TextBox Control and add ComboBox Control from toolbox

'and then test input "c:/" in textbox ,you can see it :)

Private Sub Form_Load()
    AutoComplete(Text1.hWnd, SHACF_FILESYS_ONLY)
    AutoComplete(GetComboBoxEdithWnd(Combo1.hWnd), SHACF_FILESYS_ONLY)
End Sub