Hi
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
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.
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.