How to pupup mainmenu without clicking it

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
is it possible to make mainmenu to show without being clicked? (i would like
to show menu when specific key is pressed)
Thanks for any advice
 
Hi Daniel,
i tryed to write that method, but it throws MissingMethodException when
mouse_event is called... When i add 'mouse_event( 0x8002, mx , my, 0, 0)' to
watches in VisualStudio, it's evaluated with no errors.

[DllImport("coredll.dll")]
private static extern void mouse_event( uint flags, uint dx, uint dy, uint
dwData, uint extraInfo);

public static void MouseClick( int x, int y, System.Windows.Forms.Form sender)
{
System.Drawing.Point p = sender.PointToScreen( new System.Drawing.Point(
x,y));
int ma = 65535 / Screen.PrimaryScreen.Bounds.Width;
int mb = 65535 / Screen.PrimaryScreen.Bounds.Height;
uint mx = (uint)(ma * p.X);
uint my = (uint)(mb * p.Y);
mouse_event( 0x8002, mx , my, 0, 0);
mouse_event( 0x8004, mx , my, 0, 0);
}
 
What device are you running this on? Do other coredll pinvokes work?

I tried your code in the VS PPC emulator (no SPs) and it works fine.
1. Drop your code in a form
2. Add a button to the form
3. To the maimenu add a menuitem
4. Add a button and in there put this code:
private void button1_Click(object sender, System.EventArgs e) {
MouseClick(this.Left + 5, this.Height + 5, this);
}

5. Run

Does it work?

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


Michal Rizek said:
Hi Daniel,
i tryed to write that method, but it throws MissingMethodException when
mouse_event is called... When i add 'mouse_event( 0x8002, mx , my, 0, 0)'
to
watches in VisualStudio, it's evaluated with no errors.

[DllImport("coredll.dll")]
private static extern void mouse_event( uint flags, uint dx, uint dy, uint
dwData, uint extraInfo);

public static void MouseClick( int x, int y, System.Windows.Forms.Form
sender)
{
System.Drawing.Point p = sender.PointToScreen( new System.Drawing.Point(
x,y));
int ma = 65535 / Screen.PrimaryScreen.Bounds.Width;
int mb = 65535 / Screen.PrimaryScreen.Bounds.Height;
uint mx = (uint)(ma * p.X);
uint my = (uint)(mb * p.Y);
mouse_event( 0x8002, mx , my, 0, 0);
mouse_event( 0x8004, mx , my, 0, 0);
}


Daniel Moth said:
Send it a mouse_event:
http://www.danielmoth.com/Blog/2004/11/mouseevent.html

or explicitly show the ContextMenu at the right position:
http://www.danielmoth.com/Blog/2004/11/contextmenushow.html

Cheers
Daniel
 
Back
Top