Recently i wanted to implement contextmenu with animation(progress) though there is no direct api or way to do it after hours of searching on the net i finally found a hack to do it by using win32 dll by P/invoking SHRecognizeGesture in aygshell.dll below pic shows the example of context menu in calendar week view
// Initialize the below code snippet in the beginning of the class
internal struct SHRGINFO
{
public int cbSize;
public IntPtr hwndClient;
public int ptDownX;
public int ptDownY;
public SHRGFLags dwFlags;
}
[Flags]
internal enum SHRGFLags
{
SHRG_RETURNCMD = 0x00000001,
SHRG_NOTIFYPARENT = 0x00000002,
SHRG_LONGDELAY = 0x00000008,
SHRG_NOANIMATION = 0x00000010,
}
[DllImport("aygshell")]
extern private static int SHRecognizeGesture(ref SHRGINFO shr);
[DllImport("coredll.dll", SetLastError = true)]
public static extern IntPtr GetActiveWindow();
//call the showContMenu() method in Mouseup or MouseDown event
public void showContMenu(int x, int y)
{
SHRGINFO shr = new SHRGINFO();
shr.cbSize = Marshal.SizeOf(typeof(SHRGINFO));
shr.dwFlags = SHRGFLags.SHRG_RETURNCMD;
shr.ptDownX = x;
shr.ptDownY = y;
shr.hwndClient = GetActiveWindow();
int ret = SHRecognizeGesture(ref shr);
if (ret == 1000)
contextMenu1.Show(this, new System.Drawing.Point(x, y));
}
internal struct SHRGINFO
{
public int cbSize;
public IntPtr hwndClient;
public int ptDownX;
public int ptDownY;
public SHRGFLags dwFlags;
}
[Flags]
internal enum SHRGFLags
{
SHRG_RETURNCMD = 0x00000001,
SHRG_NOTIFYPARENT = 0x00000002,
SHRG_LONGDELAY = 0x00000008,
SHRG_NOANIMATION = 0x00000010,
}
[DllImport("aygshell")]
extern private static int SHRecognizeGesture(ref SHRGINFO shr);
[DllImport("coredll.dll", SetLastError = true)]
public static extern IntPtr GetActiveWindow();
//call the showContMenu() method in Mouseup or MouseDown event
public void showContMenu(int x, int y)
{
SHRGINFO shr = new SHRGINFO();
shr.cbSize = Marshal.SizeOf(typeof(SHRGINFO));
shr.dwFlags = SHRGFLags.SHRG_RETURNCMD;
shr.ptDownX = x;
shr.ptDownY = y;
shr.hwndClient = GetActiveWindow();
int ret = SHRecognizeGesture(ref shr);
if (ret == 1000)
contextMenu1.Show(this, new System.Drawing.Point(x, y));
}
I have used above method in more than two views and it works awesome, if you have any problem with above snippet you can reach me through email at the bottom of the page and if there is a better way or if managed code exists share with us.
0 comments:
Post a Comment