Menu of another application

Hi everybody, long time. :wave:
I have a question regarding WinAPI and perhaps someone can help me (should be simple but not trivial).

I want to call a menu item of another application (maybe using SendMessage - I don't know). Anyone has an example?

Also, I want to put the menu of the other application in my Windows Forms - for example if the other application has a File menu with Save, Open, and New items, I want to create the same menu in my application. Is that possible? Anyone seen an example?
[531 byte] By [jhammer] at [2007-11-20 9:18:35]
# 1 Re: Menu of another application
Hi! Long time no see, too long!
You're way of thinking is right, you can use SendMessage (among a few others), but you would have to get a handle to the particular menu item you want to click on
There is a relatively recent thread by TT(n) demonstrating this. He also has a link to it in his signature. I think it's called "Send click to window".
Try that, and hopefully you come right
HanneSThEGreaT at 2007-11-10 3:09:08 >
# 2 Re: Menu of another application
Hey Yariv,
It is nice to see you here again. :)

GetMenu API and GetSubMenu API should give you the handle of the menu and its sub-items respectively. Once you get the handle to the main menu, use GetMenuItemrect API to get the screen coordinates. Then you can use mouse_event API to send a click the menu. Once the menu is open you can repeat the same process with the sub menu but using GetSubMenu API this time. I think this should work.

Regarding hosting another application's menu in your own application, I have not tried this before. Probably someone has a better suggestion.
Shuja Ali at 2007-11-10 3:10:05 >
# 3 Re: Menu of another application
Thanks Hannes and Shuja

What's better: the SendMessage Approach or the mouse events approach? Do you have links to code samples for that (I mean it should be easy enough, but why waste time on the bits if there are past solutions?)

Also, thanks for the link of TT(n), his class seems nice, I must test it before I use it but if it works it should simplify things.
jhammer at 2007-11-10 3:11:04 >
# 4 Re: Menu of another application
There is sample on how to use Getmenu in VB6. I guess it should be easy enought o convert that to .NET.

Take a look at Auto Click Menu on this page
http://allapi.mentalis.org/apilist/GetMenu.shtml

Well clicking also sends a message to the window so using SendMessage is easier.
Shuja Ali at 2007-11-10 3:12:09 >
# 5 Re: Menu of another application
Hi jHammer,

Hey thanks for mentioning my SendClickToWindow class HanneS.

If you have any questions about it's use, dont hesitate to ask. :)
I'd try SendMessage first with the WM_COMMAND constant.
I learned that one from HanneS.
I've got an example in my signature for the task manager that uses this, but some things can't be done with it.

So then try the internal mouse events API and it will usually be able to simulate the message more closely, because it does a couple of extra things. :thumb:
TT-n at 2007-11-10 3:13:08 >