Solved

Owner Draw CListCtrl changing fonts

Posted on 1997-02-23
1
1,078 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…

685 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