| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 820 人关注过本帖
标题:sendmessage模拟鼠标为什么显示溢出错误6?求神们帮助
取消只看楼主 加入收藏
ysyol
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2017-4-1
收藏
 问题点数:0 回复次数:0 
sendmessage模拟鼠标为什么显示溢出错误6?求神们帮助
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, ByVal lpBaseAddress As Any, ByVal lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
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)
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal IParam As Long) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Object) As Integer
Private Declare Function GetLastError Lib "kernel32" () As Long
Const PROCESS_ALL_ACCESS = &H1F0FFF '消息常量,系统内部约定一个值,代表要实现某一功能的代号,一般固定不变为&H1F0FFF
Const MOUSEEVENTF_MOVE = &H1 '移动鼠标
Const MOUSEEVENTF_LEFTDOWN = &H2 '模拟鼠标左键按下
Const MOUSEEVENTF_LEFTUP = &H4 '模拟鼠标左键抬起
Const MOUSEEVENTF_RIGHTDOWN = &H8 '模拟鼠标右键按下
Const MOUSEEVENTF_RIGHTUP = &H10 '模拟鼠标右键抬起
Const MOUSEEVENTF_MIDDLEDOWN = &H20 '模拟鼠标中键按下
Const MOUSEEVENTF_MIDDLEUP = &H40 '模拟鼠标中键抬起
Const MOUSEEVENTF_ABSOLUTE = &H8000 '标示是否采用绝对坐标
Const WM_MOUSEFIRST As Integer = &H200 '移动鼠标时发生
Const WM_MOUSEMOVE As Integer = &H200        '移动鼠标时发生,同WM_MOUSEFIRST
Const WM_LBUTTONDOWN As Integer = &H201      '按下鼠标左键
Const WM_LBUTTONUP As Integer = &H202        '释放鼠标左键
Const WM_LBUTTONDBLCLK As Integer = &H203    '双击鼠标左键
Const WM_RBUTTONDOWN As Integer = &H204      '按下鼠标右键
Const WM_RBUTTONUP As Integer = &H205        '释放鼠标右键
Const WM_RBUTTONDBLCLK As Integer = &H206    '双击鼠标右键
Const WM_MBUTTONDOWN As Integer = &H207      '按下鼠标中键
Const WM_MBUTTONUP As Integer = &H208        '释放鼠标中键
Const WM_MBUTTONDBLCLK As Integer = &H209    '双击鼠标中键
Const WM_MOUSEWHEEL As Integer = &H20A       '当鼠标轮子转动时发送此消息个当前有焦点的控件
'Const MK_LBUTTON As Integer = &H1            '鼠标左键按下
' 声明一些需要的变量
Dim hHwnd As Long  ' 储存 FindWindow 函数返回的句柄
Dim pid As Long ' 储存进程标识符( Process Id )
Dim hProcess As Long ' 储存进程句柄
'Dim MEvent As Long
Dim XPoint As Long, YPoint As Long, SMIndex As Long
Dim pt As Long

Private Sub Command1_Click()
hHwnd = FindWindow(vbNullString, "无标题 - 画图") ' 首先取得目标窗口的句柄
If (hHwnd = 0) Then
MsgBox "Window not found!"
Exit Sub
End If
GetWindowThreadProcessId hHwnd, pid ' 取得进程标识符
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, pid) ' 使用进程标识符取得进程句柄
Test
If (hProcess = 0) Then
MsgBox "Couldn't get a process handle!"
Exit Sub
End If
XPoint = 100: YPoint = 200
SendMessage hHwnd, WM_LBUTTONDOWN, 0, 0& '在数字后面加“&”隐式声明Long 数据类型
CloseHandle hProcess
End Sub
Public Function MAKELPARAM(ByVal l As Integer, ByVal h As Integer) As Integer
MAKELPARAM = 0 ' l + h * 65536
End Function
Private Sub Test()
Text1.Text = "hHWND" & hwnd & ",pid" & pid & ",hProcess" & hProcess & "Er" & GetLastError
Command1.Caption = "Exit"
End Sub

[此贴子已经被作者于2017-4-17 17:36编辑过]

2017-04-17 17:35
快速回复:sendmessage模拟鼠标为什么显示溢出错误6?求神们帮助
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017062 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved