PDA

Click to See Complete Forum and Search --> : sendkeys - i need help!!!!!!!!1


steve7946
Dec 11th, 2000, 04:48 AM
I want to try to send some keys to a program and then get a return of any text that is there for example in word. can anyone help me? please help me

Jop
Dec 11th, 2000, 09:57 AM
You should use SendMessage for both

I wrote a quick example for use with notepad, fire it up and test the code :)

Option Explicit
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 Integer, ByVal lParam As Any) As Long
Private Const WM_GETTEXTLENGTH = &HE
Private Const WM_GETTEXT = &HD
Private Const WM_SETTEXT = &HC

Private Sub Form_Load()
Dim lNoteP&, edit&
lNoteP = FindWindow("Notepad", vbNullString)
edit = FindWindowEx(lNoteP, 0&, "Edit", "")

MsgBox GetText(edit)
SetText edit, "HEYYY IK BEN JOP"
MsgBox GetText(edit)
End Sub
Private Sub SetText(Wnd As Long, Text As String)
SendMessage Wnd, WM_SETTEXT, ByVal CLng(0), ByVal Text
End Sub
Private Function GetText(Wnd As Long)
Dim l%, Wintext$, retval&
l = SendMessage(Wnd, WM_GETTEXTLENGTH, ByVal CLng(0), ByVal CLng(0)) + 1
Wintext = Space(l)
retval = SendMessage(Wnd, WM_GETTEXT, ByVal l, ByVal Wintext)
GetText = Left(Wintext, retval)
End Function

Dec 11th, 2000, 03:04 PM
You don't need the declaration of FindWindow and FindWindowEx. Just use FindWindowEx for both.

steve7946
Dec 12th, 2000, 04:09 AM
Thanx for the help. it works fine

steve7946
Dec 21st, 2000, 04:33 AM
i ot your e-mail and i dont mind if it takes you a while to reply. thanx for the help