Possible to use SendMessage with form in external application?
Possible to use SendMessage with form in external application?
(OP)
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!
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?
RE: Possible to use SendMessage with form in external application?
Hi
I have done these things before but in Main
Visual Basic . The following link shows
how to do a post message in VBA.
h
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
internet.
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
WM_LBUTTONDOWN
WM_LBUTTONUP
WM_LBUTTONDBLCLICK
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.
postmessage(hwnd,WM_LBUTTONDOWN,wparam,lparam)
postmessage(hwnd,WM_LBUTTONUP,wparam,lparam)
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
SPY.
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.
http://vb
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)
DOEVENTS
DOEVENTS
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.
Aprivate.
RE: Possible to use SendMessage with form in external application?
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.
Aprivate
RE: Possible to use SendMessage with form in external application?
I'll let you know how it goes, thanks again!
RE: Possible to use SendMessage with form in external application?
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
Aprivate