|
-
Feb 8th, 2000, 11:43 AM
#1
Thread Starter
Junior Member
I have program that will enter text into a 3rd party program's specific textbox. Now this 3rd party proggie has A parent window, then a child, on the child is several other childs, on one of the childs is the textbox I need to manipulate. I know what the main parent's class name is and I know that the name for the target textbox is "Edit", but there also 18 other textboxes named edit...Soooo I will have to specify the target textboxe's index. How do I figure out what the index is for the target textbox?
Here is the unfinished code I am currently using:
'Window Handles change every time a Window is Created, you can find the Window Handle using the API "FindWindowEx()".
'You can Pass a Window Caption or Class, you can also search within other Windows, the following searches for a Textbox.
Dim lHwnd As Long
Dim sText As String
Dim iIndex As Integer
Dim lChildWnd As Integer
sText = Text1
'lHwnd = A window's handle you desire (in this particular code it is not needed since it is unknown, but if it was known, you could cut to the chase and just use it. Refer to SendKey_part2).
'3rdPartyAppClass is the Classname of the 3rd Party App.
'3rdPartyClass needs to be replaced with the Class name of the Main Window of the 3rd Party Application.
lHwnd = FindWindowEx(0, 0, "3rdPartyAppClass", vbNullString)
'iIndex is the parentwindow's specific textbox (childwindow) index.
'I am using iIndex simply because CCS has many textboxes, and each one will have their own indicies.
'Our code will have to search all childwindows by their indexes, inorder to find the target textbox.
For iIndex = 1 To 18
'Edit is the Classname for a Standard Windows Textbox.
lChildWnd = FindWindowEx(lHwnd, lChildWnd, "Edit", vbNullString)
Next
'lChildWnd is the target child window.
SendMessage lChildWnd, WM_SETTEXT, Len(sText), ByVal sText
End Sub
I would do anything to find a solid way to make my program edit the correct textbox in the 3rd party program. I will gladly kiss the feet of the hot dog coder who makes this a reality for me 
I can't sleep well till I get it right.
Daniel Christie
-
Feb 9th, 2000, 12:20 PM
#2
Other then knowing the order in which those textboxes are setup, there's no aother way to do it. What you can do is to insert some text in those textboxes manually, then open Spy++ and check the sequence, according the text you inserted.
------------------
Serge
Senior Programmer Analyst
[email protected]
[email protected]
ICQ#: 51055819
-
Mar 13th, 2004, 05:21 PM
#3
Member
Ok Darkcloud I hope you have your lip chap ready! :bigyello: Now this is going to sound kinda complicated, so if you need help, just post your questions.
1st add this to your code module:
' Start copying here
' MODULE CODE
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public 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 SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long
' Get the class name
Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Const WM_SETTEXT = &HC
Function GetText(Handle)
GetTrim = SendMessageByNum(Handle, 14, 0&, 0& )
TrimSpace$ = Space$(GetTrim)
GetString = SendMessageByString(Handle, 13, GetTrim + 1, TrimSpace$)
GetText = TrimSpace$
End Function
'------------------------------------------------------------------
' Class name
Public Function GetWindowClassName(hWnd As Long) As String
Dim ClsName As String
Dim ClsLen As String
'If IsWindow(hWnd) = 0 Then Error 5
ClsLen = 128
ClsName = Space(ClsLen)
ClsLen = GetClassName(hWnd, ClsName, ClsLen)
GetWindowClassName = Left(ClsName, ClsLen)
MsgBox (GetWindowClassName)
End Function
' End copying module code here
////////////////////////////////////////////////////////////////////////////////////
Now this is the Pseudo-code for your app (the concepts)
' 1st find the handle of the 3rd party app
Prog = FindWindow(" insert program class ", " insert program caption ")
' 2nd find the handle of the control you wanna send text to
' note the 0& means start from beginning of the internal list of all
' component classes for your 3rd party program.
lHwnd1 = FindWindowEx(Prog, 0&, " insert component class ", " insert component caption" )
' Now send some text!
Call SendMessageByString(lHwnd1, WM_SETTEXT, 0, "Text to send")
////////////////////////////////////////////////////////////////////////////////////
Now for actual code, you need to know the class of the 'component' you wanna send text to, for example, in notepad, its "Edit" for other progs its different. I suggest using Spy++ or a similar program to find out exactly the info. Just remeber, paste the data within the quotes, so if the class is edit, its: "Edit".
Now lets say if the main program has multiple classes with the same name, which i assume it does, since in your code u wanted to loop. You will need to know exactly in what order it is in, so you can get the right hWnd. Ill show and example and hopefully youll be able to follow.
3rd party program name: "Magic Prog"
3rd party program class: "Magic_Prog_Class"
Now this program is a simple form with 4 edit boxes, all with a caption of "" and a class name of "Edit"
Let's say i want to send a string "This is a test" to the third component. This is the code:
////////////////////////////////////////////////////////////////////////////////////
' 1st find the handle of the 3rd party app
Prog = FindWindow("Magic_Prog_Class", "Magic Prog")
' 2nd find the handle of the control you wanna send text to
' note the 0& means start from beginning of the internal list of all
' component classes for your 3rd party program.
' get the 1st control
lHwnd1 = FindWindowEx(Prog, 0&, "Edit", "" )
' get the 2nd control by searching after the 1st control (lHwnd1)
lHwnd1 = FindWindowEx(Prog, lHwnd1, "Edit", "" )
' get the 3rd control by searching after the 2nd control (lHwnd1)
lHwnd1 = FindWindowEx(Prog, lHwnd1, "Edit", "" )
' Now send some text!
Call SendMessageByString(lHwnd1, WM_SETTEXT, 0, "This is a test")
////////////////////////////////////////////////////////////////////////////////////
Phew kinda long but it should work! Give it a try and leave any messages, or email me at "Dr3w_B3nton" at "hotmail.com". Me and my friend found out how to do this after a lot of research and trial and error, mostly error though, so hope it works! :wave:
-
Mar 13th, 2004, 05:35 PM
#4
Hyperactive Member
This thread is 4 years old..doubt Darkcloud will need it anymore, but It still might be useful to others
BTW, use vbcode tags around your code, it just makes it alot easier to read and Welcome to VB Forums.
"Whether you think you can or cannot, you are always right."
-
Mar 15th, 2004, 10:07 AM
#5
Member
lol didn't notice the years, but on the vb code, i just now realized you dont have to paste all your code into that new messagebox that pops up, whne i posed i thought u did and i didnt want to go line by line
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
|