Solved

Bolding Text

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Perl Awk Need Help 3 94
Smart Camera scanning and reading information 3 86
sumHeights2  challenge 7 76
Fibonacci challenge 11 82
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

707 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

17 Experts available now in Live!

Get 1:1 Help Now