Solved

Owner Draw CListCtrl changing fonts

Posted on 1997-02-23
1
1,073 Views
Last Modified: 2013-12-03
I wanted to have a CListCtrl that can display items in multiple colors, so I thought I would make it Owner-Draw.

It works fine when it uses the default font it was created with, but if it is changed to a larger font using SetFont() the rcItem member of the DRAWITEMSTRUCT passed to CListCtrl::Drawitem() has the wrong coordinates in it. It seems that the rcItem contains the rectangle for the item if it were drawn with the original (small ) font.

If the listctrl is not owner draw calling Setfont() works okay..

How can I make an owner-draw list control change font correctly? Also, how do I stop garbage pixels appearing when I resize the columns (ie: when a column is enlarged, pixels from the column boundary appear on the border of the column to the right, and remain until the row is redrawn by selecting it with the mouse)
0
Comment
Question by:ceccato
1 Comment
 
LVL 1

Accepted Solution

by:
serge010697 earned 100 total points
ID: 1300518
1. You should capture not only WM_DRAWITEM message, but WM_MEASUREITEM too.

2. I've done this using the following virtual function:

BOOL CMyListCtrl::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
HWND hHeader = ::GetWindow(m_hWnd, GW_CHILD);
LPNMHDR pHeader = (LPNMHDR)lParam;
if (hHeader && (pHeader->code == HDN_ITEMCHANGINGW || pHeader->code == HDN_ITEMCHANGINGA))
{
::InvalidateRect(m_hHeader, NULL, FALSE);
*pResult = FALSE;
return FALSE;
}
return CListCtrl::OnNotify(wParam, lParam, pResult);
}

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
Detect CR LF to each line 12 152
Set Font and Size on Excel Template 2 101
font type, point size, readability questions 7 100
has77  challenge 9 71
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

914 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