void DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct );
Parameters
lpDrawItemStruct
A pointer to a DRAWITEMSTRUCT structure describing the item to be painted.
Remarks
Called by the framework when a visual aspect of an owner-draw header control changes. The itemAction member of the DRAWITEMSTRUCT structure defines the drawing action that is to be performed.
By default, this member function does nothing. Override this member function to implement drawing for an owner-draw CHeaderCtrl object.
The application should restore all graphics device interface (GDI) objects selected for the display context supplied in lpDrawItemStruct before this member function terminates.
Example
// NOTE: CMyHeaderCtrl is a class derived from CHeaderCtrl.
// The CMyHeaderCtrl object was created as follows:
//
// CMyHeaderCtrl myHeader;
// myHeader.Create(WS_CHILD|WS_VISIBLE|HDS_HORZ,
// CRect(10, 10, 600, 50), pParentWnd, 1);
// This example implements the DrawItem method for a
// CHeaderCtrl-derived class that draws every item as a
// 3D button using the text color red.
void CMyHeaderCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// This code only works with header controls.
ASSERT(lpDrawItemStruct->CtlType == ODT_HEADER);
HDITEM hdi;
TCHAR lpBuffer[256];
hdi.mask = HDI_TEXT;
hdi.pszText = lpBuffer;
hdi.cchTextMax = 256;
GetItem(lpDrawItemStruct->itemID, &hdi);
// Draw the button frame.
::DrawFrameControl(lpDrawItemStruct->hDC,
&lpDrawItemStruct->rcItem, DFC_BUTTON, DFCS_BUTTONPUSH);
// Draw the items text using the text color red.
COLORREF crOldColor = ::SetTextColor(lpDrawItemStruct->hDC,
RGB(255,0,0));
::DrawText(lpDrawItemStruct->hDC, lpBuffer, strlen(lpBuffer),
&lpDrawItemStruct->rcItem, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
::SetTextColor(lpDrawItemStruct->hDC, crOldColor);
}
CHeaderCtrl Overview | Class Members | Hierarchy Chart
See Also CWnd::OnDrawItem