diff --git a/icon1.bmp b/icon1.bmp new file mode 100644 index 0000000..24b63af Binary files /dev/null and b/icon1.bmp differ diff --git a/unit1.lfm b/unit1.lfm index ba51a8a..c5f85b2 100644 --- a/unit1.lfm +++ b/unit1.lfm @@ -233,6 +233,9 @@ object Form1: TForm1 ImageIndex = 4 RadioItem = True end + object MenuItemBmp: TMenuItem + Caption = 'with bitmap' + end end object ImageList1: TImageList AllocBy = 8 diff --git a/unit1.pas b/unit1.pas index 652ad7e..064bdd9 100644 --- a/unit1.pas +++ b/unit1.pas @@ -56,6 +56,7 @@ TForm1 = class(TForm) MenuItem39: TMenuItem; MenuItem4: TMenuItem; MenuItem40: TMenuItem; + MenuItemBmp: TMenuItem; MenuItem5: TMenuItem; normal: TMenuItem; MenuItem6: TMenuItem; @@ -74,6 +75,7 @@ TForm1 = class(TForm) private FOrigWndState: TWindowState; FOrigBounds: TRect; + bmp: TBitmap; procedure SetFullScreen(AValue: boolean); procedure SetTheme(AColor: TColor); @@ -101,7 +103,15 @@ procedure TForm1.btnTheme2Click(Sender: TObject); end; procedure TForm1.FormCreate(Sender: TObject); +var + fn: string; begin + bmp:= TBitmap.Create; + fn:= ExtractFilePath(Application.ExeName)+'icon1.bmp'; + if FileExists(fn) then + bmp.LoadFromFile(fn); + MenuItemBmp.Bitmap:= bmp; + SetTheme(clPurple); end; diff --git a/win32menustyler.pas b/win32menustyler.pas index 1d0afe2..9fa586a 100644 --- a/win32menustyler.pas +++ b/win32menustyler.pas @@ -167,14 +167,20 @@ procedure TWin32MenuStyler.HandleMenuDrawItem(Sender: TObject; ACanvas: TCanvas; IconW:= 0; IconH:= 0; + + if Assigned(mi.Bitmap) then + begin + IconW:= mi.Bitmap.Width; + IconH:= mi.Bitmap.Height; + end; + Images:= mi.GetParentMenu.Images; if Assigned(Images) then begin - IconW:= Images.Width; - IconH:= Images.Height; + IconW:= Max(IconW, Images.Width); + IconH:= Max(IconH, Images.Height); end; - //todo: support MenuItem.Bitmap if IconW>0 then dxBig:= Max(dxBig, IconW + dxCell * MenuStylerTheme.IndentIconPercents * 2 div 100); @@ -216,11 +222,19 @@ procedure TWin32MenuStyler.HandleMenuDrawItem(Sender: TObject; ACanvas: TCanvas; R.Bottom:= ARect.Bottom; Windows.DrawTextW(ACanvas.Handle, PWideChar(BufW), Length(BufW), R, NDrawFlags); + if (not bInBar) and Assigned(mi.Bitmap) then + begin + ACanvas.Draw( + ARect.Left + (dx-mi.Bitmap.Width) div 2, + (ARect.Top+ARect.Bottom-mi.Bitmap.Height) div 2, + mi.Bitmap); + end + else if (not bInBar) and Assigned(Images) and (mi.ImageIndex>=0) then begin Images.Draw(ACanvas, - dxCell * MenuStylerTheme.IndentIconPercents div 100, - (ARect.Top+ARect.Bottom-IconH) div 2, + ARect.Left + (dx-Images.Width) div 2, + (ARect.Top+ARect.Bottom-Images.Height) div 2, mi.ImageIndex, not bDisabled); end else