Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Possible to use SendMessage with form in external application?

Possible to use SendMessage with form in external application?

Possible to use SendMessage with form in external application?

I have some 3rd party database software that I am working with. I am using VBA from Excel to open the software. To my knowledge there is no way to pass SQL script to the application via the command line and the documentation is extremely limited. There are several things I would need to do from VBA.

1. Open the application (done)
2. Double-click or simulate opening of an icon in a child window inside the application
3. Pass a string into a form that pops up when clicking the icon (i.e. "11123AB-C")
4. "Submit" the form (press a command button)

Basically I am trying to automate some database queries.

Is this even possible? If so, I'd appreciate it if someone can just point me in the right direction.

If I have to use KeyPress, that's okay, because I wouldn't be putting in THAT many values, and speed of the code is not a big priority.

Thanks in advance for any help!

RE: Possible to use SendMessage with form in external application?

By the way, the application in question is STS SmartLook if anyone has ever heard of it. I google'd just about every possible thing I could think of to find documentation for it -- no luck! I imagine there should be some way to manually pass SQL query via command line which would probably make this a thousand times easier! :)

RE: Possible to use SendMessage with form in external application?

 I have done these things before but in Main
Visual Basic . The following link shows
how to do a post message in VBA.

What you need to do for ANY windows application
in order to send or modify its behaviour
is to use the SPY++ application found in the visual
studio or download alternative spy apps from the

You need to spy on the application child windows
or main windows and look for MOUSE CLICK messages.

In your case you need to spy on
all the window handles belonging to
the main application for the following
messages. Set the FILTER  to show only


Move your mouse over the ICON and do a left click.

Identify  which window handle shows these messages.
With SPY, Close all other spy windows except
the ones you identified  and re-spy to verify.
Copy down the Wparam and the Lparam values
It will look something like

 handle  message   wparam, Lparam
  A95394, WM_LBUTTONDOWN, 1,70032
  A95394, WM_LBUTTONUP, 0,70032

use POSTMESSAGE to post them back to the windows
handle.. in VBA.

In order to get back to the same window handle
you need to observe the window tree structure
and use GetWindow() to move up and down the
chain so that your VBA code will be pointing
back to the same window handle. Then you
send it with postmessage.


This will cause the Windows OS to simulate
a mouse press over that Icon in that window.

Basically you are PLAYING BACK what you observed with

To change the text of the control you use
a postmessage or the SETWINDOWTEXT() api
to change the text.

The window handles change everytime you  close
and start any windows app.

Here is the fancy VB code to traverse a Window Tree
to look for the text and classes so that your
code will point to the right handle.


In my code I normally
control the app by shutting it down and re-running it
so that it goes back into a known state. Then
I use the getwindow(hwnd,child) nextchild to crawl
down the window tree..

How do I know where to stop?
I use SPY to see how many times I need to go down
the tree to get to the correct window handle. It will
ALWAYS be the same as long as you can control the initial
state of your external app.

You can TEST first by writing a small VBA app to
do a postmessage to see if it will work without
all the extra code.

1)Use SPY to get the window handle of
a control that responds to the a mouse click.
(use some other simple app like notepad.exe)

2) Copy the windows handle of that control
into your vba code and run it to
see if the mouse will click on the app.
You need to arrange your app so that you can see
with your eyes if things are working.

  PostMessage(handle, WM_LBUTTONDOWN, 1,&H70032 )
  PostMessage(handle, WM_LBUTTONUP, 0, &H70032)

Once that works you need to modify your
app to crawl back to the same control
when your app is running and send the messages.

Do not use SENDMESSAGE as it waits for a response.
Use postmessage so that the system and your code
can continue executing.


RE: Possible to use SendMessage with form in external application?

I forgot to mention,

The 'lparam'  eg (&H70032)
  PostMessage(handle, WM_LBUTTONDOWN, 1,&H70032 )

Will change everytime you re-spy on the windows
by repeating the mouse click. Thats because
you can hardly place the mouse back over the same
spot. To play safe, place the mouse over the CENTER
of the ICON or button so that any value you copy
will be the approximate  mouse pointer position over the center.

The Lparam contains the X,Y position of the
window in the app you want to control relative
to the apps own parent window.
For for the
ICON you want to click,The ICon is located within
a specific Child Window and the X,Y position is
referring to the position of the Icon where your
mouse clicked inside the child window.
If you move the parent window (STS program)
elsewhere on the windows Desktop , the program will
still work.


RE: Possible to use SendMessage with form in external application?

Wow thanks for taking the time to explain it with such a lengthy reply. I had kind of given up on this and resorted to keying in everything manually but this will save me a ton of time if I can get it all together! :)

I'll let you know how it goes, thanks again!

RE: Possible to use SendMessage with form in external application?

Actually you can also use AUTOIT which
is OPEN SOURCE and FREE and it can generate
.EXE files for you to launch from your app

I think the limitation of Autoit is that it
needs the app to be in Focus.. It cannot
send info to windows if the app is not in focus


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close