|
-
Jul 22nd, 2007, 12:06 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Get Text From Window
Okay... I know this post is like WAYY old but why make a new one when this one is still here. :P
Anyways... I have never gotten it to work yet. Here is what I want to do, my sister(who is 9) likes to go into chat rooms on yahoomessenger with her friends from school when no one is around. Now we've told her not to do it and everything and she talks to random people... I was wondering if there was a way to retrieve what she and the other peoeple/person(s) type to her as well as text she types into any other window(s).
All I would actually need is a list of API(s) and how to use them to accomplish this. Thanks for your help and again sorry for bringing the dead back to life.
-
Jul 22nd, 2007, 04:36 AM
#2
Re: Getting text from window..
Usually its not a good idea to reply to old threads as it will send notifications to members that have replied to the thread if they have email subscription notification choosen. 
Post split from thread - http://vbforums.com/showthread.php?t=362205 into a new separate thread.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 22nd, 2007, 01:24 PM
#3
Hyperactive Member
Re: Get Text From Window
alot of IM's will let you directly reference them progmatically. yahoo does this. you can reference the DLL(Yahoo! Messenger TypLib) by adding it to your references within your project. then press F2 and look at the YahooMessengerLib properties and methods. im pretty sure there is a way to log text that way.
YahooMessengerLib.IIMMessage.Text seems valid. im not sure exactly how it is gonna work. you can probably look it up. maybe this will be a start in your search.
otherwise you can enum the windows every 100 millisec and do alot of work recording the window text when found
-
Jul 22nd, 2007, 02:53 PM
#4
Thread Starter
Addicted Member
Re: Get Text From Window
OK, I tried using it and I cannot figure out how to set the hwnd for it to pull the text. Every time I try to use "YahooMessengerLib.IMMesssage.Text" it returns object variable not set or something like that..
I know the ThreadID and Class Name of the Yahoo Messenger Sent Textbox but I have no clue how find out the HWND of it to use GetText API to get the text from it... Any ideas?
-
Jul 23rd, 2007, 05:17 AM
#5
Re: Get Text From Window
Post the code you are using. I dont have Yahoo IM but I can take a look at it.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 23rd, 2007, 01:42 PM
#6
Thread Starter
Addicted Member
Re: Get Text From Window
Code:
Public Function GetText(hwnd As Long) As String
Dim strtemp As String
Dim lnglength As Long
lnglength = SendMessage(hwnd, WM_GETTEXTLENGTH, 0, 0)
strtemp = Space(lnglength)
SendMessage hwnd, WM_GETTEXT, lnglength + 1, strtemp
GetText = strtemp
End Function
Private Sub Timer1_Timer()
Debug.Print GetText(FindWindow("YHTMLContainer", vbNullString))
End Sub
Is my current way of trying it, but for some reason it returns nothing. I have tried nearly every class name and window name but it all seems to return the window title and nothing else. As for the YahooMessengerTypeLib I just couldn't find a way to set the hwnd or whatever to be able to use the .IMMessage.Text...
-
Jul 23rd, 2007, 03:13 PM
#7
Re: Get Text From Window
Are you sure you are getting the correct child window handle? It sounds like you are only getting the main window handle which is why its returning the forms titlebar caption.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 23rd, 2007, 03:18 PM
#8
Addicted Member
Re: Get Text From Window
try findwindowex instead of findwindow
-
Jul 23rd, 2007, 03:32 PM
#9
Thread Starter
Addicted Member
Re: Get Text From Window
 Originally Posted by RobDog888
