CHeaderCtrl::DrawItem
调用由结构,当所有者描述标头(monthcalendar)控件的可视方面是。
virtual void DrawItem(
LPDRAWITEMSTRUCT lpDrawItemStruct
);
参数
- lpDrawItemStruct
有关介绍项目的 DRAWITEMSTRUCT 结构的指针将绘制。
备注
DRAWITEMSTRUCT 结构的 itemAction 成员定义要执行的绘制事件。
默认情况下,此成员函数不执行任何操作。 重写该成员函数的实现所有者描述 CHeaderCtrl 对象的绘图。
此成员函数终止之前,应用程序应恢复为显示上下文中选择的所有图形设备接口(GDI)对象提供了在 lpDrawItemStruct。
示例
// NOTE: CMyHeaderCtrl is a class derived from CHeaderCtrl.
// The CMyHeaderCtrl object was created as follows:
//
// CMyHeaderCtrl m_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;
const int c_cchBuffer = 256;
TCHAR lpBuffer[c_cchBuffer];
hdi.mask = HDI_TEXT;
hdi.pszText = lpBuffer;
hdi.cchTextMax = c_cchBuffer;
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,
(int)_tcsnlen(lpBuffer, c_cchBuffer),
&lpDrawItemStruct->rcItem, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
::SetTextColor(lpDrawItemStruct->hDC, crOldColor);
}
要求
Header: afxcmn.h