求用SHAutoComplete实现自动匹配的实例
我的程序有个combobox是用来输网址的,我想让它有像IE一样当输入网址时弹出下拉列表自动匹配输入的内容.
在网上看了可以用SHAutoComplete来实现,可是都没有实例,我是菜鸟,一点也不懂,请高手不吝惜给个实例.
请高手指教!
谢谢了!
[解决办法]
'Code by Lúcio Chaves (luciochaves@bol.com.br)'This program needs a textbox ('Text1') on a formPrivate Const SHACF_AUTOAPPEND_FORCE_OFF = &H80000000Private Const SHACF_AUTOAPPEND_FORCE_ON = &H40000000Private Const SHACF_AUTOSUGGEST_FORCE_OFF = &H20000000Private Const SHACF_AUTOSUGGEST_FORCE_ON = &H10000000Private Const SHACF_DEFAULT = &H0Private Const SHACF_FILESYSTEM = &H1Private Const SHACF_URLHISTORY = &H2Private Const SHACF_URLMRU = &H4Private Const SHACF_USETAB = &H8Private Const SHACF_URLALL = (SHACF_URLHISTORY Or SHACF_URLMRU)Private Declare Sub SHAutoComplete Lib "shlwapi.dll" (ByVal hwndEdit As Long, ByVal dwFlags As Long)Private Sub Form_Load() SHAutoComplete Text1.hWnd, SHACF_DEFAULTEnd Sub
[解决办法]
ComboBox 也可以的,不过编辑框是子窗口。
SHAutoComplete GetWindow(Combo1.hWnd, GW_CHILD), SHACF_DEFAULT
[解决办法]
建一class
'---------------------------------------------------' Module : cAutoComplete' DateTime : 2004-3-5 1:14' Author : Lingll' Email : lingll_xl@163.com' Purpose :'---------------------------------------------------Option ExplicitPrivate Declare Function SHAutoComplete Lib "Shlwapi.dll" (ByVal hwndEdit As Long, ByVal dwFlags As Long) As LongPrivate Declare Function DllGetVersion Lib "Shlwapi.dll" (ByRef dvi As DLLVERSIONINFO) As LongPrivate Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _ ByVal hWnd1 As Long, _ ByVal hWnd2 As Long, _ ByVal lpsz1 As String, _ ByVal lpsz2 As String) As LongPrivate Type DLLVERSIONINFO cbSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildVersion As Long dwPlatformID As LongEnd TypePrivate Const SHACF_AUTOSUGGEST_FORCE_ON = &H10000000Private Const SHACF_AUTOSUGGEST_FORCE_OFF = &H20000000Private Const SHACF_AUTOAPPEND_FORCE_ON = &H40000000Private Const SHACF_AUTOAPPEND_FORCE_OFF = &H80000000Private Const SHACF_DEFAULT = &H0Private Const SHACF_FILESYSTEM = &H1Private Const SHACF_URLHISTORY = &H2Private Const SHACF_URLMRU = &H4Private Const SHACF_URLALL = (SHACF_URLHISTORY Or SHACF_URLMRU)Private Const SHACF_USETAB As Long = &H8Private Const DLLVER_PLATFORM_WINDOWS = &H1Private Const DLLVER_PLATFORM_NT = &H2Private Const S_OK = &H0Private Const NOERROR = 0Public Enum SHACF_FLAGS eSHACF_AUTOSUGGEST_FORCE_ON = SHACF_AUTOSUGGEST_FORCE_ON eSHACF_AUTOSUGGEST_FORCE_OFF = SHACF_AUTOSUGGEST_FORCE_OFF eSHACF_AUTOAPPEND_FORCE_ON = SHACF_AUTOAPPEND_FORCE_ON eSHACF_AUTOAPPEND_FORCE_OFF = SHACF_AUTOAPPEND_FORCE_OFF eSHACF_DEFAULT = SHACF_DEFAULT eSHACF_FILESYSTE = SHACF_FILESYSTEM eSHACF_URLHISTORY = SHACF_URLHISTORY eSHACF_URLMRU = SHACF_URLMRU eSHACF_URLALL = SHACF_URLALL eSHACF_USETAB = SHACF_USETABEnd Enum'local variable(s) to hold property value(s)Private mvarErrDescription As String 'local copyPublic Property Get ErrDescription() As String'used when retrieving value of a property, on the right side of an assignment.'Syntax: Debug.Print X.ErrDescription ErrDescription = mvarErrDescriptionEnd PropertyPublic Function Assign(hwndEdit As Long, Optional nFlags As SHACF_FLAGS = eSHACF_DEFAULT) As BooleanDim dvi As DLLVERSIONINFOdvi.cbSize = Len(dvi)If DllGetVersion(dvi) <> NOERROR Then mvarErrDescription = "无法检测Shlwapi.dll的版本号" Assign = False Exit FunctionEnd If'Debug.Print "dll version:", dvi.dwMajorVersionIf dvi.dwMajorVersion >= 5 Then If SHAutoComplete(hEdit(hwndEdit), nFlags) <> S_OK Then mvarErrDescription = "无法开启自动完成功能" Assign = False Exit Function End IfElse mvarErrDescription = "IE版本低于5" Assign = False Exit FunctionEnd IfAssign = TrueEnd FunctionPrivate Function hEdit(nHwnd)hEdit = FindWindowEx(nHwnd, 0, "EDIT", vbNullString)End Function