Solved

Owner Draw CListCtrl changing fonts

Posted on 1997-02-23
1
1,072 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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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…

763 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

7 Experts available now in Live!

Get 1:1 Help Now