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.
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.