Ik wilde wat dingetjes gaan automatiseren en toen liep ik tegen het volgende punt aan:
Is het mogelijk om via wat API calls in VB6 de waarde van bijv. een textbox van een andere applicatie uit te lezen, met alleen de hwnd waarde van de applicatie?
Bijvoorbeeld van de rekenmachine (standaard in windows).
Nou had ik al de volgende code gevonden:
Maar nu zit ik met het volgende probleem:
de handle van de rekenmachine verandert natuurlijk iedere keer (tevens de handle van de uit te lezen textbox).
Hoe kan ik er dan achter komen wat de handle van die desbetreffende textbox is die ik wil uitlezen, nadat de applicatie bijv. nog eens wordt opgestart?
Is het mogelijk om via wat API calls in VB6 de waarde van bijv. een textbox van een andere applicatie uit te lezen, met alleen de hwnd waarde van de applicatie?
Bijvoorbeeld van de rekenmachine (standaard in windows).
Nou had ik al de volgende code gevonden:
Visual Basic 6:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
| Option Explicit ' ClassSpy Sample from BlackBeltVB.com ' http://blackbeltvb.com ' ' Written by Matt Hart ' Copyright 1999 by Matt Hart ' ' This software is FREEWARE. You may use it as you see fit for ' your own projects but you may not re-sell the original or the ' source code. Do not copy this sample to a collection, such as ' a CD-ROM archive. You may link directly to the original sample ' using "http://blackbeltvb.com/classspy.htm" ' ' No warranty express or implied, is given as to the use of this ' program. Use at your own risk. ' ' This shows several APIs - mainly how to get the class name. ' This is handy as a utility so that you can later use the FindWindow API call. Private Type POINTAPI x As Long y As Long End Type Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) 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 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 Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long Const WM_GETTEXT = &HD Const WM_GETTEXTLENGTH = &HE Private Sub Form_Unload(Cancel As Integer) End End Sub Private Sub Timer1_Timer() Dim P As POINTAPI, lRet As Long, hHandle As Long, aClass As String, aText As String lRet = GetCursorPos(P) hHandle = WindowFromPoint(P.x, P.y) aClass = Space$(128) lRet = GetClassName(hHandle, aClass, 128) aClass = Left$(aClass, lRet) lblHandle.Caption = hHandle lblClassName.Caption = aClass Dim lTextlen As Long lTextlen = SendMessage(hHandle, WM_GETTEXTLENGTH, 0, ByVal 0) If lTextlen Then If lTextlen > 1024 Then lTextlen = 1024 lTextlen = lTextlen + 1 aText = Space$(lTextlen) lRet = SendMessage(hHandle, WM_GETTEXT, lTextlen, ByVal aText) aText = Left$(aText, lRet) End If lblWText.Caption = aText End Sub |
Maar nu zit ik met het volgende probleem:
de handle van de rekenmachine verandert natuurlijk iedere keer (tevens de handle van de uit te lezen textbox).
Hoe kan ik er dan achter komen wat de handle van die desbetreffende textbox is die ik wil uitlezen, nadat de applicatie bijv. nog eens wordt opgestart?