public int ShowContextMenu(Point pos, int type = 0, Boolean shouldShow = true) {
if (type == 0) {
var newItems = this.GetNewContextMenuItems();
using (ContextMenu menu = new ContextMenu()) {
Populate(menu, CMF.EXPLORE);
int command = User32.TrackPopupMenuEx(menu.Handle, TPM.TPM_RETURNCMD, pos.X, pos.Y, m_MessageWindow.Handle, IntPtr.Zero);
if (command > 0) {
var cmdID = command - m_CmdFirst;
var verb = cmdID == 1 ? "newFolder" : cmdID == 2 ? ".lnk" : newItems[(int)cmdID - 3];
var item = Marshal.StringToHGlobalUni(verb);
this._ShellView.IsRenameNeeded = true;
InvokeCommand(item, pos, Marshal.StringToHGlobalAnsi(verb));
}
}
return 0;
} else {
using (ContextMenu menu = new ContextMenu()) {
Populate(menu, CMF.EXPLORE);
var submenuHandle = User32.GetSubMenu(menu.Handle, 0);
if (shouldShow) {
int command = User32.TrackPopupMenuEx(
submenuHandle == IntPtr.Zero ? menu.Handle : submenuHandle, TPM.TPM_RETURNCMD, pos.X, pos.Y, m_MessageWindow.Handle, IntPtr.Zero
);
if (command > 0) InvokeCommand((IntPtr)(command - m_CmdFirst), pos, (IntPtr)(command - m_CmdFirst));
}
return User32.GetMenuItemCount(submenuHandle == IntPtr.Zero ? menu.Handle : submenuHandle);
}
}
}