Solved

Bolding Text

Posted on 1998-09-23
4
431 Views
Last Modified: 2013-11-19
I'm trying to bold certain line in a list box and trying
to keep others normal.

Is this possible and if so how?
0
Comment
Question by:rmille13
  • 2
4 Comments
 

Author Comment

by:rmille13
ID: 1322515
Edited text of question
0
 
LVL 3

Expert Comment

by:plaroche
ID: 1322516
You will have to implement your listbox as an ownerdraw control and do the drawing yourself.

You can change the control's font but it will affect every listbox item.

You can find ownerdraw listbox samples at many places, start looking at codeguru (www.codeguru.com).

All you will need is to know when to use a certain font or another one and select that font in the dc.
0
 

Author Comment

by:rmille13
ID: 1322517
I understand this but how do I select a font for a listbox item  without selecting it for the entire control?
0
 
LVL 8

Accepted Solution

by:
Answers2000 earned 100 total points
ID: 1322518
For a list box:

1. In styles set owner draw fixed (for one on a dialog this is in the resources - right click properties on the list box) - LBS_OWNERDRAWFIXED - and has strings (LBS_HASSTRINGS)

2. You need to override DrawItem.  This function is responsible for drawing each item in the list box.  You get a DRAWITEMSTRUCT (ptr to this) which contains the info you need to draw including the hDC, rectangle for the item, whether the item has selection, whether it has the focus and the index of the item.

In draw item you need to performing the following steps

1. Draw the background to the item (say using FillSolidRect).  Draw in the background color or in the selection color.  You can tell which to draw by checking the ODS_SELECTED flag, you can tell the rect by looking in rcItem of DrawItemStruct, you can tell the get the standard background or selection color by using GetSysColor

2. Get the index of the item from the draw item struct, and retrieve the text of the line

3. If the item is to be a "bold" item using CreateFont or CreateFontIndirect to create a bold font and select it into the DC (SelectObject and save the return value).  Skip this step for a normal item.

4. Set the text color using SetTextColor.  You can check the ODS_SELECTED flag to know if the item is selected.  Use GetSysColor to get either the standard window text color or the selection text color.

5. Set the text mode (SetBkMode) to transparent

6. TextOut or DrawText the text into rectangle

7. If a bold item restore the original font by callign SelectObject again

8. Check if the item is focused (should have dotted line around it) by checking the ODS_FOCUS flag.  If it is using DrawFocusRect to draw the focus rect


For a listview/listctrl in details mode, basically the same - except no "has strings style" and the owner draw style has a different name
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Separate into files by filename 12 87
iSeries DB2 Query 2 97
sum67 challenge 35 110
child constructor and parent constructor, overriding and overloading 6 89
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question