PDA

Click to See Complete Forum and Search --> : Grabbing text


NeilAvent
Jul 15th, 2000, 04:40 PM
Is it possible to find out whether a textbox currently has the users focus? If so how can my application grab the text out of it.

(I am not trying to make a password sniffer, just add spellchecking facilty to programs such as notepad.)

Dim
Jul 16th, 2000, 01:32 AM
I THINK under the Text1_GotFocus sub, place a call focus onto the form and not the textbox...

hope that helped cause API isn't my area.
D!m

Jul 16th, 2000, 06:40 PM
I think he means out of other programs, like he mentioned, Notepad,
you would still have to use GetWindowText...
I think this should work....



Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Type POINTAPI
x As Long
y As Long
End Type

Private Function WinFromXY()
Dim CurPos As POINTAPI
Call GetCursorPos(CurPos)
WinFromXY = WindowFromPoint(CurPos.x, CurPos.y)
End Function



that gets the hWnd of where the cursor is, so, you could get the text by using that, I guess

NeilAvent
Jul 18th, 2000, 03:23 PM
Yep, got it working!

Many thanks for your help

Crypt
Jul 18th, 2000, 05:54 PM
I thought the code looked intresting so I attempted to use it:

Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Public Type POINTAPI
x As Long
y As Long
End Type

Public Function WinFromXY()
Dim CurPos As POINTAPI
Call GetCursorPos(CurPos)
WinFromXY = WindowFromPoint(CurPos.x, CurPos.y)
End Function


Private Sub Timer1_Timer()

Dim TextGotten As String
TextGotten = String(10000, Chr$(0))
GetWindowText WinFromXY, TextGotten, 10000
TextGotten = Left$(TextGotten, InStr(TextGotten, Chr$(0)) - 1)
Text2 = TextGotten

End Sub

it will get the caption of other windows, the text of command buttons, it will get text out of another text box if it is on my form, but it won't get it out of another text box in another program for me for some reason, I am on windows 98, what am I doing wrong?.

NeilAvent
Jul 18th, 2000, 06:11 PM
You can only grab text from controls in other applications if that control has no edit control. (according to the amazing VB programmers guide to the API by Dan Appleman)

I guess thats to stop u stealing passwords etc

Jul 18th, 2000, 10:39 PM
Try this almost like Megatron's code:

Needed: Form, Module, Textbox, and Timer

Type POINTAPI
X As Long
Y As Long
End Type

Declare Function GetCursorPos Lib "user32" _
(lpPoint As POINTAPI) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpstring As String, ByVal cch As Long) As Long
Public Declare Function WindowFromPointXY Lib "user32" Alias "WindowFromPoint" (ByVal xPoint As Long, ByVal yPoint As Long) As Long

Function GetCaption(hWnd)
hwndLength% = GetWindowTextLength(hWnd)
hwndTitle$ = String$(hwndLength%, 0)
a% = GetWindowText(hWnd, hwndTitle$, (hwndLength% + 1))
GetCaption = hwndTitle$
End Function

Private Sub Timer1_Timer()
Dim pnt As POINTAPI
MousePointer = 0
GetCursorPos pnt
yhwnd% = WindowFromPointXY(pnt.X, pnt.Y)
Text1.text = GetCaption(yhwnd%)
End Sub






[Edited by Matthew Gates on 07-18-2000 at 11:41 PM]

sogtulakk
Oct 6th, 2003, 08:25 AM
Hi All !!
I am using Crypts Code and it works. But as said before it doesnt work for other apps than my own. So.... here it goes.

I am using DDE with this 3rd party app and it is working so I suppose I could use some API to grab text from it right ?????
maybe WM_COPYDATA.... I dont know.....

Any thoughts ?!?!?!?! please ?
Thanks !!

sogtulakk
Oct 6th, 2003, 09:29 AM
Hey !
And I tell you more...
How can I grab text from a ListBox ? on another app I made.

Ideas ?!?!!
Thanks
:o)