|
Question : Owner Draw CListCtrl changing fonts
|
|
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)
|
|
Answer : Owner Draw CListCtrl changing fonts
|
|
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); }
|
|
|
|