0

I have a desktop app which after taking input from the user displays a list of files and folder(using a ListBox).
I want that when the user right clicks on any item in the ListBox, the right click menu of windows explorer should display.

I know I will have to use P/Invoke for this, but I am unable to find any relevant information such as which dll I have to use or which function I have to call.

Can anybody help me with that?

Pratik Singhal
  • 6,283
  • 10
  • 55
  • 97
  • Is it a WPF or a Winform application ? – Orace Jul 05 '22 at 15:56
  • Does this answer your question? [How do you show the Windows Explorer context menu from a C# application?](https://stackoverflow.com/questions/451287/how-do-you-show-the-windows-explorer-context-menu-from-a-c-sharp-application) – Orace Jul 05 '22 at 16:03

2 Answers2

1

So this question is very old but has no accepted answer. I dont think Visionstar understood the issue OP is having.

My understanding is that you have an application running, and you would like to add an option in the WINDOWS EXPLORER's right-click menu. Not in your own application's context menu.

I do not think you can achieve this within your own application, however, what you can do is add an item in the Windows explorer's context menu (nothing to do with your application, you can just do that in windows; see link below) that you can setup to call a little script you would make (literally a little batch file... but could be a .net app too). That little script can take care of warning you main application. By creating a text file, or json file in a hot folder, or some other mechanism you would have to come up with.

Adding an item in the windows' contextual menu: How add context menu item to Windows Explorer for folders

If you need to deploy this to other PCs, you can make a add_menu.reg file to make it simpler. I'll let you Google that one, but I think it's as simpe as a right-click -> export key in your regedit.

0

You will need to code it yourself, there is no embedded way simply add a OS-Contextmenu to it,because you have programmed the listbox, so you have to append some contextmenu to the listitem-rightclicks

Here are examples/guidance for adding a context menu: http://msdn.microsoft.com/en-us/library/aa984254%28v=vs.71%29.aspx

http://social.msdn.microsoft.com/Forums/windows/en-US/790cd8be-0ba8-4f10-95a8-c88f1023d6e7/how-can-i-create-a-rightclick-menu-i-c?forum=winforms

Visionstar
  • 355
  • 2
  • 12
  • I know how to create a right click menu, problem is that I have to integrate windows explorer's right click menu as it is. – Pratik Singhal Feb 09 '14 at 05:32
  • Then you just need to code it, i guess that's the fastest solution. – Visionstar Feb 09 '14 at 11:48
  • See, I am not able to understand where should I start coding for it?Any libraries, tutorials would be helpful – Pratik Singhal Feb 09 '14 at 11:58
  • what exactly do you not understand? the coding of some entries in a contextmenu? you said you can code a contextmenu, so where's the problem? – Visionstar Feb 09 '14 at 14:30
  • The problem is in coding the windows right click menu(which opens when you right click any file in windows explorer.) I want that menu exactly. – Pratik Singhal Feb 09 '14 at 16:24
  • Then implement them, one by one? – Visionstar Feb 09 '14 at 16:26
  • That's what I am doing currently, but I want to have that menu only because I can't implement some options in the menu. for eg How would you implement the option to scan a file using the default anti-virus present in the user's system. – Pratik Singhal Feb 09 '14 at 16:32