-
Apr 18th, 2018, 03:36 AM
#1
Thread Starter
Lively Member
[RESOLVED] [help]WM_GETTEXT only can grap the title from some controls. How to grap content?
Dear All,
I use the code below to grab text from controls, but some controls may have a title, then the code only can grab title from those controls. How to grab content from them?
Code:
Private Sub GetTextFromControls(lControlHwnd as Long)
Dim lRC As Long
Dim strText As String
Dim lTextLen As Long
lTextLen = SendMessageW(lControlHwnd, WM_GETTEXTLENGTH, 0, 0)
If lTextLen > 0 Then
strText = String$(lTextLen, 0)
Call SendMessageW(lControlHwnd, WM_GETTEXT, lTextLen + 1, ByVal StrPtr(strText))
oForm.txtControlText.Text = " " & Trim(StrConv(byt, vbUnicode))
Else
oForm.txtControlText.Text = ""
End If
End Sub
For example: VB6.0 IDE's Immediate window, there are a lot of string created by Debug.Print "blabla...". Use the code above, only the title "Immediate" can be grabbed, all the contents can't be grabbed.
Best Regards,
Sniperhgy
-
Apr 18th, 2018, 06:56 AM
#2
Re: [help]WM_GETTEXT only can grap the title from some controls. How to grap content?
Originally Posted by gyhu
Dear All,
For example: VB6.0 IDE's Immediate window, there are a lot of string created by Debug.Print "blabla...". Use the code above, only the title "Immediate" can be grabbed, all the contents can't be grabbed.
Best Regards,
Sniperhgy
Windows can have child windows (controls), child windows can have child windows. You may need to iterate through the child windows and extract the text for each one you need. For example, calling WM_GETTEXT on a NotePad window will not return the content of text, it'll return the window's title bar caption. But calling WM_GETTEXT on NotePad's "textbox" can return its text.
Not all controls will return expected text anyway. Some controls may be custom/owner-drawn and do not respond to WM_GETTEXT.
-
Apr 18th, 2018, 08:18 AM
#3
Thread Starter
Lively Member
Re: [help]WM_GETTEXT only can grap the title from some controls. How to grap content?
Originally Posted by LaVolpe
Windows can have child windows (controls), child windows can have child windows. You may need to iterate through the child windows and extract the text for each one you need. For example, calling WM_GETTEXT on a NotePad window will not return the content of text, it'll return the window's title bar caption. But calling WM_GETTEXT on NotePad's "textbox" can return its text.
Not all controls will return expected text anyway. Some controls may be custom/owner-drawn and do not respond to WM_GETTEXT.
Hi LaVolpe,
Thank you for your reply. Actually, I don't use FindWindowEx to get the Hwnd. I use WindowFromPoint to get the Hwnd directly. And in VB6.0, "Immediate window" only has one hwnd, doesn't have child window, you can do a test.
Best Regards,
Sniperhgy
-
Apr 20th, 2018, 11:39 PM
#4
Re: [help]WM_GETTEXT only can grap the title from some controls. How to grap content?
"Immediate window" only has one hwnd, doesn't have child window
not quite correct
the top window of vb ide immediate is a vbfloatingpalette, which has a child with same caption and type vbawindow, which in turn has 3 child windows being type scrollbar
i do not know if this will help you get the text, probably not, but it at least gives you some more things to look at
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Apr 21st, 2018, 03:27 AM
#5
Thread Starter
Lively Member
Re: [help]WM_GETTEXT only can grap the title from some controls. How to grap content?
Originally Posted by westconn1
not quite correct
the top window of vb ide immediate is a vbfloatingpalette, which has a child with same caption and type vbawindow, which in turn has 3 child windows being type scrollbar
i do not know if this will help you get the text, probably not, but it at least gives you some more things to look at
Thank your for your TIP, will have a look.
-
Apr 21st, 2018, 04:50 AM
#6
Re: [help]WM_GETTEXT only can grap the title from some controls. How to grap content?
If you need the text from the Immediate window you're really better off just swapping all Debug.Print statements in the project that's generating it to a function that routes the text elsewhere (like for example, I do a find/replace all on Debug.Print and replace it with a DebugOut function that writes to a text file, for debugging after compiled). If you're not talking about that window specifically, others aren't usually set up that way and will have a child window you can use WM_GETTEXT with.
-
Apr 21st, 2018, 07:29 AM
#7
Re: [help]WM_GETTEXT only can grap the title from some controls. How to grap content?
Last edited by dz32; Apr 26th, 2019 at 11:22 AM.
-
Apr 22nd, 2018, 04:08 AM
#8
Thread Starter
Lively Member
Re: [help]WM_GETTEXT only can grap the title from some controls. How to grap content?
Originally Posted by fafalone
If you need the text from the Immediate window you're really better off just swapping all Debug.Print statements in the project that's generating it to a function that routes the text elsewhere (like for example, I do a find/replace all on Debug.Print and replace it with a DebugOut function that writes to a text file, for debugging after compiled). If you're not talking about that window specifically, others aren't usually set up that way and will have a child window you can use WM_GETTEXT with.
Hi fafalone,
I just take "Immediate window" as an example, it seems a lot of controls don't response WM_GETTEXT message.
Best Regards,
Sniperhgy
-
Apr 22nd, 2018, 04:09 AM
#9
Thread Starter
Lively Member
Re: [help]WM_GETTEXT only can grap the title from some controls. How to grap content?
Originally Posted by dz32
Different controls require different techniques to grab the data in them.
Some can be pretty involved like a listview or treeview.
Here is a collection of classes which handle Listview, Treeview, Listbox, ComboBox, IE Window
http://www.vbforums.com/showthread.p...oBox-IE-Window
Thank you very much for the demo.
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
|