Are you sure you are getting the correct child window handle? It sounds like you are only getting the main window handle which is why its returning the forms titlebar caption.
How would I get the handle of a child window? Maybe that is where I am getting confused at...
How would I use FindWindowEx?
Last edited by Jaquio; Jul 23rd, 2007 at 03:36 PM.
-
Jul 23rd, 2007, 03:36 PM
#10
Re: Get Text From Window
First you get the main window handle with FindWindow then you pass that handle with FindWndowEx. That will get the first child window but the app will have a window heirarchy that you need to detect so you will drill down the window heirarchy correctly. This is why you should use MS Spy++ to determine its structure.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 23rd, 2007, 03:38 PM
#11
Thread Starter
Addicted Member
Re: Get Text From Window
So what goes into the HWND2 spot? I am confused already >.>
-
Jul 23rd, 2007, 03:59 PM
#12
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 23rd, 2007, 04:26 PM
#13
Thread Starter
Addicted Member
Re: Get Text From Window
Code:
Private Sub Timer1_Timer()
Dim lngMainHandle As Long
lngMainHandle = FindWindow("YSearchMenuWndClass", vbNullString)
Debug.Print lngMainHandle & " - " & FindWindow(vbNullString, "in_his_arms_forever2323 - bjmoreton") 'Comparing the handle values to make sure they were the same, they were
Debug.Print FindWindowEx(lngMainHandle, ByVal 0&, "YHTMLContainer", vbNullString) 'This returns 0 for some reason...
End Sub
Any ideas?
-
Jul 23rd, 2007, 04:28 PM
#14
Re: Get Text From Window
No because without knowing the window heirarchy any code is pointless.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 23rd, 2007, 04:34 PM
#15
Thread Starter
Addicted Member
Re: Get Text From Window
Where can I get MS Spy++ at?
-
Jul 23rd, 2007, 05:18 PM
#16
Re: Get Text From Window
Its a tool/utility that is included with most versions of Visual Studio. What version do you have? It may not have been installed if you didnt select the tools to install in a custom install.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 23rd, 2007, 09:28 PM
#17
Thread Starter
Addicted Member
Re: Get Text From Window
Okay, finally after hours of looking for my CD I found it and installed ALL the tools and have MS Spy++. How the heck do I use this thing? It seems REALLY confusing to me...
-
Jul 23rd, 2007, 09:34 PM
#18
Re: Get Text From Window
Click the Find Window (Ctl+F) button and then drag the window finder crosshairs toover your other programs target child window. Release and in SPy++ it will be highlighted. You will then see how the structure is derivved.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 23rd, 2007, 09:41 PM
#19
Thread Starter
Addicted Member
Re: Get Text From Window
OKay, I see... "000104DE "in_his_arms_forever2323 - bjmoreton" YSearchMenuWndClass" then it trees off into "000104E6 "" ReBarWindow32" and "000104E8 "" IMClass" and IMClass is "00010502 "" YHTMLContainer"(That is where all sent text goes) and it trees of into "00020498 "" Internet Explorer_Server"... So umm, where do I go from there?
-
Jul 23rd, 2007, 09:46 PM
#20
Re: Get Text From Window
You have to use FindWindow on the top level window of your yahoo im. Then pass the retrieved handle in a second call to the child window which is next in line to get down to your target window. Post a small screen shot of the window heirarchy.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 23rd, 2007, 10:01 PM
#21
Thread Starter
Addicted Member
-
Jul 23rd, 2007, 10:42 PM
#22
Re: Get Text From Window
Yes but I am unsure of the destination as is it the blue highlighted one?
You should start with...
lHwnd = FindWindow("YSearchMenuWndClass", vbNullstring)
lChwnd = FindWindowEx(lHwnd, 0&, "IMClass", vbNullstring)
etc.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 23rd, 2007, 11:00 PM
#23
Thread Starter
Addicted Member
Re: Get Text From Window
Okay here is what I am currently trying...
Code:
Public Function GetText(hwnd As Long) As String
Dim strtemp As String
Dim lnglength As Long
lnglength = SendMessage(hwnd, WM_GETTEXTLENGTH, 0, 0)
strtemp = Space(lnglength)
SendMessage hwnd, WM_GETTEXT, lnglength + 1, strtemp
GetText = strtemp
End Function
Private Sub Timer1_Timer()
Dim lngHWND As Long, lngCHwnd As Long, lngC2Hwnd As Long, lngC3Hwnd As Long
lngHWND = FindWindow("YSearchMenuWndClass", vbNullString) 'Returns Handle
Debug.Print "lnghwnd:" & lngHWND
Debug.Print "GT:" & GetText(lngHWND) 'Returns in_his_arms_forever2323 - bjmoreton
lngCHwnd = FindWindowEx(lngHWND, 0&, "IMClass", vbNullString) 'Returns Handle
Debug.Print "lngCHwnd:" & lngCHwnd
Debug.Print "GT:" & GetText(lngCHwnd) 'Returns Nothing
lngC2Hwnd = FindWindowEx(lngCHwnd, 0&, "YHTMLContainer", vbNullString) 'Returns Handle
Debug.Print "lngC2Hwnd:" & lngC2Hwnd
Debug.Print "GT:" & GetText(lngC2Hwnd) 'Returns Nothing
lngC3Hwnd = FindWindowEx(lngC2Hwnd, 0&, "Internet Explorer_Server", vbNullString) 'Returns Handle
Debug.Print "lngC3Hwnd:" & lngC3Hwnd
Debug.Print "GT:" & GetText(lngC3Hwnd) 'Returns Nothing
End Sub
As for the highlighted part in the blue I accidently clicked that. When I used the cross-airs to find the handle it highlighted the "Internet Explorer_Server" part in YHTMLContainer.
-
Jul 24th, 2007, 12:25 AM
#24
Re: Get Text From Window
And... are you getting the correct window handles? You will need to refresh the Spy++ window between runs of your app.
Note: some windows will not have window caption text.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 24th, 2007, 01:35 AM
#25
Thread Starter
Addicted Member
Re: Get Text From Window
 Originally Posted by RobDog888
