Advanced: Color Listbox

Volte
04-09-2002, 09:48 AM
Color Listbox: Subclassing

This project is an example of subclassing and hooking to apply
and ownerdrawn style to a listbox. I based the hooking on an
example from TheScarms, however since it has a big memory
leak, I didn't just copy and paste.

I am fairly sure there is no memory leak in my program, but you
never know. Report to me if you find anything.

Basically, you use this listbox exactly like you normally would (it
is an actual listbox, not just a simulation). When you want to
add an item in color, you put a specially formatted identifier on
the beginning of it. Be careful though, it's easy to kill the IDE
if you mess it up. Error handling is non existant in subclassing:
you gotta get it right the first time.

The format is:List1.AddItem "FC[red,green,blue]This is a colored item!"Where red, green and blue are the numbers.
Don't put spaces! It will mess it up, possible causing an IDE crash.

The downside to using this style of hooking is that it will add
the color functionality to all the listboxes on your form,
whether you want it or not. It's not that bad though, since if you
simply ignore the color formatting, it will function just like it
normally would.

Volte
04-09-2002, 09:52 AM
Source. Use at your own risk. If this takes down your IDE, it's
probably because of something you did. :p

Volte
06-01-2005, 02:28 PM
Over three years after this was posted I was notified of a slight error which prevented a compiled application using this code from actually subclassing anything, so the fixed code is attached.

The problem was with the class-name of the listbox which is used in the subclassing code being different between the IDE and compiled EXE.

To fix this manually, change the lineIf sClass = "ThunderListBox" Thenin ListHook() to If sClass = "ThunderListBox" Or sClass = "ThunderRT6ListBox" Then

Mathimagics
06-10-2005, 10:30 AM
Perhaps you could include the DbgWproc.dll to make it IDE friendly ... :cool:


PS - like the avatar, one of my favourite albums ;)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum