|
-
Jun 25th, 2001, 06:28 PM
#1
Thread Starter
Hyperactive Member
Thanx
Umm... It does what I asked... but it doesn't work. I'm using it on a rich edit text box, class 'RichEdit20A' and it won't pick up the text, but it will on normal text boxes??? very annoying...
Visual Basic 6.0 Enterprise
Visual C++ 6.0 Professional
Wak 
-
Jun 25th, 2001, 06:50 PM
#2
Try:
VB Code:
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_GETTEXT = &HD
Private Const WM_GETTEXTLENGTH = &HE
Private Type POINTAPI
x As Long
y As Long
End Type
Private Sub Form_Load()
Timer1.Interval = 1
End Sub
Private Sub Form_Resize()
Text1.Move 0, 0, ScaleWidth, ScaleHeight
End Sub
Private Sub Timer1_Timer()
Dim lhWnd As Long
Dim sText As String
Dim lLen As Long
Dim tPOINT As POINTAPI
Call GetCursorPos(tPOINT)
lhWnd = WindowFromPoint(tPOINT.x, tPOINT.y)
lLen = SendMessage(lhWnd, WM_GETTEXTLENGTH, 0, ByVal 0&) + 1
sText = Space(lLen)
Call SendMessage(lhWnd, WM_GETTEXT, lLen, ByVal sText)
Text1 = sText
End Sub
-
Jun 26th, 2001, 01:17 AM
#3
Thread Starter
Hyperactive Member
Perfect :)
How come the GetWindowText wouldn't pick it up though?
One more question... :S
What if there are multiple windows with the same class and I'm using FindWindowEx?? It only finds the handle for the window that is at the top of the z-order, how can I get multiple handles so I can find the text for all of the windows??
Visual Basic 6.0 Enterprise
Visual C++ 6.0 Professional
Wak 
-
Jun 26th, 2001, 10:00 PM
#4
Fanatic Member
Isn't EM_STREAMOUT needed to get text from rich text boxes?
You will have to enumerate all the windows in order to find more than the first from any class. Go here: http://www.mvps.org/vbnet/code/enums...indowsdemo.htm
-
Jun 26th, 2001, 10:55 PM
#5
MSDN
The GetWindowText function copies the text of the specified window's title bar (if it has one) into a buffer. If the specified window is a control, the text of the control is copied. However, GetWindowText cannot retrieve the text of a control in another application.
You can get the next Window handle with the same class by specifying the previous Child window handle as the Hwnd2 Parameter, which just indicates it should start looking after the specified handle, i.e.
In a Module:
VB Code:
Private 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 Function GetAllWindowsByClass(ByVal ParentHwnd As Long, ByVal sClass As String) As Variant
Dim lHwnd As Long
Dim aHwnds() As Long
Dim lCount As Long
Do
lHwnd = FindWindowEx(ParentHwnd, lHwnd, sClass, vbNullString)
If lHwnd Then
ReDim Preserve aHwnds(lCount)
aHwnds(lCount) = lHwnd
lCount = lCount + 1
End If
Loop While lHwnd
GetAllWindowsByClass = IIf(lCount, aHwnds, Array())
End Function
Example Usage:
VB Code:
Private Sub Command1_Click()
Dim aList As Variant
Dim lIndex As Long
aList = GetAllWindowsByClass(hWnd, "ThunderTextBox")
For lIndex = 0 To UBound(aList)
Debug.Print aList(lIndex)
Next
End Sub
Alternatively you can use the EnumChildWindows API to enumerate all Child Windows of the specified parent and check the class of each for a match, i.e.
In a Module:
VB Code:
Private Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private aHwndsEnum() As Long
Private lCountEnum As Long
Private sClassEnum As String
Public Function GetAllWindowsByClass_Enum(ByVal ParentHwnd As Long, ByVal sClass As String) As Variant
ReDim aHwndsEnum(0)
lCountEnum = 0
sClassEnum = sClass
Call EnumChildWindows(ParentHwnd, AddressOf ChildEnumProc, 0)
GetAllWindowsByClass_Enum = aHwndsEnum
End Function
Private Function ChildEnumProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
Dim sClass As String
sClass = Space(255)
sClass = Left(sClass, GetClassName(hWnd, ByVal sClass, 255))
If LCase(sClass) = LCase(sClassEnum) Then
ReDim Preserve aHwndsEnum(lCountEnum)
aHwndsEnum(lCountEnum) = hWnd
lCountEnum = lCountEnum + 1
End If
ChildEnumProc = hWnd
End Function
Example Usage:
VB Code:
Private Sub Command1_Click()
Dim aList As Variant
Dim lIndex As Long
aList = GetAllWindowsByClass_Enum(hWnd, "ThunderTextBox")
For lIndex = 0 To UBound(aList)
Debug.Print aList(lIndex)
Next
End Sub
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
|