Как получить результат вычислений их программы "Калькулятор".
Киньте, плз, реально рабочий пример, а то я уже часа 2 этого добиться
не могу (( Устал, спать хочу
Private Sub Command1_Click()
Dim ReturnValue, I
ReturnValue = Shell("CALC.EXE", 1)
AppActivate ReturnValue
Clipboard.Clear
SendKeys "^{C}", True
End Sub
Можно FindWindowEx(FindWindow "Калькулятор",класс текстбокса) и послать ему WM_COPY.
][акер, это делается в C++, ну в С но не в VB...
Есть много других методов...
Интерестно, а как каклькулятор по казахски или по грузински? Я для себя сделал так, нормально работает.
Option Explicit
'*********************************для вызова калькулятора**********************
Private Declare Function ShellExecute& Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long)
'******************************************************************************
Dim ReturnValue, I
'**********************изменяем раскладку на англ.**********************
Private Declare Function LoadKeyboardLayout Lib "user32" Alias "LoadKeyboardLayoutA" (ByVal pwszKLID As String, ByVal FLAGS As Long) As Long
Private Const KLF_ACTIVATE = 1
Public Sub SetLanguage(ByVal s As String)
Select Case UCase(Left(s, 1))
Case "R"
LoadKeyboardLayout "00000419", KLF_ACTIVATE 'Имя раскладки клавиатуры - строка из 8 символов. Например, имя русской раскладки - "00000419"
Case "U"
LoadKeyboardLayout "00000422", KLF_ACTIVATE
Case "E"
LoadKeyboardLayout "00000409", KLF_ACTIVATE
End Select
End Sub
Private Sub Command1_Click()
ReturnValue = Shell("CALC.EXE", 1)
AppActivate ReturnValue
End Sub
Private Sub Command2_Click()
SetLanguage ("E"
AppActivate ReturnValue
Clipboard.Clear
SendKeys "^{C}", True
End Sub
hEdit - hWnd поля ввода в калькуляторе (проверено, работает)
lngTextLength - Длина текста в поле ввода + vbNullChar
WM_COPY - Не работает (может не так использую?)
WM_GETTEXT - Не работает (Правильно ли lParam указываю?)
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 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 Const WM_GETTEXT = &HD
Private Const WM_GETTEXTLENGTH = &HE
Private Sub Form_Load()
Dim l As Long, ret As Long, hwnd As Long
hwnd = FindWindow(ByVal vbNullString, "Калькулятор"
hwnd = FindWindowEx(hwnd, ByVal 0, "Edit", vbNullString)
l = SendMessage(ByVal hwnd, WM_GETTEXTLENGTH, ByVal 0&, ByVal 0&
t = Space(128)
ret = SendMessage(ByVal hwnd, WM_GETTEXT, ByVal 128, ByVal StrPtr(t))
t = StrConv(t, vbUnicode)
MsgBox t
End Sub
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 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 Const WM_GETTEXT = &HD
Private Sub Form_Load()
Dim ret As Long, hwnd As Long
hwnd = FindWindow(ByVal vbNullString, "Êàëüêóëÿòîð"
hwnd = FindWindowEx(hwnd, ByVal 0, "Edit", vbNullString)
t = Space(128)
ret = SendMessage(ByVal hwnd, WM_GETTEXT, ByVal 128, ByVal StrPtr(t))
t = StrConv(t, vbUnicode)
MsgBox t
End Sub