Sign in to follow this  
BeanDog

[Windows] Showing shell context menu for a file?

Recommended Posts

I'd like to show the Windows shell context menu for a file in a tool I'm writing--that is, show the popup menu that would appear if they right-clicked a particular file in Windows Explorer. Two hours of Googling have produced nothing; suprising to me, since it seems a reasonably straightforward and common task :'-( I'm using C#, but I'd appreciate sample code in any language.

Share this post


Link to post
Share on other sites
There may be an easier way, but one way is to get the IShellFolder interface for the folder that contains the file. Use the GetUIObjectOf() member function with the IID_IContextMenu to get a IContextMenu for the file. You then use IContextMenu::QueryContextMenu() to fill an HMENU with the menu items. TrackMenuItems displays the menu, and you then use IContextMenu::InvokeCommand() to execute the selected command when TrackMenuItems returns (or off of the window message).

Share this post


Link to post
Share on other sites
I managed to combine a bunch of examples found on the intertubes into a class that can produce such a context menu with one function call, passing in the path to display the menu for as well as the location on the screen to display the menu.

I'd post the source here, but it's 145KB. Any future readers or Google searchers, feel free to PM me for the source.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this