473,388 Members | 1,298 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Shell Extension in C#

Hi, i'm writing a shell extension in c# that will add two menu's to the
right-click menu of explorer if any file is selected, i.e. it's
registered in the * section of Classes in the registry.

Here is the problem. If i select one file and use the standard OPEN
context menu, for a .txt file let's say, all is well, but if i select
two or more files and use the standard OPEN context menu it seems to
want to run through the code snippet for MY created menus. Here is the
code in question for my created menus:

int IContextMenu.QueryContextMenu(uint hmenu,uint iMenu, int
idCmdFirst,int idCmdLast,uint uFlags)
{
// The first id to use (should be 1)
int id = 1;
if ((uFlags & 0xf) == 0 || (uFlags & (uint)CMF.CMF_EXPLORE) !=
0)
{
// Create a new Menu Item to add to the context menu
MENUITEMINFO mii = new MENUITEMINFO();
mii.cbSize = 48;
mii.fMask = (uint)MIIM.ID | (uint)MIIM.TYPE |
(uint)MIIM.STATE;
mii.wID = idCmdFirst + id;
mii.fType = (uint)MF.STRING;
mii.dwTypeData = "Send file(s) to CheapFTP member(s)";
mii.fState = (uint)MF.ENABLED;
// Add it to the item
DllImports.InsertMenuItem(hmenu, (uint)2, 1, ref mii);

id = 2;
// Create a new Menu Item to add to the context menu
MENUITEMINFO miii = new MENUITEMINFO();
miii.cbSize = 48;
miii.fMask = (uint)MIIM.ID | (uint)MIIM.TYPE |
(uint)MIIM.STATE;
miii.wID = idCmdFirst + id;
miii.fType = (uint)MF.STRING;
miii.dwTypeData = "Quick Send file(s) to CheapFTP preferred
member(s)";
miii.fState = (uint)MF.ENABLED;
// Add it to the item
DllImports.InsertMenuItem(hmenu, (uint)2, 1, ref miii);

id = 3;
// Create a seperator
MENUITEMINFO sep = new MENUITEMINFO();
sep.cbSize = 48;
sep.fMask = (uint)MIIM.TYPE;
sep.wID = idCmdFirst + id;
sep.fType = (uint)MF.SEPARATOR;
// Add it to the seperator to the context menu
DllImports.InsertMenuItem(hmenu, (uint)2, 1, ref sep);
}
// Return the number of items added
return id;
}
void IContextMenu.InvokeCommand(IntPtr pici)
{
try
{
//fileList
StringBuilder fileList = new StringBuilder();
StringBuilder sb = new StringBuilder(1024);
uint i = 0;
//Get number of files
uint uNumFiles = 0;
uNumFiles = DllImports.DragQueryFile(m_hDrop, 0xFFFFFFFF, null,
0);
//make file name
while (i < uNumFiles)
{
DllImports.DragQueryFile(m_hDrop, i, sb, sb.Capacity + 1);
fileList.Append(sb + ",");
i++;
}
// Determine which of the context menus was clicked
Type t = Type.GetType("ShellExt.INVOKECOMMANDINFO");
INVOKECOMMANDINFO ici;
ici = (INVOKECOMMANDINFO)Marshal.PtrToStructure(pici, t);
switch (ici.verb - 1)
{
case 0:
// Send File(s) to CheapFTP client
Process.Start("c:\\CheapFTP.exe", "\"" +
fileList.ToString() + "\"");
break;
case 1:
// Send File(s) to CheapFTP client with QuickSend Flag
enabled
fileList.Append("QuickSend,");
Process.Start("c:\\CheapFTP.exe", "\"" +
fileList.ToString() + "\"");
break;
default:
MessageBox.Show("Shell Error");
break;
}
}
catch(Exception e)
{
System.Windows.Forms.MessageBox.Show("Error : " + e.ToString(),

"Error in CheapFTP installation. Please re-install.");
}
}

If i use my created menus everything works as planned, and so do all
the other menus i have installed, i.e. WinRar and NOD32 Antivirus. If i
select one file and use the standard OPEN menu it works correctly.
Only when i select multiple files and select OPEN, i notice that it
runs through the code for MY menu, i.e. the MessageBox "Shell Error"
will pop up as often as the number of files i have selected. It seems
that if one file is selected and it has an OPEN static command in the
registry "notepad.exe %1" it runs that, but if i have two selected does
it run a different command in the registry?

It is my understanding that if i select the OPEN menu it should not
even run through my
code at all. If I uninstall my menu, selecting multiple files+OPEN
works properly even with the WinRar context menus installed. The only
difference i can see is that WinRAR's is a .dll probably made in
unhandled c++ where mine is made in c# .NET.

ideas/suggestions? TIA,lushdog

Mar 24 '06 #1
0 4059

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Tiziano Bettio | last post by:
Hi there I'm looking for a simple solution of a win32 shell extension (virtual drive). It should make available a new drive with letter, which will be read-only. Instead of a network drive or...
2
by: Sin | last post by:
Hello everyone, I'm totally stumped at how little info I can find in MSDN or on the web concerning this. It's almost as if only microsoft personel hold the key to these secrets or something!!! ...
4
by: yxq | last post by:
Hello Can anyone tell me Context Menu shell extension? It is better that provide some samples or links. Thanks
1
by: Luhar | last post by:
Greetings, I'd like to write a shell extension so that a user can right-click on any file, regardless of its extension, and my extension will appear as one of the choices on the context menu...
5
by: gjuro kladaric | last post by:
it was not possible to make a shell extension from within VB2003, I believe has anything changed since then, can I (easily) write a VB code that would function as a shell extension thank you ...
6
by: Pieter | last post by:
Hi, I'm trying to use the Edanmo Shell Extension Library (http://www.mvps.org/emorcillo/en/code/shell/shellextensions.shtml) to make a Context Menu in the Windows Explorer with VB.NET 2005. It...
1
by: James Maeding | last post by:
I was looking for the easiest way to add an item to explorer's right click menus, and I found what looks to be a goldmine. There is a vb.net project available on:...
3
by: Shafiq | last post by:
Hi, I am trying to insert a new toolbar button to the windows explorer menu. I an able to locate the correct ToolbarWindow32, and inserted a button using the code snippet shown below. However...
2
by: Jeff Gaines | last post by:
I am in the process of upgrading to XP 64. VS2008 is running fine but one of my apps, which adds functionality to the Explorer context menu, just won't work under XP 64. Googling resulted in my...
5
by: AGP | last post by:
I have been looking far and wide for an easy to implement shell extension. My needs are basic...for two file extensions .YYY and .ZZZ I would like the context menu in explorer to simply show my app...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.