다음을 통해 공유


CMenu::DrawItem

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

virtual void DrawItem(
   LPDRAWITEMSTRUCT lpDrawItemStruct 
);

매개 변수

  • lpDrawItemStruct
    에 대 한 포인터는 DRAWITEMSTRUCT 필요한 드로잉 유형에 대 한 정보를 포함 하는 구조입니다.

설명

itemAction 소속은 DRAWITEMSTRUCT 수행 되는 그리기 작업 구조를 정의 합니다.드로잉에 대 한 소유자 그리기를 구현 하려면이 멤버 함수를 재정의 합니다. CMenu 개체입니다.응용 프로그램에서 디스플레이 컨텍스트를 제공에 대해 선택한 모든 그래픽 장치 인터페이스 (GDI) 개체를 복원 해야 lpDrawItemStruct 이 멤버 함수를 종료 합니다.

참조 CWnd::OnDrawItem 에 있는 DRAWITEMSTRUCT 구조.

예제

MFC에서 다음 코드는 CTRLTEST 샘플:

// Override DrawItem() to implement drawing for an owner-draw CMenu object.
// CColorMenu is a CMenu-derived class.
void CColorMenu::DrawItem(LPDRAWITEMSTRUCT lpDIS)
{
   CDC* pDC = CDC::FromHandle(lpDIS->hDC);
   COLORREF cr = (COLORREF)lpDIS->itemData; // RGB in item data

   if (lpDIS->itemAction & ODA_DRAWENTIRE)
   {
      // Paint the color item in the color requested
      CBrush br(cr);
      pDC->FillRect(&lpDIS->rcItem, &br);
   }

   if ((lpDIS->itemState & ODS_SELECTED) &&
      (lpDIS->itemAction & (ODA_SELECT | ODA_DRAWENTIRE)))
   {
      // item has been selected - hilite frame
      COLORREF crHilite = RGB(255-GetRValue(cr),
                  255-GetGValue(cr), 255-GetBValue(cr));
      CBrush br(crHilite);
      pDC->FrameRect(&lpDIS->rcItem, &br);
   }

   if (!(lpDIS->itemState & ODS_SELECTED) &&
      (lpDIS->itemAction & ODA_SELECT))
   {
      // Item has been de-selected -- remove frame
      CBrush br(cr);
      pDC->FrameRect(&lpDIS->rcItem, &br);
   }
}

요구 사항

헤더: afxwin.h

참고 항목

참조

CMenu 클래스

계층 구조 차트