共用方式為


CHeaderCtrl::DrawItem

呼叫框架,其在主控描繪標題變更的視覺外觀。

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

請參閱

參考

CHeaderCtrl 類別

階層架構圖

CWnd::OnDrawItem