CCustomMenu m_cCustomMenu; MENUDATA menuData [8]; // as many menu items are present , You should be able to use //new and do the same 2、调用CreateMenu()设置有关参数。 m_customMenu.CreateMenu (); m_customMenu.SetIconSize (25,25); //This is to set the size of the Icon. // This should be used only once for any menu // in order to resize it, destroy and create the menu again with different size. m_customMenu.SetHighlightStyle (Normal); //Or TextOnly, if you want the // background color to remain the same // and the Text color to change to the Highlight color. // The following setXXXColor sets the menu colors. If you dont want to change any, Dont call these member functions. m_customMenu.SetTextColor (RGB (255,0,0)); m_customMenu.SetBackColor (RGB (255,255,255)); m_customMenu.SetHighlightColor (RGB (0,0,255)); 3、设置MENUDATA变量,并增加菜单项。 lstrcpy (menuData[0].menuText , "text1"); menuData[0].menuIconNormal= IDI_ICON1; m_customMenu.AppendMenu (MF_OWNERDRAW,3,(LPCTSTR)menuData);
if ( (state & ODS_SELECTED) ) { // draw the down edges
CPen *pOldPen = pDC->SelectObject (&m_penBack);
//You need only Text highlight and thats what you get if (m_hilightStyle != Normal) { pDC->FillRect (rect,&m_brBackground); } else { pDC->FillRect (rect,&m_brSelect); }
//While selected move the text a bit TRACE0 ("SELECT,SELECTED\n"); } else { CPen *pOldPen = pDC->SelectObject (&m_penBack); pDC->FillRect (rect,&m_brBackground); pDC->SelectObject (pOldPen); // draw the up edges pDC->Draw3dRect (rect,m_clrBack,m_clrBack); if ((HFONT)dispFont != NULL) dispFont.DeleteObject (); dispFont.CreateFontIndirect (&lf); //Normal
TRACE0 ("SELECT, NORMAL\n"); }
// draw the text if there is any //We have to paint the text only if the image is nonexistant if (hIcon != NULL) { if(DrawIconEx (pDC->GetSafeHdc(),rect.left,rect.top,hIcon, (m_iconX)?m_iconX:32,(m_iconY)?m_iconY:32,0,NULL,DI_NORMAL)) TRACE0("Wrote the icon successfully\n"); else TRACE0 ("SORRY.NOGO\n"); } //This is needed always so that we can have the space for check marks rect.left = rect.left +((m_iconX)?m_iconX:32);
if ( !strText.IsEmpty()) { // pFont->GetLogFont (&lf);
int iOldMode = pDC->GetBkMode();
pDC->SetBkMode( TRANSPARENT);
pDC->SetTextColor( crText);
pFont = pDC->SelectObject (&dispFont); TRACE1( "About To DrawText %s\n",strText); pDC->DrawText (strText,rect,DT_LEFT|DT_SINGLELINE|DT_VCENTER); TRACE0("Done\n"); pDC->SetBkMode( iOldMode ); pDC->SelectObject (pFont); //set it to the old font } dispFont.DeleteObject (); }