Solved

Bolding Text

Posted on 1998-09-23
4
442 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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
xyBalance chalenge 58 104
Window placement 17 100
x-bar in Google Sheets 2 126
"Black Box" Testing of Control System Software 2 125
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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 an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Suggested Courses

734 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