[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 807
  • Last Modified:

SetMenuItemBitmaps parameters...

Hi!

let me ask a pretty silly question.
What are the parameters for SetMenuItemBitmaps????

I know which they are and have read the documentation in win32.hlp but waht I mean is what are they?

hMenu : Integer
for example is it the handle to the mainmenu or the specific menu item I want to assign a bitmap to?

and the following two paramets
what should they be if I want to
assign the bitmap to the menuitem with menuindex = 4?

And finally the bitmap handle.
Can I us e both bitmap and icon
handles?
or just bitmap.handle????

please enlighten me...

tnx on advance
\Dr. Gonzo
0
dr_gonzo
Asked:
dr_gonzo
  • 4
  • 4
  • 3
1 Solution
 
LischkeCommented:
Hi Gonza,

from my view the parameters are quite unique.

hMenu is the handle to the menu to which the item belongs (might be a submenu)

For changing item with index 4 (assuming zero based indexing) you'd pass 4 and MF_BYPOSITION in the next two parameters.

The last two parameters clearly tell you they expect HBITMAPS not HICON, so you only can pass bitmap handles not icon handles.

Ciao, Mike
0
 
intheCommented:
see an example here at this fantastic website:

http://inthe.future.easyspace.com/delphi/addmenu.html

;-)
0
 
dr_gonzoAuthor Commented:
hmmm. Something really fishy with my code.
inthe: I run the code you linked to. And it works very nice with the system menu. I think my problem is the handle of my menu.
-----------

If I have a TMainMenu.
Wouldn't the handle be myMainMenu.Handle
???

Look at my source below.
Look at the trhee diffrent assigns of myHandle. Why does it only work with the one that is not commented out?

I want to set a bitmap to the first item in my main menu. Why doesn't it work???

procedure TForm1.FormCreate(Sender: Object);
var
myBmp            : TPicture;
myHandle      : Integer;

begin
   myBmp := TPicture.Create;
   myBmp.LoadFromFile('c:\test.bmp');
   myHandle := Windows.GetSystemMenu(Handle, False);
   //myHandle := Main1.Handle
   //myHandle := Windows.GetMenu(Handle);
   SetMenuItemBitmaps(myHandle, 0, MF_BYPOSITION, myBmp.Bitmap.Handle, myBmp.Bitmap.Handle);
   DrawMenuBar(Handle);
end;

tnx for the help sofar.
\Dr. Gonzo
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LischkeCommented:
Hi Gonzo,

perhaps at this time your menu handle isn't created yet? Try assigning the bitmap in a button click handler. If that works that my assumption is true else there must be another problem.

Ciao, Mike
0
 
intheCommented:
i put some comments i hope you follow you need to reference the item[0] etc for the correct handle.

try this instead:

procedure TForm1.FormCreate(Sender: TObject);
var
myBmp : TPicture;
myHandle : Hmenu;
begin
   myBmp := TPicture.Create;
   myBmp.LoadFromFile('c:\test.bmp');
   myHandle := Mainmenu1.Items[0].Handle;
  { the  0 in above is the first mainmenuitem}
   SetMenuItemBitmaps(myHandle, 0, MF_BYPOSITION, myBmp.Bitmap.Handle, myBmp.Bitmap.Handle);
  {the 0 in this above is the first item in first mainmenuitem
    changed to a 1 would be second item in first mainmenuitem
     SetMenuItemBitmaps(myHandle, 1, MF_BYPOSITION, myBmp.Bitmap.Handle, myBmp.Bitmap.Handle);}
   DrawMenuBar(Handle);
end;


Regards Barry
0
 
intheCommented:
did you try it ?
0
 
dr_gonzoAuthor Commented:
Yeah sure I tried it!

I even thought I had given you the points already but EE's database don't seem to remeber what happened during the weekend :-)

I said I'd give you the points, but that I wanted to keep the question open so I could also understand the code.

It was hard to se why
MainMenu.Items[0].Handle
wasn't the same thing as
Item1.Handle

When Item1 was MainMenu's first item...

It all came clear to me anyway so I don't need to ask it anymore :-)

tnx for the help

regards,
Dr. Gonzo
0
 
intheCommented:
ok :-)
and yes it is a bit confusing at first.
0
 
LischkeCommented:
Gonzo, thank you for totally ignoring me. I actually answered most of your original question...
0
 
dr_gonzoAuthor Commented:
Lischke:
Sorr actually I wasn't ignoring you. I wrote two mesages during the weekend but none of them shows up here today. And when I wrote the last time I was in a bite of a hurry.
Anyway: Your answer didn't take me were I wanted to go.
My code does follow all your tips and ideas of what code be wrong.

What was actually wrong was that the handle to use is suppost to be
something else than one could expect if one didn't use the brain the hole way out.

What made me understand what I was doing wrong was the code from Inthe.
And I have to give the points to the one that solved my problem, not the one that answered first.

Anyway wasn't my meaning to ignore your answer. No hard feelings I hope...

regards,
Dr. Gonzo
0
 
LischkeCommented:
Hi Dr. Gonzo,

I agree, the points should go to the one who actually solved the problem. Only one conflict remains, though. What about the one who answers your question? The first (Barry) and the latter (me) are different persons...

I don't want that you offer now additional points. All I request that you think about the discussion here and draw your consequences.

Ciao, Mike
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now