Click here to Skip to main content
15,911,848 members
Articles / Programming Languages / C#
Article

Explorer Shell Context Menu

Rate me:
Please Sign up or sign in to vote.
4.55/5 (22 votes)
27 May 2008CPOL 124.5K   7.9K   73   33
Add the Windows Explorer Shell Context Menu to your application
Screenshot -

Introduction

I am currently working on an Advanced text editor, and I was looking for a way to implement the Window's shell context menu in my code. I came across Andreas Johansson's WebLog which provided me with the answer. He took some of the code that Steven Roebert created and placed it in one file for ease of use. His code had several errors that were easily corrected, and now I am posting the finished product.

Using the Code

The code is pretty straightforward to use:

  1. Add the ShellContextMenu.cs file to your project.
  2. Create a new instance of the ShellContextMenu class.
  3. Call the ShowContextMenu method with the proper arguments.
    1. FileInfo/DirectoryInfo Array - A list of files/directories that need the Context Menu
    2. Point - Point to Display Context Menu
C#
// Sample code

ShellContextMenu ctxMnu = new ShellContextMenu();
FileInfo[] arrFI = new FileInfo[1];
arrFI[0] = new FileInfo(this.treeMain.SelectedNode.Tag.ToString());
ctxMnu.ShowContextMenu(arrFI, this.PointToScreen(new Point(e.X, e.Y)));

History

  • 12/10/07 - Created article
  • 27/05/08 - Cleaned code a bit

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Halliburton
United States United States

Comments and Discussions

 
GeneralRe: Some tweaks (drives, files and folders, desktop items) Pin
Swatto8617-Mar-19 12:59
Swatto8617-Mar-19 12:59 
Generalnot good on win 7 Pin
so0_lanhlung228-Feb-10 17:27
so0_lanhlung228-Feb-10 17:27 
GeneralGreat! Pin
JoseMenendez27-May-08 10:19
JoseMenendez27-May-08 10:19 
GeneralGreat, but needs a bit tweaking Pin
ZeroXX24-Mar-08 12:08
ZeroXX24-Mar-08 12:08 
QuestionRe: Great, but needs a bit tweaking Pin
seguso20-Aug-09 7:48
seguso20-Aug-09 7:48 
AnswerRe: Great, but needs a bit tweaking Pin
MANSATAN29-Apr-10 11:35
MANSATAN29-Apr-10 11:35 
GeneralRe: Great, but needs a bit tweaking Pin
Colin Lamarre1-Mar-18 19:46
Colin Lamarre1-Mar-18 19:46 
GeneralShort and Sweet Pin
The_Mega_ZZTer10-Dec-07 16:39
The_Mega_ZZTer10-Dec-07 16:39 
I've been looking for articles relating to shell folder things like this, and this is part of what I'm looking for. Very simple implementation and execution that covers what I would need it to do nicely.

I was going to use a more thorough source code sample for my research into mimicking a Vista Explorer-esque interface in .NET, but your code should be a nice and simple alternative for me to look at as well! Thanks!

I was disappointed when I saw you haven't written any other articles. I'll be sure to check them out when you do. Smile | :)

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.