How to add different Fonts to a Listbox?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi, title is my question.
I would need it to paint warnings or notifications in a different color so the user could immediately see them (Im currently using the listbox for logging).

So for example I am adding constantly black strings/entries to the listbox. Then suddenly a warning appears and I want to add a line that is colored in red. And when a normal message is passed again, it should be again colored in black of course.
<br/>
Im using VS 2010 and I have a Win32 application.
I create the listbox like this:
<br/>

<div style="color:black; background-color:white
<pre>HWND listbx = CreateWindowEx(
WS_EX_CLIENTEDGE,
<span style="color:#a31515 "listbox",
NULL,
WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | ES_LEFT,
0, 335, <span style="color:green //Window Position (in hWnd)
WindowRect.right-WindowRect.left - 7*2, 300, <span style="color:green //Window Size
hWnd, (HMENU)(101),
(HINSTANCE)GetWindowLong (hWnd, GWL_HINSTANCE),
NULL);
[/code]


<br/>
<br/>
and I create the font like this:
<br/>
<div style="color:black; background-color:white
<pre>HFONT hFont = CreateFont (16, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_SWISS, <span style="color:#a31515 "Arial");
[/code]


<br/>

after that I am using the SendMessage method to tell the listbox that it should use my font:
<br/>
<div style="color:black; background-color:white
<pre>SendMessage(listbx, WM_SETFONT, (WPARAM)hFont, 0);
[/code]


<br/>
<br/>

and I am also using it for adding new entries/strings to the listbox:
<br/>
<pre>SendMessage(listbx, LB_ADDSTRING, NULL, (LPARAM)Message);[/code]

<br/>
<br/>
Now if I simply send a message to the listbox that it should use another font like I did above then it apply that font to the complete listbox, not only a single line (of course).
But I didnt found an answer in the internet yet so it would be very nice if you could help me solve this problem or even only say if its possible with a listbox, thx ;)
<br/>
<br/>
<br/>
<br/>

View the full article
 
Back
Top