views:

44

answers:

1

Hello,

I am currently writing a plugin for a third party application.
As the plugin framework does not provide any way to access the UI I am now trying to do this manually via the WinAPI.

More specifically, I want to add a custom menu item for my plugin in the "File" menu.

My first attempt using FindWindow to retrieve the handle of the main window and the using GetMenu was not successful, as GetMenu simply returned NULL.

My next step was to use EnumChildWindows and search for a child having the text "&File" (I really don't like this approach as it makes localization quite terrible). However, I only found out the handle of the menu item, but I need the corresponding HMENU to use AppendMenu then, don't I?
Simply casting does not work and results in an "Invalid menu handle".

Is it actually possible to achieve what I am trying? How?

Thanks for your ideas in advance!

+1  A: 

It more than likely just isn't a HMENU. Custom menu implementations are common, the one Window provides is dated and inflexible. Compare to Windows Forms' MenuStrip for example.

Of course, that blows a gaping hole in your approach.

Hans Passant
But Winsharp only needs it to work on this specific application (that his plugin is written for) so if he can make this method work why not?
Elemental
Erm, he can't make it work.
Hans Passant
Hmm - I understand. If it is a custom menu - do you have any ideas how it might be implemented (it looks like a OS themed menu)? Maybe I am able to hook the creation of the menu popup itself...
winSharp93
Hooking the popup might work to get a handle, but you still don't have any way to *add* an item. These won't be MENUINFOs. Anything goes as far as possible implementations, study the dependencies and look at the EXE internals to try to discover a class library that might have been used.
Hans Passant
Maybe this won't be necessary: I hooked into the WndProc of the application's window and waited for WM_MENUSELECT whose lParam contains a handle to the menu being opened. I used AppendMenu passing that handle and finally my menu item is visible (not in the menu I want it to have but I hopefully will manage to place it where I want). Now I will try if I can solve the problem and try to react to the user clicking my menu item.
winSharp93
There is still one big problem: WM_MENUSELECT is only sent when the user moves over the first menu entry - when opening the menu for the first time, my entry won't be visible. For the "File" menu WM_INITMENU does not seem to be triggered. WM_INITMENU could be the solution but I don't receive this message. Any ideas why?
winSharp93