VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Listbox Select Color

by Charles R. Chobot (1 Submission)
Category: Custom Controls/Forms/Menus
Compatability: Visual Basic 5.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (11 Votes)

What this code does is it subclasses a listbox's parent (in order to trap the listbox's messages), then the listbox (in order to change colors). I have commented the area's that you will need to change in order to change the colors.

Assumes
I hope this helps you, and don't forget to vote. Thanks ahead of time.
Side Effects
You must end project by click the exit button in the upper right corner of the form or else Visual Basic WILL error.
API Declarations
'\\ This code is for the people that were wondering
'\\ how to get this working with 2 listbox's instead
'\\ of just one. All the code you will see below is
'\\ what you will need to replace in the original
'\\ form.
'\\ I'm letting you know ahead of time that this code
'\\ could be modified to make it shorter by using
'\\ controll arrays, however I just didn't feel like
'\\ writing the code for arrays. This method still
'\\ works though.
'\\ Enjoy!
Option Explicit
Private Sub Form_Activate()
Dim lrtn As Long
lrtn = GetWindowLong(lst_subclass1.hwnd, GWL_STYLE)

If (lrtn And LBS_OWNERDRAWFIXED) = LBS_OWNERDRAWFIXED Then
End If

If (lrtn And LBS_MULTIPLESEL) = LBS_MULTIPLESEL Then
lrtn = lrtn Xor LBS_MULTIPLESEL
End If
lrtn = SetWindowLong(lst_subclass1.hwnd, GWL_STYLE, lrtn)

lrtn = GetWindowLong(lst_subclass2.hwnd, GWL_STYLE)

If (lrtn And LBS_OWNERDRAWFIXED) = LBS_OWNERDRAWFIXED Then
End If

If (lrtn And LBS_MULTIPLESEL) = LBS_MULTIPLESEL Then
lrtn = lrtn Xor LBS_MULTIPLESEL
End If
lrtn = SetWindowLong(lst_subclass2.hwnd, GWL_STYLE, lrtn)

End Sub
Private Sub Form_Load()
Dim i As Integer
If App.PrevInstance = True Then
MsgBox "There is an instance already running. Cant run one more"
Unload Me
Else
lst_subclass1.AddItem ("Hello there!")
lst_subclass2.AddItem ("hello there!")

mod_subclass.List_Set lst_subclass1
mod_subclass.List_Set lst_subclass2
Hook_SetParent Me.hwnd, True
m_hooked = True

End If

End Sub

Rate Listbox Select Color

Download Listbox Select Color

Download Listbox Select Color (5 KB)

Listbox Select Color Comments

No comments have been posted about Listbox Select Color. Why not be the first to post a comment about Listbox Select Color.

Post your comment

Subject:
Message:
0/1000 characters