I have a problem, it's simply to change the colors (background, text) of a Listbox-control.
I think it can be done using the LBS_OWNERDRAW style, the problem is I don't know how to do it. I have tried but failed. :(

The listbox's purpose is to be filled with data and always show the last added line, should I realy use a listbox for this task or should I use another control?

Any tips, help, thoughts regarding this would be appreciated.
Posted on 2002-06-21 11:43:01 by scientica
Ok, I might be able to help here, but I will need just a little more information. My answer depends on yours :grin:

Are you simply changing the background and text color to something new? Or are you trying to code each line with a different c o l o r ?

The first is quite easy, the second requires the LBS_OWNERDRAW style and drawing it all yourself which is a pain.
Posted on 2002-06-21 12:52:04 by Graebel
Simply changing the background and text color to something new is what I would like to start with, it would be enougth to resume the project.
Coloring each line different could be usefull for instance, red text color when reporting an error or such, but that is not urgent.

So for now I'll be satisfied with only changing bg and text color, but you could if you don't think it's to much work you can include the other one too.

Thanks for takeing time to help me! :)
Posted on 2002-06-21 13:08:12 by scientica
Bah, its no trouble at all. Im usually quite good at the API but I suck at assembly so I hang around the board alot to learn.

Let me see. The easiest way to make changes to the colors (IMHO) is to capture the WM_CTLCOLORLISTBOX message sent to the parent WndProc.

wParam ; handle of list box display context
lParam ; handle of list box

something like this should work:

WndProc proc hWin :DWORD, uMsg :DWORD, wParam :DWORD, lParam :DWORD
; set the text color for an item
invoke SetTextColor, wParam, 0FF0000h

; set the text back color for an item
invoke SetBkColor, wParam, 000FF00h

; set the background of the listbox
mov eax, hBrush
cmp eax, 0
jne BrushAlreadyCreated
invoke CreateSolidBrush, 00000FFh
mov hBrush, eax

mov eax, hBrush
WndProc endp

Make hBrush a global and on application exit call DeleteObject on it. Note: This proc (as is) will color *all* the listboxes on this parent. If you only want a particular one, compare the lParam to the listbox's hWnd.

Posted on 2002-06-21 13:26:20 by Graebel
Thanks again!

It works, WM_CTLCOLORLISTBOX, I never would have thought of that (didn't even know it existed).

Thanks again, what else is there to say but thanks.
:) :) :)

Btw, I'm quite a newbie too.
Posted on 2002-06-21 13:37:39 by scientica
Afternoon, scientica.

It's always good to see newbies here:).

Don't be worried about asking any questions you may have.

To help you along in finding more information regarding listboxes, I'll remind you that our search feature, at the top-right of this messageboard, has a wealth of hidden talent in supplying you with "heaps of tasty tid-bits" (<- I couldn't think of something fancy or profound to say ;) ).

Click (HERE ) for an example of a coloured listbox.

Posted on 2002-06-22 02:15:38 by Scronty
Here are other two threads. My examples are always in C ( :rolleyes: ) , so less interesting in an assembly board, but maybe you will find anyway some useful tips.

Posted on 2002-06-22 02:51:53 by LuHa