Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SendMessages to controls in different app? 1

Status
Not open for further replies.

KevinYearian

Programmer
Jun 28, 2001
4
US
Hello,

Is there a way using API Calls that I can SendMessages to controls in another running app?

I have a VB program (App #1) that is a simple address book. The primary window shows the contact information for an individual.
The user can search for another contact by:
1) Clicking on a "Search" button.
- Open a search window.
2) Entering a value in the "search text" box.
3) Clicking "OK"
- Displays a not found message if none found
or
- Populates the primary window with the found contact

I do not have the source code for this app, only the executable.

I have a second program (App #2) that access the same database. This program also does a search, but it returns a list of "Found matches"

What I would like to do, if possible, is to let the user double-click on a "Found entry" in App #2 and have App #1 respond by:
1) Displaying the search window
2) Populating the "Search Text" box with the entry that was double clicked in App #2
3) Clicking the "OK" button in the search window.

 
Have you tried the "SendKeys" command? I've used it before in some applications, I believe sending to PROMIS. Try:

strData = SearchTextBox.value
Sendkeys strData, wait

Craig Canter
Cost Accountant
Sipex
Milpitas, CA
 
Thanks for your reply,

I know about using SendKeys for sending keystrokes to the textbox, and I know about using SendMessage to fire the events.

What I don't know is how to gain addressability to the other application's text box and command buttons so I can use SendKeys and SendMessage.

I have seen several postings in this forum describing how to get the handle to an open window, but I have not seen any for how to get the handle for a control ON another window.

Thank you, your assistance is appreciated.
Kevin Yearian
 
Kevin,

I think I can help you.

You are trying to send messages to controls in other applications. One thing that is important to know is the class of the controls you are trying to access.

Use SPY++ and find the application, then expand the tree to find out the class of the controls you are trying to find, and the class and window caption of the parent application"

Now, get the handle of the parent window:

Code:
hParent& = FindWindow("Parent.Class", "Window Caption")

Now, get the handle of the controls you want

Code:
hButton = FindWindowEX(hParent&, 0&, "Class.Button", vbNullstring)

If it's not the first button on the form, you can use the handle of the button you just found to look for the next one.

Code:
hNextButton = FindWindowEX(hParent&, hButton&, "Class.Button", vbNullString)

When you find the button, use SendMessage API to click the button.

Code:
lRes& = SendMessage(hNextBUtton, WM_LBUTTONDOWN, 0, 0&)
lRes& = SendMessage(hNextBUtton, WM_LBUTTONUP, 0, 0&)

Or To Fill a textbox:

Code:
lRes& = SendMessage(hTextBox, WM_SETTEXT, 0&, sText)

Hope this helped you out! s-)

--NipsMG
 
And a funny detail is that you can press buttons, even if they're disabled...

Remedy [wink]
 
I have write a program to send message to yahoo message windows and click the send button. I can send a string to the send edit box but cannot trigger the send button to send this message out. Why?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top