Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
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
Public Const BM_CLICK = &HF5
Private Sub Command2_Click() '自动在计算器中计算结果
Dim t As Long, b As String, c As String, d As String, e As String
t = FindWindow(vbNullString, "计算器")
b = FindWindowEx(t, 0, vbNullString, "1")
c = FindWindowEx(t, 0, vbNullString, "+")
d = FindWindowEx(t, 0, vbNullString, "2")
e = FindWindowEx(t, 0, vbNullString, "=")
SendMessage b, BM_CLICK, 0, 0
SendMessage c, BM_CLICK, 0, 0
SendMessage d, BM_CLICK, 0, 0
SendMessage e, BM_CLICK, 0, 0
End Sub
因为你没打开标题为“计算器”的窗口