Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Owner Draw CListCtrl changing fonts

Posted on 1997-02-23
1
Medium Priority
?
1,085 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 200 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

916 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