SendMessage发送鼠标单击事件

来源:百度知道 编辑:UC知道 时间:2024/07/02 11:02:08
我想向一个网页的某一位置发送一个鼠标单击信息,就是想用程序来按网页,我找过很多资料,都只能按到按钮,但我想是按到一个位置(位置上可能是图片,文字,或超级链接),有什么方法?
这段是我写的,可是不行:
g_WindowHwnd = FindWindow(vbNullString, "XXX - Windows Internet Explorer")

hWnd1 = g_WindowHwnd

Dim x As Integer, y As Integer, res As Long

x = Int(Text1.Text)
y = Int(Text2.Text)

Dim r1, r2 As Long

res = (y * &H10000) + x
r1 = SendMessage(hWnd1, WM_LBUTTONDOWN, MK_LBUTTON, ByVal res)
r2 = SendMessage(hWnd1, WM_LBUTTONUP, MK_LBUTTON, ByVal res)
(句柄没问题)

最后100分,谢谢.

One Possible Answer:

Change SendMessage into mouse_event
{
Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)

Call mouse_event(&H2, 0, 0, 0, 0)
Call mouse_event(&H4, 0, 0, 0, 0)
}

你可以写个程序操作鼠标啊

你很厉害。

c#的代码:

[DllImport("user32", EntryPoint = "SetCursorPos")]
public extern static void SetCursorPos(int x, int y);

[DllImport("user32", EntryPoint = "mouse_event")]
public extern static void Mouse_Event(int dwFlags, int dx, int dy, int dwData, IntPtr dwExtraInfo);

public enum MouseEventFlags
{
LeftDown = 0x0002,
LeftUp = 0x0004,
Absolute = 0x8000
}
//int x ,y为横坐标与纵坐标
public void MouseMoveClick(int x, int y)
{
SetCursorPos