And... are you getting the correct window handles? You will need to refresh the Spy++ window between runs of your app.
Note: some windows will not have window caption text.
I am pretty sure I am getting the correct window handles.
Code:
lnghwnd:4064884 - Value in Hex:3E0674
GT:Bj Moreton (bjmoreton) - bjmoreton
lngCHwnd:1246554 - Value in Hex:13055A
GT:
lngC2Hwnd:656898 - Value in Hex:A0602
GT:
lngC3Hwnd:853466 - Value in Hex:D05DA
GT:
And the values are the same as what Spy++ returns.
-
Jul 24th, 2007, 01:57 AM
#26
Re: Get Text From Window
Then just keep going until you get to the final window where you want to read/write to, use that final window handle to pass as the handle in the GetText/SetText etc.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 24th, 2007, 02:03 AM
#27
Thread Starter
Addicted Member
Re: Get Text From Window
 Originally Posted by RobDog888
Then just keep going until you get to the final window where you want to read/write to, use that final window handle to pass as the handle in the GetText/SetText etc.
That is the final handle... If you look at the image I posted, it goes from YSearchMenuWndClass to IMClass to YHTMLContainer and then to Internet Explorer_Server... That is the last one and for some reason I cannot get the text from the screen into the buffer. No idea why...
Edit:Look at this one, http://76.181.208.153/Yahoo1.jpg
-
Jul 24th, 2007, 02:16 AM
#28
Re: Get Text From Window
Ah thats because it appears to be a self contained ActiveX control. They dont expose the inner windows that make up the control.
What about just adding a reference to the YIM and automate it? Have you tried doing that yet?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 24th, 2007, 02:20 AM
#29
Thread Starter
Addicted Member
Re: Get Text From Window
If you mean using the YahooMessengerTypeLib? Then yes I have, I cannot find a way to set the HWND for it because it returns that object or variable is not set or something like that....
I found this post http://www.vbforums.com/showthread.php?t=357460 But the code is for VB.Net how do you change it to work for VB6?
-
Jul 24th, 2007, 02:40 AM
#30
Re: Get Text From Window
Its not too different from VB 6 since its IE automation. Its almost complete but I am not sure about the IID_IHTMLDocument declaration so I left it as "???"
This is the basis of getting the inner IE server window and getting its Document Object Model...(VB.NET).
Code:
Imports mshtml
Imports System.Text
Imports System.Runtime.InteropServices
Public Class IEDom
Declare Function ObjectFromLresult Lib "oleacc" (ByVal lResult As Int32, ByRef riid As System.Guid, ByVal wParam As Int32, ByRef ppvObject As IHTMLDocument) As Int32
Dim win32 As New Win32Functions()
Public Function IEDOMFromhWnd(ByVal hWnd As IntPtr) As IHTMLDocument
Dim IID_IHTMLDocument As System.Guid = New System.Guid("626FC520-A41E-11CF-A731-00A0C9082637")
'Dim hWndChild As Int32
Dim lRes As Int32
Dim lMsg As Int32
Dim hr As Int32
If Not hWnd.Equals(0) Then
If Not hWnd.Equals(0) Then
' Register the message
lMsg = win32.RegisterWindowMessage("WM_HTML_GETOBJECT")
'MsgBox(lMsg.ToString)
' Get the object
Call win32.SendMessageTimeout(hWnd, lMsg, 0, 0, _
win32.SMTO_ABORTIFHUNG, 1000, lRes)
If lRes Then
' Get the object from lRes
hr = ObjectFromLresult(lRes, IID_IHTMLDocument, 0, IEDOMFromhWnd)
If hr Then Throw New COMException(hr)
End If
End If
Else
MsgBox("bad hwnd!!")
End If
End Function
End Class
Now to translate it into all VB 6.
The conversions....
Code:
'In a Module....
Option Explicit
Private Declare Sub ObjectFromLresult Lib "OLEACC.dll" ( _
ByVal lResult As Long, _
ByVal riid As Long, _
ByVal wParam As Long, _
ByRef ppvObject As Any)
Private Declare Function RegisterWindowMessage Lib "user32.dll" Alias "RegisterWindowMessageA" ( _
ByVal lpString As String) As Long
Private Declare Function SendMessageTimeout Lib "user32.dll" Alias "SendMessageTimeoutA" ( _
ByVal hwnd As Long, _
ByVal msg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long, _
ByVal fuFlags As Long, _
ByVal uTimeout As Long, _
ByRef lpdwResult As Long) As Long
Private Const SMTO_ABORTIFHUNG As Long = &H2
Public Function IEDOMFromhWnd(ByVal hWnd As Long) As IHTMLDocument
Dim IID_IHTMLDocument As ???
Dim lRes As Long
Dim lMsg As Long
Dim hr As Long
If hWnd <> 0 Then
If hWnd <> 0 Then
'Register the message
lMsg = RegisterWindowMessage("WM_HTML_GETOBJECT")
SendMessageTimeout hWnd, lMsg, 0, 0, SMTO_ABORTIFHUNG, 1000, lRes
If lRes Then
'Get the object from lRes
hr = ObjectFromLresult(lRes, IID_IHTMLDocument, 0, IEDOMFromhWnd)
If hr Then MsgBox "Error"
End If
End If
Else
MsgBox("bad hwnd!!")
End If
End Function
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 24th, 2007, 02:55 AM
#31
Thread Starter
Addicted Member
Re: Get Text From Window
Visual Basic Crashes upon using this... Any idea why? I am calling the IEDOMFromhWnd with the last HWND I get(Internet Explorer_Server)...
-
Jul 24th, 2007, 02:56 AM
#32
Re: Get Text From Window
 Originally Posted by RobDog888
