Beranda > Delphi > Add a Bitmap to a Menu Item

Add a Bitmap to a Menu Item

Just follow these steps:

Create a Picture and store it as a file 'img.bmp'. Use the SetMenuItemBitmaps API call to connect the Picture to the Menu with these parameters: MenuItemFile is the name given to the horizontal Menuitem, e.g. "File", "Edit", "Help" 0,1 ... is the position of the item on which you want to place the bitmap (start counting with 0).

The first of the two bitmap handles is the one for the bitmap displayed for the unchecked menuitem.

The second bitmap handle is the one for the checked menuitem. They may be the same.


All this can by coded in the .Create of a form.
Try to make the picture not to large, or it will not be displayed completely. Only the right-top of the bitmap will be displayed.

Finally, here's the code:

var
Bmp1 : TPicture;

...

Bmp1 := TPicture.Create;
Bmp1.LoadFromFile('.\img.bmp');
SetMenuItemBitmaps(MenuItemTest.Handle, 0, MF_BYPOSITION,Bmp1.Bitmap.Handle, Bmp1.Bitmap.Handle);
...

Iklan
Kategori:Delphi
  1. Belum ada komentar.
  1. No trackbacks yet.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: