-
this should get the text from a user has typed into ANY window:
Code:
'module1:
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public 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
Public Declare Function SendMessageLong& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
Public Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Public Const WM_GETTEXT = &HD
Public Const WM_GETTEXTLENGTH = &HE
'form1:
'general
Private Declare Function GetForegroundWindow Lib "user32" () 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
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
'end general
Private Sub Timer1_Timer()
Dim aimimessage As Long, wndateclass As Long, ateclass As Long
aimimessage = FindWindow(vbNullString, GetActiveWindowTitle(True))
wndateclass = FindWindowEx(aimimessage, 0&, "wndate32class", vbNullString)
ateclass = FindWindowEx(wndateclass, 0&, "ate32class", vbNullString)
Dim TheText As String, TL As Long
TL = SendMessageLong(ateclass, WM_GETTEXTLENGTH, 0&, 0&)
TheText = String(TL + 1, " ")
Call SendMessageByString(ateclass, WM_GETTEXT, TL + 1, TheText)
TheText = Left(TheText, TL)
Text2.Text = TheText
End Sub
but it only works with aol instant messenger.
what am i doing wrong????
-
That's because all it does is find what's written in the top text box in aim. Nothing else.
Code:
Private Sub Timer1_Timer()
Dim aimimessage As Long, wndateclass As Long, ateclass As Long
aimimessage = FindWindow(vbNullString, GetActiveWindowTitle(True))
wndateclass = FindWindowEx(aimimessage, 0&, "wndate32class", vbNullString) 'aim window
ateclass = FindWindowEx(wndateclass, 0&, "ate32class", vbNullString) 'aim top textbox
Dim TheText As String, TL As Long
TL = SendMessageLong(ateclass, WM_GETTEXTLENGTH, 0&, 0&
TheText = String(TL + 1, " ")
Call SendMessageByString(ateclass, WM_GETTEXT, TL + 1, TheText) 'aim text box
TheText = Left(TheText, TL)
Text2.Text = TheText
End Sub
wndate32class and the ateclass variables contain aim's classes.