Click to See Complete Forum and Search --> : How to set certain item in BOLD in a listbox?
Grace
August 10th, 2004, 11:27 PM
Hi all,
How would you change the font or set the item text in bold in a listbox in win32? I've been digging around, and couldn't find anything in win32.
Thanks in advance,
Grace
Bond
August 11th, 2004, 08:23 AM
I think it's an all-or-nothing type of thing. You could send the listbox a WM_SETFONT message, but that would affect all items.
If you want to bold a particular item, you'll probably have to use owner-drawing. Specify LBS_OWNERDRAWFIXED or LBS_OWNERDRAWVARIABLE (if the height of your items is not the same) and draw it anyway you want.
Grace
August 11th, 2004, 01:19 PM
Hi Bond,
Do you have any sample code for Owner-Drawing to accomplish this?
Thanks,
Grace
If you want to bold a particular item, you'll probably have to use owner-drawing. Specify LBS_OWNERDRAWFIXED or LBS_OWNERDRAWVARIABLE (if the height of your items is not the same) and draw it anyway you want.
kirants
August 11th, 2004, 02:03 PM
Probably this article would help.
http://www.codeguru.com/Cpp/controls/listbox/colorlistboxes/article.php/c1611/
Take a look at the CColorListBox::DrawItem method. This will give you an idea.
depending on your condition, you may simply need to maintain 2 fonts. One a non bold font and other a bold font.
In the DrawItem you just need to select the proper font to the DC before you call DrawText .
Grace
August 11th, 2004, 03:51 PM
I am having problems setting and retrieving the text.
From the parent of the listbox, I do
SendMessage(HwndListBox, LB_ADDSTRING, 0, (LPARAM)"someText");
I don't see any text.
In the WM_DRAWITEM of the listbox callback function, I couldn't get text by doing
TCHAR sText[256] = {"\0"};
SendMessage(HwndListBox, LB_GETTEXT, lpDIS->itemID, (LPARAM)sText);
That's from the MFC code.
CString sText;
GetText(lpDIS->itemID, sText);
Any Idea?
Thanks in advance,
Grace
Probably this article would help.
http://www.codeguru.com/Cpp/controls/listbox/colorlistboxes/article.php/c1611/
Take a look at the CColorListBox::DrawItem method. This will give you an idea.
depending on your condition, you may simply need to maintain 2 fonts. One a non bold font and other a bold font.
In the DrawItem you just need to select the proper font to the DC before you call DrawText .
kirants
August 11th, 2004, 04:00 PM
I am having problems setting and retrieving the text.
From the parent of the listbox, I do
SendMessage(HwndListBox, LB_ADDSTRING, 0, (LPARAM)"someText");
I don't see any text.
Hm.. if you do not use owner draw style i.e. a normal list box, do you see the text appear. Just to make sure that at least that part is working fine.
Grace
August 11th, 2004, 04:04 PM
I figured it out.
It should be SendDlgItemMessage(hwndParant, IDC_LIST1, LB_GETTEXT, lpDIS->itemID, (LPARAM)sText);
Thanks for all of your help, guys! You two are awesome!
Grace
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.