Not a Member Yet,
Click here to Register
How do you like the new design?
It's cool, great job
[tally: 70%] 70%
It's okay
[tally: 20%] 20%
Its OK but I liked the old layout better
[tally: 0%] 0%
Please bring the old one back
[tally: 10%] 10%

votes: 10

ID: 263
Viewed: 2079
Added: Jul 26, 2002
Snippet uploaded by: snippet
Written By: unknown
Demo: Sorry, no demo

User Rated at: 0 Stars
Rate This:

Thank you for your vote. Please wait...

It appears you already voted for this snippet

It appears your vote value was empty

Get Highlighted ComboBox Item

Highlight all by clicking in box
'In a Module..
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam 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 GWL_WNDPROC = (-4)
Private Const WM_CTLCOLORLISTBOX = &H134
Private Const LB_GETCURSEL = &H188

Private lPrevWndFunc As Long
Public oLabel As Label

Private Function WindowProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim iIndex As Long

iIndex = SendMessage(lParam, LB_GETCURSEL, 0&, ByVal 0&)
If iIndex >= 0 Then oLabel = "Item Index: " & iIndex
End If
WindowProc = CallWindowProc(lPrevWndFunc, hwnd, Msg, wParam, lParam)
End Function

Public Sub SubClassIt(ByVal hwnd As Long, ByVal Add As Boolean)
If Add Then
lPrevWndFunc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindowProc)
Call SetWindowLong(hwnd, GWL_WNDPROC, lPrevWndFunc)
End If
End Sub

Highlight All
'In a Form, with a Label and a ComboBox..
Private Sub Form_Load()
Dim iIndex As Long
Set oLabel = Label1
SubClassIt Combo1.hwnd, True
For iIndex = 1 To 10
Combo1.AddItem "Item " & iIndex
End Sub

Private Sub Form_Unload(Cancel As Integer)
SubClassIt Combo1.hwnd, False
End Sub;

No Comments to show

Please completely fill out the form below if you want to review this snippet. All reviews are subject to validation.

Replying to a Comment...

Adding your comment. Please wait...

Thanks for adding your comment!. After further review it will be added.

There was a problem adding your comment. Please try again.

Please complete all the fields in the form before sending.

© 2002 - 2017 All Rights Reserved. Conditions