Private Sub Cmb_sp_Change()
Dim i As Integer
Dim strTemp As String
SendMessage Cmb_sp.hwnd, CB_SHOWDROPDOWN, 1, CLng(0)
Me.MousePointer = 0
For i = 0 To Cmb_sp.ListCount - 1
If InStr(Cmb_sp.List(i), Cmb_sp.Text) > 0 Then
'''''Cmb_sp.TopIndex = i
Exit Sub
End If
Next
end sub1.希望能像IE地址栏一样,输入字母后,能让光标停在相应的项上,我不知道该怎么做?用TOPINDEX属性不行,没用。LISTINDEX属性会直接把相应的项填到输入框中。
2.如何显示两个字段的值,我会的只有用字符连接的方法,有没有其他很好的方法呢?
3.我用FLEXGRID,单击显示COMBO,显示后为什么COMBO的DBLCLICK事件不起作用?
100分求答案,谢谢
Dim i As Integer
Dim strTemp As String
SendMessage Cmb_sp.hwnd, CB_SHOWDROPDOWN, 1, CLng(0)
Me.MousePointer = 0
For i = 0 To Cmb_sp.ListCount - 1
If InStr(Cmb_sp.List(i), Cmb_sp.Text) > 0 Then
'''''Cmb_sp.TopIndex = i
Exit Sub
End If
Next
end sub1.希望能像IE地址栏一样,输入字母后,能让光标停在相应的项上,我不知道该怎么做?用TOPINDEX属性不行,没用。LISTINDEX属性会直接把相应的项填到输入框中。
2.如何显示两个字段的值,我会的只有用字符连接的方法,有没有其他很好的方法呢?
3.我用FLEXGRID,单击显示COMBO,显示后为什么COMBO的DBLCLICK事件不起作用?
100分求答案,谢谢
'The first four 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.The last five can be
'used to specify which files or URLs will be
'available for autoappend or autosuggest operations.'Ignore registry default and force feature on
Private Const SHACF_AUTOSUGGEST_FORCE_ON As Long = &H10000000'Ignore registry default and force feature off.
Private Const SHACF_AUTOSUGGEST_FORCE_OFF As Long = &H20000000'Ignore registry default and force feature on. (Also know as AutoComplete)
Private Const SHACF_AUTOAPPEND_FORCE_ON As Long = &H40000000'Ignore registry default and force feature off. (Also know as AutoComplete)
Private Const SHACF_AUTOAPPEND_FORCE_OFF As Long = &H80000000'Currently (SHACF_FILESYSTEM | SHACF_URLALL)
Private Const SHACF_DEFAULT As Long = &H0'Includes the File System as well as the rest
'of the shell (Desktop\My Computer\Control Panel\)
Private Const SHACF_FILESYSTEM As Long = &H1'URLs in the User's History
Private Const SHACF_URLHISTORY As Long = &H2'URLs in the User's Recently Used list
Private Const SHACF_URLMRU As Long = &H4Private Const SHACF_URLALL As Long = (SHACF_URLHISTORY Or SHACF_URLMRU)'Identifies the platform for which the DLL was built.
Private Const DLLVER_PLATFORM_WINDOWS As Long = &H1 'Windows 95
Private Const DLLVER_PLATFORM_NT As Long = &H2 'Windows NTPrivate Type DllVersionInfo
cbSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformID As Long
End TypePrivate Declare Function SHAutoComplete _
Lib "Shlwapi.dll" _
(ByVal hwndEdit As Long, _
ByVal dwFlags As Long) As LongPrivate Declare Function DllGetVersion _
Lib "Shlwapi.dll" _
(dwVersion As DllVersionInfo) As Long
Private Function GetIEVersion(DVI As DllVersionInfo) As Long DVI.cbSize = Len(DVI)
Call DllGetVersion(DVI) GetIEVersion = DVI.dwMajorVersionEnd Function
Private Function GetIEVersionString() As String Dim DVI As DllVersionInfo DVI.cbSize = Len(DVI)
Call DllGetVersion(DVI) GetIEVersionString = "Internet Explorer " & _
DVI.dwMajorVersion & "." & _
DVI.dwMinorVersion & "." & _
DVI.dwBuildNumberEnd Function
Private Sub Command1_Click() Dim DVI As DllVersionInfo If GetIEVersion(DVI) >= 5 Then 'Turn on auto-complete
Call SHAutoComplete(Text1.hWnd, SHACF_DEFAULT) 'update the captions and set focus to the textbox
Command1.Caption = "SHAutoComplete is On"
Command1.Enabled = False
Text1.SetFocus
Text1.SelStart = Len(Text1.Text) Else 'damn!
MsgBox "Sorry ... you need IE5 to use this demo", vbExclamation End IfEnd Sub
Private Sub Form_Load() 'dim a DllVersionInfo type
Dim DVI As DllVersionInfo 'display the version of Shlwapi
Label1 = "Using Shlwapi.dll for " & GetIEVersionString 'if not 5 or greater, can't do it
Command1.Enabled = GetIEVersion(DVI) >= 5
Command1.Caption = "SHAutoComplete is Off"End Sub'--end block--'
我在窗体上放了一个WebBrowser控件,就可以浏览网站了,但是网站有一些弹出的窗体,却使用了系统默认的浏览器,既使用的IE作为弹出窗体的浏览器了。
上面的代码好多是判断是否 IE >= 5,因为 IE < 5 无法实现这个功能。
最简单的:
Private Declare Function SHAutoComplete _
Lib "Shlwapi.dll" _
(ByVal hwndEdit As Long, _
ByVal dwFlags As Long) As Long调用:
Private Sub Form_Load()
SHAutoComplete Text1.hWnd, 0
End Sub
SHAutoComplete Text1.hWnd, 0
End Sub为什么在FORM_LOAD事件中
'Windows declarations
Private Declare Function GetSystemDirectory Lib "kernel32" Alias "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const CB_FINDSTRING = &H14C
Private Const CB_ERR = (-1)'Declarations for alternate code (see comments below)
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const CB_SETCURSEL = &H14E'Private flag
Private m_bEditFromCode As Boolean
Private Sub Form_Load()
Dim sSysDir As String, sFile As String 'Get files from system directory for test list
Screen.MousePointer = vbHourglass
sSysDir = Space$(256)
GetSystemDirectory sSysDir, Len(sSysDir)
sSysDir = Left$(sSysDir, InStr(sSysDir, Chr$(0)) - 1)
If Right$(sSysDir, 1) <> "\" Then
sSysDir = sSysDir & "\"
End If
sFile = Dir$(sSysDir & "*.*")
Do While Len(sFile)
Combo1.AddItem sFile
sFile = Dir$
Loop
Screen.MousePointer = vbDefault
End Sub'Certain keystrokes must be handled differently by the Change
'event, so set m_bEditFromCode flag if such a key is detected
Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyDelete
m_bEditFromCode = True
Case vbKeyBack
m_bEditFromCode = True
End Select
End SubPrivate Sub Combo1_Change()
Dim i As Long, J As Long
Dim strPartial As String, strTotal As String 'Prevent processing as a result of changes from code
If m_bEditFromCode Then
m_bEditFromCode = False
Exit Sub
End If
With Combo1
'Lookup list item matching text so far
strPartial = .Text
i = SendMessage(.hwnd, CB_FINDSTRING, -1, ByVal strPartial)
'If match found, append unmatched characters
If i <> CB_ERR Then
'Get full text of matching list item
strTotal = .List(i)
'Compute number of unmatched characters
J = Len(strTotal) - Len(strPartial)
'
If J <> 0 Then
'Append unmatched characters to string
m_bEditFromCode = True
.SelText = Right$(strTotal, J)
'Select unmatched characters
.SelStart = Len(strPartial)
.SelLength = J
Else '*** Text box string exactly matches list item *** 'Note: The ListIndex is still -1. If you want to
'force the ListIndex to the matching item in the
'list, uncomment the following line. Note that
'PostMessage is required because Windows sets the
'ListIndex back to -1 once the Change event returns.
'Also note that the following line causes Windows to
'select the entire text, which interferes if the
'user wants to type additional characters.
' PostMessage Combo1.hwnd, CB_SETCURSEL, i, 0
End If
End If
End With
End SubPrivate Sub cmdClose_Click()
Unload Me
End Sub
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long Public Const CB_FINDSTRING = &H14C Private Sub Combo1_Change() Dim iStart As Integer Dim sString As String Static iLeftOff As Integer
iStart = 1 iStart = Combo1.SelStart
If iLeftOff <> 0 Then Combo1.SelStart = iLeftOff iStart = iLeftOff End If
sString = CStr(Left(Combo1.Text, iStart)) Combo1.ListIndex = SendMessage(Combo1.hwnd, _ B_FINDSTRING, -1, ByVal CStr(Left( _ ombo1.Text, iStart)))
If Combo1.ListIndex = -1 Then iLeftOff = Len(sString) combo1.Text = sString End If
Combo1.SelStart = iStart iLeftOff = 0 End Sub 静态变量 iLeftOff 指定了字符长度。
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Sub Combo1_Change()
Dim iStart As Integer
Dim sString As String
Static iLeftOff As Integer
iStart = 1
iStart = Combo1.SelStart
If iLeftOff <> 0 Then Combo1.SelStart = iLeftOff: iStart = iLeftOffsString = CStr(Left(Combo1.Text, iStart))
Combo1.ListIndex = SendMessage(Combo1.hwnd, &H14C, -1, ByVal CStr(Left(Combo1.Text, iStart)))
If Combo1.ListIndex = -1 Then iLeftOff = Len(sString): Combo1.Text = sString
If Combo1.Text <> "" Then SendMessage Combo1.hwnd, &H14F, True, 0Combo1.SelStart = iStart
Combo1.SelLength = 0
iLeftOff = 0End Sub
Private Sub Form_Load()
Dim i As Long
For i = 1 To 500
Randomize
Combo1.AddItem Chr(Int(Rnd * 26) + 97) & Chr(Int(Rnd * 26) + 97) & Chr(Int(Rnd * 26) + 97) & Chr(Int(Rnd * 26) + 97) & Chr(Int(Rnd * 26) + 97)
Next
Combo1.Text = ""
End Sub
方式二:Dim strCombo As String
Const WM_SETREDRAW = &HB
Const KEY_A = 65
Const KEY_Z = 90Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPrivate Sub combo1_KeyUp(KeyCode As Integer, Shift As Integer)
Dim x%
Dim strTemp$
Dim nRet&If KeyCode >= KEY_A And KeyCode <= KEY_Z Then
'only look at letters A-Z
strTemp = Combo1.Text
If Len(strTemp) = 1 Then strCombo = strTemp
nRet& = SendMessage(Combo1.hwnd, WM_SETREDRAW, False, 0&)
For x = 0 To (Combo1.ListCount - 1)
If UCase((strTemp & Mid$(Combo1.List(x), Len(strTemp) + 1))) = UCase(Combo1.List(x)) Then
Combo1.ListIndex = x
Combo1.Text = Combo1.List(x)
Combo1.SelStart = Len(strTemp)
Combo1.SelLength = Len(Combo1.Text) - (Len(strTemp))
strCombo = strCombo & Mid$(strTemp, Len(strCombo) + 1)
Exit For
Else
If InStr(UCase(strTemp), UCase(strCombo)) Then
strCombo = strCombo & Mid$(strTemp, Len(strCombo) + 1)
Combo1.Text = strCombo
Combo1.SelStart = Len(Combo1.Text)
Else
strCombo = strTemp
End If
End If
Next
nRet& = SendMessage(Combo1.hwnd, WM_SETREDRAW, True, 0&)
End If
End SubPrivate Sub Form_Load()
Combo1.AddItem "AAAAAAAA"
Combo1.AddItem "ABBBBBBB"
Combo1.AddItem "ABCCCCCC"
Combo1.AddItem "ABCDDDDD"
Combo1.AddItem "ABCDEEEE"
Combo1.AddItem "ABCDEFFF"
Combo1.AddItem "ABCDEFGG"
Combo1.AddItem "ABCDEFGH"
End Sub