Its almost complete but I am not sure about the IID_IHTMLDocument declaration so I left it as "???"
It needs that final line of code converted and then its done.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 24th, 2007, 03:10 AM
#33
Thread Starter
Addicted Member
Re: Get Text From Window
But what could it possibly be declared as?
-
Jul 24th, 2007, 03:22 AM
#34
Thread Starter
Addicted Member
Re: Get Text From Window
Well I got somewhere... lol
Code:
Option Explicit
Private Declare Function ObjectFromLresult Lib "OLEACC.dll" ( _
ByVal lResult As Long, _
riid As UUID, _
ByVal wParam As Long, _
ByRef ppvObject As Any) As Long
Private Declare Function RegisterWindowMessage Lib "user32.dll" Alias "RegisterWindowMessageA" ( _
ByVal lpString As String) As Long
Private Declare Function SendMessageTimeout Lib "user32.dll" Alias "SendMessageTimeoutA" ( _
ByVal hWnd As Long, _
ByVal msg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long, _
ByVal fuFlags As Long, _
ByVal uTimeout As Long, _
ByRef lpdwResult As Long) As Long
Private Const SMTO_ABORTIFHUNG As Long = &H2
Private Type UUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type
Public Function IEDOMFromhWnd(ByVal hWnd As Long) As IHTMLDocument
'On Error Resume Next
Dim IID_IHTMLDocument As UUID
Dim lRes As Long
Dim lMsg As Long
Dim hr As Long
If hWnd <> 0 Then
If hWnd <> 0 Then
'Register the message
lMsg = RegisterWindowMessage("WM_HTML_GETOBJECT")
SendMessageTimeout hWnd, lMsg, 0, 0, SMTO_ABORTIFHUNG, 1000, lRes
If lRes Then
'Get the object from lRes
hr = ObjectFromLresult(lRes, IID_IHTMLDocument, 0, IEDOMFromhWnd)
If hr Then MsgBox "Error"
End If
End If
Else
MsgBox ("bad hwnd!!")
End If
End Function
Using it like that it returns "[object]" anyideas why? I found that fix here: http://www.rohitab.com/discuss/lofiv...hp/t25422.html
Nevermind didn't look at it fully, it now works. Hooray! lol Calling that function and using it like this worked.
Code:
Private Sub Timer1_Timer()
Dim lngHWND As Long, lngCHwnd As Long, lngC2Hwnd As Long, lngC3Hwnd As Long
Dim doc As New HTMLDocument
lngHWND = FindWindow("YSearchMenuWndClass", vbNullString) 'Returns Handle
Debug.Print "lnghwnd:" & lngHWND
Debug.Print "GT:" & GetText(lngHWND) 'Returns in_his_arms_forever2323 - bjmoreton
lngCHwnd = FindWindowEx(lngHWND, 0&, "IMClass", vbNullString) 'Returns Handle
Debug.Print "lngCHwnd:" & lngCHwnd
Debug.Print "GT:" & GetText(lngCHwnd) 'Returns Nothing
lngC2Hwnd = FindWindowEx(lngCHwnd, 0&, "YHTMLContainer", vbNullString) 'Returns Handle
Debug.Print "lngC2Hwnd:" & lngC2Hwnd
Debug.Print "GT:" & GetText(lngC2Hwnd) 'Returns Nothing
lngC3Hwnd = FindWindowEx(lngC2Hwnd, 0&, "Internet Explorer_Server", vbNullString) 'Returns Handle
Debug.Print "lngC3Hwnd:" & lngC3Hwnd
Debug.Print "GT:" & GetText(lngC3Hwnd) 'Returns Nothing
Set doc = modTest.IEDOMFromhWnd(lngC3Hwnd)
Debug.Print doc.body.innerText
End Sub
Last edited by Jaquio; Jul 24th, 2007 at 03:28 AM.
-
Jul 24th, 2007, 01:58 PM
#35
Re: Get Text From Window
Cool gald its working finally. 
Ps, dont forget to Resolve your thread so other members will know its been answered.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 24th, 2007, 05:55 PM
#36
Thread Starter
Addicted Member
Re: [RESOLVED] Get Text From Window
Thanks again, you were a lot of help.
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
|