我在制作自定义自画菜单时,怎么也去不掉菜单的边缘,很难看!!
请问该如何处理???
还有就是,我怎么才能制作仿XP的菜单?????
多谢了!!!

解决方案 »

  1.   

    http://mydelphi.8u8.com/download/xpmenu.zip
    这个控件有源码
      

  2.   

    用XPMenu 控件,輕輕松松搞定....
      

  3.   

    http://mydelphi.8u8.com/download/xpmenu.zip
    这个很好!
      

  4.   

    这是我以前写的一个XPMenu组件,写得很不好。就算给你一个思路吧,你看看吧,主要是写自画事件(OnDrawItem):
    unit XPMenu;interfaceuses
      Windows, Messages,SysUtils, Classes,Menus,Graphics;type
      TXPMenu = class(TComponent)
      private
        { Private declarations }
        FSelColor,FBdyColor,FIcnColor,FFntColor:TColor;
        procedure SetSelColor(SelColor:TColor);
        function  GetSelColor:TColor;
        procedure SetBdyColor(BdyColor:TColor);
        function  GetBdyColor:TColor;
        procedure SetFntColor(FntColor:TColor);
        function  GetFntColor:TColor;
        procedure SetIcnColor(IcnColor:TColor);
        function  GetIcnColor:TColor;
        procedure DrawItem(Sender: TObject; ACanvas: TCanvas;
                  ARect: TRect; Selected: Boolean);
        procedure MeasureItem(Sender: TObject; ACanvas: TCanvas;
                  var Width, Height: Integer);
      protected
        { Protected declarations }
      public
        { Public declarations }    constructor Create(AOwner:TComponent);override;
      published
        { Published declarations }
        property  BodyColor:TColor read GetBdyColor write SetBdyColor;
        property  SelectedColor:TColor read GetSelColor write SetSelColor;
        property  FontColor:TColor read GetFntColor write SetFntColor;
        property  GlyphColor:TColor read GetIcnColor write SetIcnColor;
      end;procedure Register;implementationprocedure Register;
    begin
      RegisterComponents('BlazingFire', [TXPMenu]);
    end;{ TXPMenu }procedure TXPMenu.MeasureItem(Sender: TObject; ACanvas: TCanvas;
      var Width, Height: Integer);
    var
      Txt:String;
    begin
      ACanvas.Font.Size:=8;
      Txt:=(Sender as TMenuItem).Caption;
      Width :=ACanvas.TextWidth(Txt)+20;
      Height:=ACanvas.TextHeight(Txt)+6;
      if Txt='-' then
         Height:=ACanvas.TextHeight(Txt) div 2;
    end;constructor TXPMenu.Create(AOwner: TComponent);
    var
      icount:integer;
    begin
      inherited create(AOwner);
      FBdyColor:=$00E6E6E6;
      FIcnColor:=$0074F1B9;
      FFntColor:=clBlack;
      FSelColor:=$00FFD8CE;
      for icount:=0 to Owner.ComponentCount-1 do
      begin
        if Owner.Components[icount] Is TMenu then
          (Owner.Components[icount] as TMenu).OwnerDraw:=True;
        if Owner.Components[icount] Is TMenuItem then
        begin
          (Owner.Components[icount] as TMenuItem).OnDrawItem:=DrawItem;
          (Owner.Components[icount] as TMenuItem).OnMeasureItem:=MeasureItem;
        end;
      end;
    end;procedure TXPMenu.DrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect;
      Selected: Boolean);
    var
      MenuItem:TMenuItem;
      IcnRect,TxtRect:TRect;
      Txt:String;
      B:TBitmap;
      icount:integer;
      IsTopItem:Boolean;
    begin
      MenuItem:=Sender as TMenuItem;
      Txt:=MenuItem.Caption;
      IcnRect:=Rect(ARect.Left,ARect.Top, ARect.Left+20,ARect.Bottom);
      TxtRect:=Rect(ARect.Left+22,ARect.Top,ARect.Right,ARect.Bottom);
      IsTopItem:=False;
      if MenuItem.GetParentMenu Is TMainMenu then
        for icount:=0 to MenuItem.GetParentMenu.Items.Count-1 do
          if MenuItem.GetParentMenu.Items[icount]=MenuItem then
          begin
            IsTopItem:=True;
            break;
          end;
      if IsTopItem then
      begin
        ACanvas.Brush.Color:=clBtnFace;
        ACanvas.Pen.Color:=clBtnFace;
        ACanvas.Rectangle(IcnRect);
      end
      else
      begin
        ACanvas.Brush.Color:=FIcnColor;
        ACanvas.Pen.Color:=FIcnColor;
        ACanvas.Rectangle(IcnRect);
        ACanvas.Brush.Color:=FBdyColor;
        ACanvas.Pen.Color:=FBdyColor;
      end;
      ACanvas.Rectangle(TxtRect.Left-2,TxtRect.Top,TxtRect.Right,TxtRect.Bottom);
      if Selected then
      begin
        ACanvas.Brush.Color:=FSelColor;
        ACanvas.Pen.Color  :=clBlack;
        ACanvas.Rectangle(ARect);
      end;
      if Txt='-' then
      begin
        ACanvas.Pen.Width  :=1;
        ACanvas.Pen.Color:=clGray;
        ACanvas.MoveTo(TxtRect.Left -1 ,TxtRect.Top+(TxtRect.Bottom-TxtRect.Top) div 2);
        ACanvas.LineTo(TxtRect.Right-2 ,TxtRect.Top+(TxtRect.Bottom-TxtRect.Top) div 2);
      end
      else
      begin
        ACanvas.Font.Size:=8;
        if MenuItem.Enabled then
          ACanvas.Font.Color:=FFntColor
        else
          ACanvas.Font.Color:=clGray;
        SetBkMode(ACanvas.Handle,Transparent);
        DrawText(ACanvas.Handle,
                 Pchar(Txt),
                 Length(Txt),
                 TxtRect,
                 DT_VCenter or DT_Left or DT_SingleLine );
      end;
      if MenuItem.Checked then
      begin
        ACanvas.Pen.Color  :=clGray;
        ACanvas.Pen.Width  :=1;
        ACanvas.Polyline([Point(IcnRect.Left+2 ,IcnRect.Bottom-2),
                          Point(IcnRect.Left+2 ,IcnRect.Top+2   ),
                          Point(IcnRect.Right-2,IcnRect.Top+2   )]);
        ACanvas.Pen.Color  :=clWhite;
        ACanvas.Pen.Width  :=1;
        ACanvas.Polyline([Point(IcnRect.Right-2,IcnRect.Top+2   ),
                          Point(IcnRect.Right-2,IcnRect.Bottom-2),
                          Point(IcnRect.Left+2 ,IcnRect.Bottom-2)]);
        ACanvas.Pen.Color  :=clRed  ;
        ACanvas.Pen.Width  :=2;
        ACanvas.Polyline([Point(IcnRect.Left+4 ,IcnRect.Top+10  ),
                          Point(IcnRect.Left+8 ,IcnRect.Top+14  ),
                          Point(IcnRect.Right-5,IcnRect.Top+5   )]);
      end
      else if (MenuItem.GetParentMenu.Images<>nil)and(Txt<>'-') then
      begin
        B:=TBitmap.Create;
        B.Transparent:=True;
        MenuItem.GetParentMenu.Images.GetBitmap(MenuItem.ImageIndex,B);
        IcnRect:=Rect(IcnRect.Left+2,IcnRect.Top+2,IcnRect.Right-2,IcnRect.Bottom-2);
        ACanvas.StretchDraw(IcnRect,B);
        B.Free;
      end;
    end;function TXPMenu.GetSelColor: TColor;
    begin
      Result:=FSelColor;
    end;procedure TXPMenu.SetSelColor(SelColor: TColor);
    begin
      FSelColor:=SelColor;
    end;function TXPMenu.GetBdyColor: TColor;
    begin
      Result:=FBdyColor;
    end;procedure TXPMenu.SetBdyColor(BdyColor: TColor);
    begin
      FBdyColor:=BdyColor;
    end;function TXPMenu.GetFntColor: TColor;
    begin
      Result:=FFntColor;
    end;procedure TXPMenu.SetFntColor(FntColor: TColor);
    begin
      FFntColor:=FntColor;
    end;function TXPMenu.GetIcnColor: TColor;
    begin
      Result:=FIcnColor;
    end;procedure TXPMenu.SetIcnColor(IcnColor: TColor);
    begin
      FIcnColor:=IcnColor;
    end;end.
      

  5.   

    D5-6:XPmenu+ThemeManagerD7只要XPmenu+MPmanifest
      

  6.   

    D5-6:XPmenu+ThemeManager  网上有很好使!我用了
      

  7.   

    to HOOK_TTG(钩子[TTG]) :解决没有啊?
    那个控件包下载后,安装完,可看到样例,或拷贝或直接应用sidebar控件都可。下载之后便知道了。
      

  8.   

    用控件倒是没问题!但是,这个控件的编程技巧很是令我伤心……
    很多,API函数以前都没见过,还有就是谁能详细的讲解一下
    像这种控件的编程方法!!!
    多谢了!!!