Hi,
I am working on a contextmenu shell extension, which works quite fine
as long as I implement the IContextMenu interface.
However, as I need to include an owner-drawn menu item, I would like
to switch to IContextMenu3 (as I read that IContextMenu2 is not called
by the shell). When I do this, interestingly
IContextMenu2::HandleMenuMsg is called instead of
IContextMenu3::HandleMenuMsg2 and the umsg parameter contains some
strange (seemingly random) number. HandleMenuMsg gets called three
times.
Furthermore, as I return a value of 0 (S_OK) after (not) handling
HandleMenuMsg (as I do not know what the umsg means), I get a null
pointer exception error (reference to memory block 0x...000c).
Below you will find an extract of the sources. I have includes the
QueryContextMenu method so that you can take a look at the
initialization of the menu. Of course I have only abbreviated
HandleMenuMsg and HandleMenuMsg2 to keep the post small. ;)
Any "Helpers"-functions you might find are only DLLImports of
Win32-functions of the same name.
Hope someone can help,
Ron
namespace ShellExt
{
[ComImport(), InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
GuidAttribute("000214e4-0000-0000-c000-000000000046")]
public interface IContextMenu
{
[PreserveSig()]
int QueryContextMenu(uint hmenu, uint iMenu, int idCmdFirst, int
idCmdLast, uint uFlags);
[PreserveSig()]
void InvokeCommand (IntPtr pici);
[PreserveSig()]
void GetCommandString(int idcmd, uint uflags, int reserved,
StringBuilder commandstring, int cch);
}
[ComImport(), InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
GuidAttribute("000214e4-0000-0000-c000-000000000046")]
public interface IContextMenu2 : IContextMenu
{
[PreserveSig]
int HandleMenuMsg( uint uMsg, IntPtr wParam, IntPtr lParam );
}
[ComImport(), InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
GuidAttribute("BCFCE0A0-EC17-11D0-8D10-00A0C90F2719")]
public interface IContextMenu3 : IContextMenu2
{
[PreserveSig()]
int HandleMenuMsg2( uint uMsg, IntPtr wParam, IntPtr lParam, IntPtr
plResult );
}
public class AABBContextMenuExtension : IShellExtInit, IContextMenu3,
IPersistFile, IQueryInfo
{
....
int IContextMenu.QueryContextMenu(uint hMenu, uint iMenu, int
idCmdFirst, int idCmdLast, uint uFlags)
{
int nID = 0;
if ( (uFlags & 0xf) == 0 || (uFlags & (uint)CMF.CMF_EXPLORE) != 0)
{
MENUITEMINFO mii = new MENUITEMINFO();
mii.cbSize = 48;
mii.fMask = (uint) MIIM.TYPE | (uint)MIIM.STATE;
mii.fType = (uint) MF.STRING;
mii.dwTypeData = "myMenu";
mii.fState = (uint) MF.ENABLED;
Helpers.InsertMenuItem(hMenu, (uint)(iMenu + ++nID), 1, ref mii);
}
return nID;
}
int IContextMenu3.HandleMenuMsg2(uint uMsg, IntPtr wParam, IntPtr
lParam, IntPtr plResult )
{
return (0);
}
int IContextMenu2.HandleMenuMsg(uint uMsg, IntPtr wParam, IntPtr
lParam)
{
return (0);
}