DelphiFAQ Home Search:

Add a bitmap to a menu item

 

commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

Just follow these steps:

  1. Create a Picture and store it as a file 'img.bmp'.
  2. Use the SetMenuItemBitmaps API call to connect the Picture to the Menu with these parameters:
  3. MenuItemFile is the name given to the horizontal Menuitem, e.g. "File", "Edit", "Help"
  4. 0,1 ... is the position of the item on which you want to place the bitmap. (start counting with 0)
  5. The first of the two bitmap handles is the one for the bitmap displayed for the unchecked menuitem
  6. 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);
...

Don't forget to free the bitmap Bmp1 e.g. when you destroy your form.

Comments:

 

 

Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option.
 
It seems that you are
from Los Angeles, US .

Info/ Feedback on this

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:
photo Add a picture:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity. The owner of this web site reserves the right to delete such material.