다음을 통해 공유


CButton::DrawItem

소유자가 그린 단추의 시각적 측면이 변경 될 때 프레임 워크에 의해 호출 됩니다.

virtual void DrawItem( 
   LPDRAWITEMSTRUCT lpDrawItemStruct  
);

매개 변수

  • lpDrawItemStruct
    하 긴 포인터는 DRAWITEMSTRUCT 구조. 구조가 필요한 드로잉 형식과 그려야 하는 항목에 대 한 정보가 포함 되어 있습니다.

설명

이 소유자가 그린 단추는 BS_OWNERDRAW 스타일 집합. 그리기는 소유자 그리기를 구현 하려면이 멤버 함수를 재정의 합니다. CButton 개체입니다. 응용 프로그램에서 디스플레이 컨텍스트를 제공에 대해 선택한 모든 그래픽 장치 인터페이스 (GDI) 개체를 복원 해야 lpDrawItemStruct 이전 멤버 함수를 종료 합니다.

참고는 BS_ 스타일 값입니다.

예제

// NOTE: CMyButton is a class derived from CButton. The CMyButton 
// object was created as follows: 
// 
// CMyButton myButton; 
// myButton.Create(_T("My button"), 
//      WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_OWNERDRAW,  
//      CRect(10,10,100,30), pParentWnd, 1); 
// 

// This example implements the DrawItem method for a CButton-derived  
// class that draws the button's text using the color red. 
void CMyButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
   UINT uStyle = DFCS_BUTTONPUSH;

   // This code only works with buttons.
   ASSERT(lpDrawItemStruct->CtlType == ODT_BUTTON);

   // If drawing selected, add the pushed style to DrawFrameControl. 
   if (lpDrawItemStruct->itemState & ODS_SELECTED)
      uStyle |= DFCS_PUSHED;

   // Draw the button frame.
   ::DrawFrameControl(lpDrawItemStruct->hDC, &lpDrawItemStruct->rcItem, 
      DFC_BUTTON, uStyle);

   // Get the button's text.
   CString strText;
   GetWindowText(strText);

   // Draw the button text using the text color red.
   COLORREF crOldColor = ::SetTextColor(lpDrawItemStruct->hDC, RGB(255,0,0));
   ::DrawText(lpDrawItemStruct->hDC, strText, strText.GetLength(), 
      &lpDrawItemStruct->rcItem, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
   ::SetTextColor(lpDrawItemStruct->hDC, crOldColor);
}

요구 사항

헤더: afxwin.h

참고 항목

참조

CButton 클래스

계층 구조 차트

CButton::SetButtonStyle

WM_DRAWITEM