CMenu::DrawItem
Called by the framework when a visual aspect of an owner-drawn menu changes.
virtual void DrawItem(
LPDRAWITEMSTRUCT lpDrawItemStruct
);
Параметры
- lpDrawItemStruct
A pointer to a DRAWITEMSTRUCT structure that contains information about the type of drawing required.
Заметки
The itemAction member of the DRAWITEMSTRUCT structure defines the drawing action that is to be performed. Override this member function to implement drawing for an owner-draw CMenu object. The application should restore all graphics device interface (GDI) objects selected for the display context supplied in lpDrawItemStruct before the termination of this member function.
See CWnd::OnDrawItem for a description of the DRAWITEMSTRUCT structure.
Пример
The following code is from the MFC CTRLTEST sample:
// 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);
}
}
Требования
Header: afxwin.h