Solved

Bolding Text

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

772 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