Solved

Bolding Text

Posted on 1998-09-23
4
416 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expand data scrubbing tool 13 32
MaxSpan challenge 9 80
sumHeights2  challenge 7 87
Trying to run powershell  in a batch file. How do I do this? 8 65
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 …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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.

910 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now