procedure AddBitmapToMenuItem( PopupMenu : TPopupMenu; nItemPos : integer; Bitmap : TBitmap ); begin SetMenuItemBitmaps( PopupMenu.Handle, nItemPos, MF_BYPOSITION, Bitmap.Handle, Bitmap.Handle ); end; |
The Windows API function "SetMenuItemBitmaps()" is mostly used to set bitmaps for "checkable" menu items -- menu items with two bitmaps for checked and unchecked states. To keep the "AddBitmapToMenuItem()" function simple, we're not changing menu item's size according to the size of the bitmap. This means, you can only pass bitmaps that are small enough to fit in the default size of your menu items.
To keep the bitmaps for your menu items built into your application:
AddBitmapToMenuItem( PopupMenu1, 0, Image1.Picture.Bitmap ); |
To load the menu item bitmaps at the run-time:
procedure TForm1. FormCreate(Sender: TObject); var BMP : TBitmap; begin BMP := TBitmap.Create; BMP.LoadFromFile( 'MyBitmap.BMP' ); AddBitmapToMenuItem( PopupMenu1, 0, BMP ); end;