CMenu::DrawItem

调用由结构,在一个所有者描述的菜单的可视方面是更改。

virtual void DrawItem(
   LPDRAWITEMSTRUCT lpDrawItemStruct 
);

参数

  • lpDrawItemStruct
    对包含有关所需的绘图的类型的信息 DRAWITEMSTRUCT 结构的指针。

备注

DRAWITEMSTRUCT 结构的 itemAction 成员定义要执行的绘制事件。 重写该成员函数的实现所有者描述 CMenu 对象的绘图。 应用程序应恢复为显示上下文中选择的所有图形设备接口(GDI)对象提供了在 lpDrawItemStruct 此成员函数的停止之前。

DRAWITEMSTRUCT 结构的声明参见 CWnd::OnDrawItem

示例

下面的代码是从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);
   }
}

要求

Header: afxwin.h

请参见

参考

CMenu选件类

层次结构图