|
-
September 15th, 1999, 10:49 PM
#1
help with getting text from active window
I need some ones infinite wisdom. I am trying to write an app. in vb6 that first you click a button then in 5 seconds it will grab the text from the active window. Ie. iexplorer e-mail ect. then send it to notepad. I haven't been able to figure it out though. I can get the entire window as bmp. but not just the text.
-
September 16th, 1999, 01:52 AM
#2
Re: help with getting text from active window
use this code to grab the window text of the foreground window then send it to notepad via sendkeys.
option Explicit
private Declare Function GetActiveWindow Lib "user32" () as Long
private Declare Function GetForegroundWindow Lib "user32" () as Long
private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (byval hwnd as Long, byval lpString as string, byval cch as Long) as Long
private Const WM_GETTEXT = &HD
private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (byval hwnd as Long, byval wMsg as Long, byval wParam as Long, byval strParam as string) as Long
private Sub Command1_Click()
Dim hwnd as Long
hwnd = getacticewindow()
End Sub
private Sub t_Timer()
Dim hwnd as Long
hwnd = GetForegroundWindow()
If hwnd = 0 then Exit Sub
Dim strbuffer as string * 100
SendMessage hwnd, WM_GETTEXT, 100, strbuffer
MsgBox strbuffer
End Sub
tested in NT 4 with VB 6
-
September 16th, 1999, 10:15 PM
#3
Re: help with getting text from active window
Thank you so mutch for responding. I tried the code but have not been able to get it to send it. Is there any way you could send me a working modle to play with so I can see what I am doing wrong? I am still in the learning proces and need all the help I can get. I dont care where it sends it as long as it sends it some where.Thanks 
-
September 17th, 1999, 01:24 AM
#4
Re: help with getting text from active window
given my example I assume that you have managed to grab the caption of the active (foreground) window. To send the text to notepad, use code like this:
AppActivate "Unbenannt - Editor", true
SendKeys "hi"
This is based on a German NT installation. In an American version it's probably
Appactivate "untitled - Notepad"...
-
September 17th, 1999, 08:33 PM
#5
Re: help with getting text from active window
Ok thanks for the help. I now have it functional. I just have one more question. How do you captcher the client area of the active window? Thank you so mutch for the help so far.
-
September 18th, 1999, 09:43 AM
#6
Re: help with getting text from active window
Careful with that SendKeys function though. If you close the target window in the middle of sending you crash your program and VB at the same time!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|