vb中如何用代码起到与鼠标点击同样的效果
我想用VB代码来“点击”控件。不用鼠标,用代码代替。如果有人会的话顺便看看能不能用VB代码来“”点击电脑其他软件的某个按钮。那种用模板的就不用来了,我不想用模板,就用代码...
我想用VB代码来“点击”控件。不用鼠标,用代码代替。如果有人会的话顺便看看能不能用VB代码来“”点击电脑其他软件的某个按钮。那种用模板的就不用来了,我不想用模板,就用代码。谢谢各位
展开
2个回答
展开全部
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal Hwnd1 As Long, ByVal Hwnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Sub Form_Load()
Shell "calc.exe", vbNormalNoFocus
End Sub
Private Sub Command1_Click()
Dim Hwnd1 As Long
Dim Hwnd2 As Long
Hwnd1 = FindWindow("SciCalc", "计算器")
Hwnd2 = FindWindowEx(Hwnd1, 0, "Button", "1")
SendMessage Hwnd2, WM_LBUTTONDOWN, ByVal 0&, ByVal 0&
SendMessage Hwnd2, WM_LBUTTONUP, ByVal 0&, ByVal 0&
End Sub
Private Const WM_LBUTTONUP = &H202
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal Hwnd1 As Long, ByVal Hwnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Sub Form_Load()
Shell "calc.exe", vbNormalNoFocus
End Sub
Private Sub Command1_Click()
Dim Hwnd1 As Long
Dim Hwnd2 As Long
Hwnd1 = FindWindow("SciCalc", "计算器")
Hwnd2 = FindWindowEx(Hwnd1, 0, "Button", "1")
SendMessage Hwnd2, WM_LBUTTONDOWN, ByVal 0&, ByVal 0&
SendMessage Hwnd2, WM_LBUTTONUP, ByVal 0&, ByVal 0&
End Sub
追问
你能不能写点备注在上面啊,看不懂
追答
看不懂慢慢学
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询