|
Yes, with minor changes we can make it work in WinUI 3. Thanks for this class. Wish you the best!
|
|
|
|
|
Can you share the WinUI3 version?
|
|
|
|
|
There are many files, how to share?
|
|
|
|
|
|
Thanks. On your request I made a github repo - GitHub - gautambjain/WinUI-ShellContextMenu[^]
It is not a project. But just a group of files. It should work with slight tweaking.
Please don't ask any technical questions here. Request you to resolve general compilatione error yourselves.
|
|
|
|
|
Hi @Gautam-Jain
Don't worry, I won't bother you, I understand that you are sharing as is.
🙏Thank you very much for sharing your work and for your prompt response.
Kind regards,
Claudio Salvio
|
|
|
|
|
Thanks author to provide this excellent sample code.
But I encountered an issue is about "Open wtih" submenu.
For example, I want to open a jpg image by clicking Paint/Photos in Open with submenu, however, after I clicked any apps in submenu, there was nothing happend.
But the item "Choose another app" and "Search the Microsoft Store" in Open with submenu can be executed successfully.
By the way, all items in "Send to" submenu can be executed successfully either.
Does anyboy know the reason or have solution?
My development environment is .NET Framewokr 4.7.2 on Windows10 2004 version.
|
|
|
|
|
|
baconYao wrote: By the way, [not] all items in "Send to" submenu can be executed successfully either.
The issue of non-working "Send to" menu is fixed for me by the code change outlined in the link here.
Send to" menu visible but doesn't execute.[^]
Maybe it will help with other issues too.
modified 23-Jan-22 6:08am.
|
|
|
|
|
How can I send multiple files?
|
|
|
|
|
The input parameter is an array, you can put multiple files
ShellContextMenu ctxMnu = new ShellContextMenu();
FileInfo[] arrFI = new FileInfo[2];
arrFI[0] = new FileInfo(@"c:\cmd1.txt");
arrFI[1] = new FileInfo(@"c:\cmd2.txt");
ctxMnu.ShowContextMenu(arrFI, System.Windows.Forms.Cursor.Position);
|
|
|
|
|
If I use it for moving files in my projects, UI is blocked for the length of the operation.
|
|
|
|
|
This does not open ShellContextMenu,
arrFI[0] = new FileInfo(@"c:\");
ShellContextMenu menu = new ShellContextMenu();
|
|
|
|
|
Thanks a lot ,I've been searching for this like forever !!!
|
|
|
|
|
Method ShellContextMenu.ShowContextMenu first calls User32.dll DestroyMenu then calls IContextMenu.InvokeCommand, using the menu id of the previous destroyed menu.
Changed the order of calls, then it worked.
private void ShowContextMenu(Point pointScreen)
{
...
uint nSelected = TrackPopupMenuEx(
pMenu,
TPM.RETURNCMD,
pointScreen.X,
pointScreen.Y,
this.Handle,
IntPtr.Zero);
if (nSelected != 0)
{
InvokeCommand(_oContextMenu, nSelected, _strParentFolder, pointScreen);
}
DestroyMenu(pMenu);
pMenu = IntPtr.Zero;
...
}
ShellContextMenu.InvokeContextMenuDefault does it in the right order.
|
|
|
|
|
This is a bug in author's code. I don't know how to fix it, but founded other code module/class for showing Explorer's context menu: Gong Solutions Shell Library. You should see source code of this project. It is really work!
|
|
|
|
|
This works. Thanks a lot )
|
|
|
|
|
Could you please tell me how can I add one more personal option to the context menu?
I want to have smthng like "Add to..." and when the users click on it, i want to show a form created from me in the same solution... But I want to keep the rest of the shell menu..
Thank you in advance...
|
|
|
|
|
Paste this code after
pMenu = CreatePopupMenu();
int nResult = _oContextMenu.QueryContextMenu(
pMenu,
0,
CMD_FIRST,
CMD_LAST,
CMF.EXPLORE |
CMF.NORMAL |
((Control.ModifierKeys & Keys.Shift) != 0 ? CMF.EXTENDEDVERBS : 0)); in void ShowContextMenu(Point pointScreen) (ShellContextMenu.cs):
MENUITEMINFO mii = new MENUITEMINFO();
mii.cbSize = Marshal.SizeOf(mii);
mii.fMask = MIIM.STRING | MIIM.ID;
mii.fState = MFS.DEFAULT;
mii.fType = MFT.BYCOMMAND;
mii.wID = 500;
mii.dwItemData = IntPtr.Zero;
mii.dwTypeData = "Your_Item_Name";
InsertMenuItem(pMenu, (uint)(GetMenuItemCount(pMenu) + 1), true, ref mii);
You'll need API-functions' declaration:
[DllImport("user32",
SetLastError = true,
CharSet = CharSet.Auto)]
private static extern bool InsertMenuItem(
IntPtr hMenu,
uint uItem,
bool fByPosition,
ref MENUITEMINFO lpmii);
[DllImport("user32.dll")]
private static extern int GetMenuItemCount(IntPtr hMenu);
How to handle clicking your item:
uint nSelected = TrackPopupMenuEx(
pMenu,
TPM.RETURNCMD,
pointScreen.X,
pointScreen.Y,
this.Handle,
IntPtr.Zero);
DestroyMenu(pMenu);
pMenu = IntPtr.Zero;
if (nSelected != 0)
{
if (nSelected == 500)
else
InvokeCommand(_oContextMenu, nSelected, _strParentFolder, pointScreen);
}
modified 23-Jul-12 6:06am.
|
|
|
|
|
I have been playing a bit with the code but can't quite figure out how to place "my menu" items before / or on top of the explorer one? I figure it has something to do with the InsertMenuItem method? No matter what I set "uint" to be,
in example set to: (uint)(GetMenuItemCount(pMenu) + 1)
it still ends up last.
Could you maybe help me? I would be very grateful
|
|
|
|
|
Does not work correctly on Windows Server 2008 64 bit or Win7 64 bit (I suspect the same with Vista 64 bit)
Try bringing up the context menu a few times (right clicking a file) it works the first few times then falls over.
I can't get any useful debug information from it, all I know is its memory access violation.
Can anyone else test and try confirm, I am unable to find a working .Net Explorer Context menu that works under 64 bit.
modified on Saturday, June 19, 2010 9:07 AM
|
|
|
|
|
For 64bit there is an unhandled overflow exception in WndProc which crashes the app.
Solution see http://www.codeproject.com/Messages/3541887/Re-Does-not-work-on-64-bit.aspx[^]
public static uint HiWord(IntPtr ptr)
{
uint param32 = (uint)(ptr.ToInt64() & 0xffffffffL);
if ((param32 & 0x80000000) == 0x80000000)
return (param32 >> 16);
else
return (param32 >> 16) & 0xffff;
}
and
public static uint LoWord(IntPtr ptr)
{
uint param32 = (uint)(ptr.ToInt64() & 0xffffffffL);
return (param32 & 0xffff);
}
|
|
|
|
|
I had same problem, but I changed
public static uint HiWord(IntPtr ptr)
to
public static long HiWord(IntPtr ptr)
And same for the LoWord function too
And its working perfectly
|
|
|
|
|
Excellent work, however i had to modify it for my evil purposes, the GetPIDLs overloads for DirectoryInfo and FileInfo were unnecessary and it made it not possible to get the menu of files and folders at the same time, i modified it to take string[] yet the drives menus where non functional so i added a check to GetParentFolder for drive paths to have parent folder "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" which is "My Computer"'s guid, and for desktop items like "My computer, My Documents, Desktop" i added an overload to ShowContextMenu and GetPIDLs that takes CSIDL that gets the PIDLs using SHGetSpecialFolderLocation, the rest of the CSIDL are quite useless so i just ignored them.
|
|
|
|
|
@mansatan
sorry, I speak English so badly that C#
would be nice if you give us the changes to uses directories and files
thank you in advance
(and thank you google for the translation,
which should not be great but better than this I could do)
@+
|
|
|
|