我正尝试在我的WinForm
应用中模拟鼠标右键,如下所示:
public const int WM_RBUTTONDOWN = 0x204;
public const int WM_RBUTTONUP = 0x205;
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
public static IntPtr MakeLParam(int LoWord, int HiWord)
{
return (IntPtr)((HiWord << 16) | (LoWord & 0xffff));
}
public static void Click(int x, int y)
{
SendMessage(this.Handle, WM_RBUTTONDOWN, IntPtr.Zero, MakeLParam(x,y));
SendMessage(this.Handle, WM_RBUTTONUP, IntPtr.Zero, MakeLParam(x,y));
}
(x,y)
应用程序窗口内的坐标形成了,但是没有任何反应在这里缺少什么?
编辑:我也尝试了FindWindow(null,"Form1");
,它与Handle
提供了相同的this.Handle
..
答案 0 :(得分:-2)
为什么不使用Windows窗体中内置的事件?
使用任何控件的de MouseDown事件,例如Form:
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
}
}
MouseDown事件在按下的任何鼠标按钮中取出控件。