|
-
Feb 5th, 2000, 04:31 PM
#1
Thread Starter
Addicted Member
Ok, I am hoping to make my program send text to a 3rd party program's specific textbox. This 3rd party program has several textboxes and I need to target a specific one. I naturally do not have the 3rd party program's source code. If you where in my shoes, what would you do to get a 3rd party program's specific textbox handle?
p.s. I thought I had it licked when I used a hWnd spy program. It told me the specific textbox's hWnd. But the hWnd was differnt the next time the 3rd party program was launched.
As always, any help is greatly appreciated,
Daniel Christie
-
Feb 5th, 2000, 04:50 PM
#2
The only way I can think of is to see what the Index of the Edit box is in the Spy program you're using, by Index I mean Instance, is it the 3rd Edit box, the 2nd, etc..
Code:
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 FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Const WM_SETTEXT = &HC
Private Sub Command1_Click()
Dim lHwnd As Long
Dim sText As String
Dim iIndex As Integer
Dim lChildWnd As Integer
sText = Text1
lHwnd = FindWindowEx(0, 0, "3rdParyAppClass", vbNullString)
For iIndex = 1 To 5 'Change 5 to Index Number of Editbox to Find
lChildWnd = FindWindowEx(lHwnd, lChildWnd, "Edit", vbNullString)
Next
SendMessage lChildWnd, WM_SETTEXT, Len(sText), ByVal sText
End Sub
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
-
Feb 5th, 2000, 05:20 PM
#3
Hyperactive Member
What is a 3rd party program?
-
Feb 5th, 2000, 05:25 PM
#4
A program written by a 3rd Party, ie. Commercial Software.
I used 3rdPartyClass just as a Filler, it needs to be replaced with the Class name of the Main Window of the 3rd Party Application.
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
-
Feb 5th, 2000, 06:15 PM
#5
Thread Starter
Addicted Member
Aaron, I admire your vast knowledge and talent. I know that with the information you have supplied me, I am sure to figure my delemma out soon.
Thank you once again,
Daniel Christie
-
Feb 5th, 2000, 07:14 PM
#6
Thread Starter
Addicted Member
Aaron Young,
Here is the source for the spy proggie I am refering to... If you can think of anything it lacks or needs, I'd be happy to listen.
add to .bas:
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameA" (ByVal hModule As Long, ByVal lpFileName As String, ByVal nSize As Long) As Long
Public Declare Function WindowFromPointXY Lib "user32" Alias "WindowFromPoint" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Public Declare Function GetClassName& Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long)
Public Declare Function GetWindowWord Lib "user32" (ByVal hwnd As Long, ByVal nIndex As Long) As Integer
Public Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Public Type POINTAPI
x As Long
y As Long
End Type
Public Const GWL_STYLE = (-16)
Public Const GWW_HINSTANCE = (-6)
Public Const GWW_ID = (-12)
Function WindowSPY(WinHdl As TextBox, WinClass As TextBox, WinTxt As TextBox, WinStyle As TextBox, WinIDNum As TextBox, WinPHandle As TextBox, WinPText As TextBox, WinPClass As TextBox, WinModule As TextBox)
'Call This In Timer1
Dim pt32 As POINTAPI, ptx As Long, pty As Long, sWindowText As String * 100
Dim sClassName As String * 100, hWndOver As Long, hWndParent As Long
Dim sParentClassName As String * 100, wID As Long, lWindowStyle As Long
Dim hInstance As Long, sParentWindowText As String * 100
Dim sModuleFileName As String * 100, r As Long
Static hWndLast As Long
Call GetCursorPos(pt32)
ptx = pt32.x
pty = pt32.y
hWndOver = WindowFromPointXY(ptx, pty)
If hWndOver <> hWndLast Then
hWndLast = hWndOver
WinHdl.Text = "Window Handle: " & hWndOver
r = GetWindowText(hWndOver, sWindowText, 100)
WinTxt.Text = "Window Text: " & Left(sWindowText, r)
r = GetClassName(hWndOver, sClassName, 100)
WinClass.Text = "Window Class Name: " & Left(sClassName, r)
lWindowStyle = GetWindowLong(hWndOver, GWL_STYLE)
WinStyle.Text = "Window Style: " & lWindowStyle
hWndParent = GetParent(hWndOver)
If hWndParent <> 0 Then
wID = GetWindowWord(hWndOver, GWW_ID)
WinIDNum.Text = "Window ID Number: " & wID
WinPHandle.Text = "Parent Window Handle: " & hWndParent
r = GetWindowText(hWndParent, sParentWindowText, 100)
WinPText.Text = "Parent Window Text: " & Left(sParentWindowText, r)
r = GetClassName(hWndParent, sParentClassName, 100)
WinPClass.Text = "Parent Window Class Name: " & Left(sParentClassName, r)
Else
WinIDNum.Text = "Window ID Number: N/A"
WinPHandle.Text = "Parent Window Handle: N/A"
WinPText.Text = "Parent Window Text : N/A"
WinPClass.Text = "Parent Window Class Name: N/A"
End If
hInstance = GetWindowWord(hWndOver, GWW_HINSTANCE)
r = GetModuleFileName(hInstance, sModuleFileName, 100)
WinModule.Text = "Module: " & Left(sModuleFileName, r)
End If
End Function
add to form1:
Private Sub Timer1_Timer()
WindowSPY Text1, Text2, Text3, Text4, Text5, Text6, Text7, Text8, Text9
End Sub
[This message has been edited by Daniel_Christie (edited 02-06-2000).]
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
|