1.N13AdvancedDrawItem 绘制子菜单
TRect tempRect;//临时矩形区域
TMenuItem *pItem = dynamic_cast<TMenuItem *>(Sender);
if(!pItem) return;
AnsiString Caption = pItem->Caption;
ACanvas->Brush->Color = clWhite;
ACanvas->FillRect(ARect);
tempRect = Rect(ARect.left,ARect.top,21,ARect.Bottom);
ACanvas->Brush->Color = TColor(RGB(249,248,244));;
ACanvas->FillRect(tempRect);
TCustomImageList *ImageLst = new TCustomImageList(this);
TIcon *DrawIcon = new TIcon();
if(Caption=="-")
{
ACanvas->Pen->Color=TColor(RGB(208,201,161));
ACanvas->MoveTo(21,ARect.top+(ARect.Bottom-ARect.top)/2);
ACanvas->LineTo(ARect.right,ARect.top+(ARect.Bottom-ARect.top)/2);
return;
}
ImageLst = pItem->GetImageList();
ImageLst->GetIcon(pItem->ImageIndex,DrawIcon);
if((State.Contains(odSelected)==true)&&(State.Contains(odDisabled)==false))
{
ACanvas->Brush->Color = TColor(RGB(198,211,239));
ACanvas->Pen->Color = TColor(RGB(49,105,198));
ACanvas->Rectangle(ARect.left,ARect.top,ARect.right,ARect.Bottom);
if(ImageLst!=NULL)
{
ACanvas->Draw(ARect.left,ARect.top,DrawIcon);
}
ACanvas->Font->Color = clBlack;
}
else if(State.Contains(odDisabled)==true)
{
ACanvas->Font->Color = TColor(RGB(208,201,161));
}
if(pItem->Checked)
{
ACanvas->Brush->Color = TColor(RGB(198,211,239));
ACanvas->Pen->Color = TColor(RGB(49,105,198));
ACanvas->Rectangle(ARect.left+1,ARect.top+1,20,ARect.Bottom-1);
}
if(ImageLst!=NULL)
{
ACanvas->Draw(ARect.left,ARect.top-1,DrawIcon);
}
DrawIcon->Free();
ACanvas->Brush->Style = bsClear;
ARect.left+=30;
ARect.top+=5;
DrawText(ACanvas->Handle,Caption.c_str(),-1,&ARect,DT_LEFT);
AnsiString ShortCutText = ShortCutToText(pItem->ShortCut)+" ";
DrawText(ACanvas->Handle,ShortCutText.c_str(),-1,&ARect,DT_RIGHT);
2 绘制主菜单
void __fastcall TMainFm::MenuOwerDrawAdvancedDrawItem(TObject *Sender, TCanvas *ACanvas,
TRect &ARect, TOwnerDrawState State)
{
TRect tempRect;//临时矩形区域
TMenuItem *pItem = dynamic_cast<TMenuItem *>(Sender);
if(!pItem) return;
ACanvas->Brush->Color = clBtnFace;
ACanvas->FillRect(ARect);
AnsiString Caption = pItem->Caption;
tempRect = Rect(ARect.left,ARect.top,ARect.right,ARect.Bottom);
if(State.Contains(odHotLight)&&!State.Contains(odDisabled))
{
ACanvas->Brush->Color = TColor(RGB(198,211,239));
ACanvas->Pen->Color = TColor(RGB(49,105,198));
ACanvas->Rectangle(ARect.left,ARect.top+1,ARect.right,ARect.Bottom);
}
else if ((State.Contains(odSelected)==true)&&(State.Contains(odDisabled)==false))
{
ACanvas->Brush->Color = TColor(RGB(236,233,216));
ACanvas->Pen->Color = TColor(RGB(138,134,122));
ACanvas->Rectangle(ARect.left,ARect.top+1,ARect.Right,ARect.Bottom);
}
else if(State.Contains(odDisabled)==true)
{
ACanvas->Font->Color = TColor(RGB(208,201,161));
}
tempRect.top+=3;
DrawText(ACanvas->Handle,Caption.c_str(),-1,&tempRect,DT_CENTER);
}