次の方法で共有


CHeaderCtrl::DrawItem

オーナー描画のヘッダー コントロールの表示上の外観が変化したときに、フレームワークが呼び出します。

virtual void DrawItem(
   LPDRAWITEMSTRUCT lpDrawItemStruct 
);

パラメーター

  • lpDrawItemStruct
    描画する項目を記述している DRAWITEMSTRUCT 構造体へのポインター。

解説

DRAWITEMSTRUCT 構造体の itemAction メンバーは、実行する描画動作を定義します。

既定では、このメンバー関数は何も実行しません。 オーナー描画の CHeaderCtrl オブジェクトの描画を実装するには、このメンバー関数をオーバーライドします。

アプリケーションでは、このメンバー関数を終了する前に、lpDrawItemStruct で指定したディスプレイ コンテキストに対して選択されているすべてのグラフィック デバイス インターフェイス (GDI) オブジェクトを元の状態に戻しておく必要があります。

使用例

// 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);
}

必要条件

**ヘッダー:**afxcmn.h

参照

参照

CHeaderCtrl クラス

階層図

CWnd::OnDrawItem

その他の技術情報

CHeaderCtrl のメンバー