winform用SendMessage怎么发送一个鼠标消息,指定鼠标在某个窗口(32,32)处按下,指定坐标在sendmess 50
2个回答
展开全部
你先要用FindWindow(string lpClassName,string lpWindowName)获取该窗口的句柄
IntPtr hwnd QQ= FindWindow(null,"QQ2011");这样就能获取QQ登录窗口的句柄
然后再使用SendMessage(IntPtr hwnd,int msg,IntPtr wParam,IntPtr lParam)
向该窗口发送消息
SendMessage(hwndQQ,WM_LBUTTONDBLCLK ,MK_LBUTTON,32 * 65535 + 32);
public const int WM_LBUTTONDBLCLK = 515
public const int MK_LBUTTON = 1;
(在电脑中搜索winuser.h,这个文件中包含消息值)
这个消息是左键单击消息
lParam的低16位填鼠标位置的x值,高16位填y值
要先声明
[DllImport( "user32.dll ", CharSet=CharSet.Auto)]
public static extern int SendMessage(int hWnd, int msg, IntPtr wParam, IntPtr lparam);
[DllImport( "user32.dll ", CharSet=CharSet.Auto)]
public static extern IntPtr FindWindow(string lpClassName,string lpWindowName);
IntPtr hwnd QQ= FindWindow(null,"QQ2011");这样就能获取QQ登录窗口的句柄
然后再使用SendMessage(IntPtr hwnd,int msg,IntPtr wParam,IntPtr lParam)
向该窗口发送消息
SendMessage(hwndQQ,WM_LBUTTONDBLCLK ,MK_LBUTTON,32 * 65535 + 32);
public const int WM_LBUTTONDBLCLK = 515
public const int MK_LBUTTON = 1;
(在电脑中搜索winuser.h,这个文件中包含消息值)
这个消息是左键单击消息
lParam的低16位填鼠标位置的x值,高16位填y值
要先声明
[DllImport( "user32.dll ", CharSet=CharSet.Auto)]
public static extern int SendMessage(int hWnd, int msg, IntPtr wParam, IntPtr lparam);
[DllImport( "user32.dll ", CharSet=CharSet.Auto)]
public static extern IntPtr FindWindow(string lpClassName,string lpWindowName);
更多追问追答
追问
现在就是用这种方法,可是 IntPtr lparam这个参数怎么设置。只知道x,y
追答
IntPtr lParam = (IntPtr)(y * 65535 + x);
展开全部
/// <summary>
/// 发送鼠标左键单击消息
/// </summary>
/// <param name="x">X坐标</param>
/// <param name="y">Y坐标</param>
public static void EsSendKey_MouseLeftClick(int x, int y)
{
int xx = Screen.PrimaryScreen.Bounds.Width;
int yy = Screen.PrimaryScreen.Bounds.Height;
mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE | MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, x * 65536 / xx, y * 65536 / yy, 0, 0);
}
/// <summary>
/// 鼠标事件
/// </summary>
[DllImport("user32.dll")]
private static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
没用过SendMessage 我自己写的
/// 发送鼠标左键单击消息
/// </summary>
/// <param name="x">X坐标</param>
/// <param name="y">Y坐标</param>
public static void EsSendKey_MouseLeftClick(int x, int y)
{
int xx = Screen.PrimaryScreen.Bounds.Width;
int yy = Screen.PrimaryScreen.Bounds.Height;
mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE | MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, x * 65536 / xx, y * 65536 / yy, 0, 0);
}
/// <summary>
/// 鼠标事件
/// </summary>
[DllImport("user32.dll")]
private static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
没用过SendMessage 我自己写的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询