本附件用excel自带的VBA,调用windowsAPI
用 mouse_event 实现了对前台程序发送按键和鼠标动作
用 sendmessege 实现了对后台程序发送鼠标动作
做法是 先人手打开画图程序,切换回excel点击按钮
就可以在画图程序画出一个正方形图案
对想要学习 如何 sendmessage 到后台程序的同学很有帮助。
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wparam As Long, ByVal lparam As Long) As Long
Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Public 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)