Board index » delphi » Bitmaps in menus - Help!!!

Bitmaps in menus - Help!!!

I wish to assign a bitmap to items in a mainmenu. I have been trying the
API call as below, but this fails. Can anyone help please.

procedure TForm1.FormCreate(Sender: TObject);
begin
    if not
SetMenuItemBitmaps(mainmenu1.handle,1,MF_BYPOSITION,image1.picture.bitmap.ha
ndle, image2.picture.bitmap.handle)
    then messagedlg('Error: '+inttostr(getlasterror),mterror,[mbok],0);
end;

I have a form with a mainmenu & 2 images.
Thanks in advance
Peter Phillips
Pet...@rmg.co.uk

 

Re:Bitmaps in menus - Help!!!


Peter Phillips heeft geschreven in bericht
<01bd3ad5$dab3bf60$a2557...@rodman.globalnet.co.uk>...

Quote
>I wish to assign a bitmap to items in a mainmenu. I have been trying the
>API call as below, but this fails. Can anyone help please.

>procedure TForm1.FormCreate(Sender: TObject);
>begin
>    if not
>SetMenuItemBitmaps(mainmenu1.handle,1,MF_BYPOSITION,image1.picture.bitmap.h
a
>ndle, image2.picture.bitmap.handle)
>    then messagedlg('Error: '+inttostr(getlasterror),mterror,[mbok],0);
>end;

>I have a form with a mainmenu & 2 images.
>Thanks in advance
>Peter Phillips
>Pet...@rmg.co.uk

Try this. I took from a list of Delphi tips and tricks.

From: kcla...@innet.be (Kurt Claeys)
Subject: Re: [delphi] How do I add a bitmap to a MENU ...
Date: Tue, 20 Jun 1995 23:40:14 +0200

Quote
> How do I add bitmaps to a menu?

Maybe like this :

var
   Bmp1 : TPicture;

...

Bmp1 := TPicture.Create;
Bmp1.LoadFromFile('c:\where\b1.BMP');
SetMenuItemBitmaps( MenuItemTest.Handle,
   0,
   MF_BYPOSITION,
   Bmp1.Bitmap.Handle,
   Bmp1.Bitmap.Handle);
...

Create a Picture.
Load a .BMP from somewhere into the picture.
Use the SetMenuItemBitmaps API call to connect the Picture to the Menu with
these
parameters :
- MenuItemTest is the name given to the horizontal Menuitem
- 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 is the one for the checked menuitem. These can be the same or
not.

All this can by coded in the .Create of a form.

Result : It works, but only the right-top of the bitmap is displayed. Rest
us to change the height and/or width of the menuitem according to the bitmap

Re:Bitmaps in menus - Help!!!


In article <01bd3ad5$dab3bf60$a2557...@rodman.globalnet.co.uk>, "Peter

Quote
Phillips" <Pet...@rmg.co.uk> writes:
>I wish to assign a bitmap to items in a mainmenu. I have been trying the
>API call as below, but this fails. Can anyone help please.

>procedure TForm1.FormCreate(Sender: TObject);
>begin
>    if not
>SetMenuItemBitmaps(mainmenu1.handle,1,MF_BYPOSITION,image1.picture.bitmap.ha
>ndle, image2.picture.bitmap.handle)
>    then messagedlg('Error: '+inttostr(getlasterror),mterror,[mbok],0);
>end;

The API call you are using allocates bitmaps for the check-mark for the checked
and un-checked states. It failed because a main menu item does not have
check-marks.

If you wanted to replace the text of the menu items with bitmaps then you want
the ModifyMenu call. I used it for popup menu items , the bitmaps of which were
held in a resource, as follows :-

  ModifyMenu(NotePopUpMenu.Handle, Crotchet.Command,
             mf_ByCommand or mf_BitMap, Crotchet.Command, PChar(HCrotchetBMP));

The popup menu had a TMenuItem named Crotchet (it was a music program), using
mf_ByCommand and Crotchet.Command makes for clearer code. The mf_BitMap
nominates the last parameter as a bitmap handle.

See the ModifyMenu API call in Win32API.

Alan Lloyd
alangll...@aol.com

Other Threads