7,763
社区成员
发帖
与我相关
我的任务
分享
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam 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 Const WM_GETTEXT = &HD
Private Function Getsum() As Long
Dim tempstr As String, strlong As Long, rtn As Long
Dim winHwnd As Long
Dim RetVal As Long
winHwnd = FindWindow(vbNullString, "计算器")
If winHwnd <> 0 Then
winHwnd1& = FindWindowEx(winHwnd&, 0&, "Edit", vbNullString)
tempstr = Space(200)
strlong = Len(tempstr)
rtn = SendMessage(winHwnd1, WM_GETTEXT, strlong + 1, tempstr)
tempstr = Trim(tempstr)
Getsum = tempstr
Else
MsgBox "计算器程序没有运行?"
End If
End Function
Private Sub Form_Load()
Dim ReturnValue, I
ReturnValue = Shell("CALC.EXE", 1) ' 运行计算器
AppActivate ReturnValue ' 激活计算器
For I = 1 To 100 ' 设置计数循环
SendKeys I & "{+}", True ' 按下按键给计算器
Debug.Print Getsum
Next I ' 将所有 I 值相加
MsgBox Getsum
End Sub
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, ByVal lParam As String) As Long
Private Const WM_GETTEXT = &HD
Private Const WM_GETTEXTLENGTH = &HE
Private Function GetResult() As String
Dim hWndParent As Long
Dim hWndChild As Long
Dim strText As String
Dim lngLen As Long
hWndParent = FindWindow("SciCalc", vbNullString)
hWndChild = FindWindowEx(hWndParent, 0, "Edit", vbNullString)
lngLen = SendMessage(hWndChild, WM_GETTEXTLENGTH, ByVal 0&, ByVal 0&)
strText = Space$(lngLen)
SendMessage hWndChild, WM_GETTEXT, ByVal lngLen, strText
If strText <> "" Then GetResult = Left(strText, lngLen - 1)
End Function
'//Timer 的 Interval设成10ms,这样每隔10ms自动取数据
Private Sub timAuto_Timer()
txtResult.Text = GetResult()
End Sub
Private Sub Form_Load()
Dim ReturnValue, I
ReturnValue = Shell("CALC.EXE", 1) ' ?s?ŽZŠí
AppActivate ReturnValue ' ŒƒŠˆ?ŽZŠí
For I = 1 To 30 ' ?’u?”z?
SendKeys I & "{+}", True ' ˆÂ‰ºˆÂ???ŽZŠí
' ?—¢œƒ?Žæ“¾?ŽZŠíiˆ½› –‹ãj?Ž¦“I?ŽŸi??j?‰ÊH
Next I ' «Š—L I ?‘Š‰Á
SendKeys "=", True ' Žæ“¾?˜a
' ?—¢œƒ?Žæ“¾?ŽZŠíiˆ½› –‹ãj?Ž¦“IÅ?iÃ?j?‰ÊH
SendKeys "^C", True ' ˆÂ ALT+F4 ???ŽZŠí
SendKeys "%{F4}", True ' ˆÂ ALT+F4 ???ŽZŠí
Text1.Text = Clipboard.GetText
End Sub