|
-
Jul 18th, 2001, 03:12 PM
#1
Thread Starter
Lively Member
Getting text from any label?
I was wondering how I could retrive the text from any label?
-Thanks
-
Jul 18th, 2001, 03:40 PM
#2
Member
What's wrong with [lblName].Caption?
-
Jul 18th, 2001, 04:05 PM
#3
Thread Starter
Lively Member
I'm talking about compiled programs, Like lets say I get a pop up msg and I want to get that text out of a label. This code I need to work for everything... a universal code to get the text out of any kind of label.
-
Jul 18th, 2001, 04:09 PM
#4
Hyperactive Member
I got you covered
Code:
Option Explicit
Declare Function FindWindow _
Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String _
) As Long
Declare Function GetWindowText _
Lib "user32" Alias "GetWindowTextA" ( _
ByVal hwnd As Long, _
ByVal lpString As String, _
ByVal cch As Long _
) As Long
Declare Function GetWindowTextLength _
Lib "user32" Alias "GetWindowTextLengthA" ( _
ByVal hwnd As Long _
) As Long
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
Declare Function SendMessage _
Lib "user32" Alias "SendMessageA" ( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any _
) As Long
Public Const WM_GETTEXT = &HD
Public Const WM_GETTEXTLENGTH = &HE
Private Function GetText() as long
Dim hwndParent As Long, hwndChild As Long, hwndChildPrev As Long
Dim hwndChildTextLength As Long, hwndChildText As String, lCharactersReturned As Long
hwndParent = FindWindow("WindowClass", vbNullString)
hwndChildPrev = FindWindowEx(hwndParent, 0, "Static", vbNullString)
hwndChild = FindWindowEx(hwndParent, hwndChildPrev, "Edit", vbNullString)
hwndChildTextLength = SendMessage(hwndChild, WM_GETTEXTLENGTH, 0, ByVal 0&) + 1
hwndChildText = Space(hwndChildTextLength)
Call SendMessage(hwndChild, WM_GETTEXT, hwndChildTextLength, ByVal hwndChildText)
GetText = hwndChildText
End Function
Some labels have the class 'static' other are just 'edit' classes that are made to look like labels, and other labels, are similar to the DrawText or TextOut Functions.
Visual Basic 6.0 Enterprise
Visual C++ 6.0 Professional
Wak 
-
Jul 18th, 2001, 05:28 PM
#5
Thread Starter
Lively Member
Thanks! I'm new with API functions and heh, how would I put this to use?
-
Jul 19th, 2001, 07:33 AM
#6
Hyperactive Member
ok
Well to start off u need a Window Spy similar to Spy++ or any other home brand ones.
Once you have the class of the child window(label) and the paren window, andor the previous control in the order to the child window(label) just stick their classes names is. I'll post a working example 2moro if you want. I haven't any time now. sorry.
Visual Basic 6.0 Enterprise
Visual C++ 6.0 Professional
Wak 
-
Jul 19th, 2001, 11:39 AM
#7
Thread Starter
Lively Member
Yea, I would really appreciate that, do it when you have the time.
Thanks!
-
Jul 20th, 2001, 04:55 PM
#8
Hyperactive Member
Here's my example
I'm guessing your using Vb, so here it is in vb. Notice the timer control and also the getText().
Visual Basic 6.0 Enterprise
Visual C++ 6.0 Professional
Wak 
-
May 7th, 2002, 05:05 PM
#9
Thread Starter
Lively Member
I tried this code but it didn't work. The text i'm trying to get from is static.
It's better to burn out than fade away...

-
May 7th, 2002, 05:20 PM
#10
Note: You can only get the text of an "actual window", i.e. trying to get the caption of an external VB "Label" will not work, because a "Label" is not actually a window.
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
|