Passing events to third party app.
My program needs to send Mouse Click events to another app. My program opens
the third party app using CreateProcess
but I need my prog to communicate with the other app by sending Clicks to
display buttons on the third party app.
Does anyone have any suggestions?
thanx for any help,
Kevin D.
ksdr1@home.com
[347 byte] By [
Kevin] at [2007-11-10 12:51:42]

# 1 Re: Passing events to third party app.
Hi Kevin,
I haven't found a way to get a HWND back from CreateProcess in order
to directly communicate with the launched app's main window (If you know
a way, please let me know!) However, you can use FindWindow() to locate
the window, then send messages to its child controls. You will need to know
the child control IDs (such as IDOK or IDCANCEL, or your user-defined button
control IDs). For example:
HWND hWnd;
STARTUPINFO si;
PROCESS_INFORMATION pi;
CreateProcess(NULL, "sndrec32.exe", NULL, NULL, FALSE, 0, NULL, ".", &si,
&pi);
// may need to wait a moment here until the app launches...
Sleep(1000);
// search by title bar text
//hWnd = FindWindow(NULL, "Sound - Sound Recorder");
// or search by window class (if the title may change)
hWnd = FindWindow("SoundRec", 0);
if (hWnd) {
// press the Play button (control ID 207 sniffed out by Spy++)
SetForegroundWindow(hWnd);
SendMessage(GetDlgItem(hWnd, 207), BM_CLICK, 0, 0);
}
If you're using MFC or other framework, remember to use the global scope
resolution operator :: before each of the window functions above, i.e., ::GetDlgItem().
I hope this helps.
Kevin Sikes
Software Engineer
ENCO Systems, Inc.
Farmington Hills, MI
sikes@enco.com
"Kevin" <ksdr1@home.com> wrote:
>
>My program needs to send Mouse Click events to another app. My program
opens
>the third party app using CreateProcess
>but I need my prog to communicate with the other app by sending Clicks to
>display buttons on the third party app.
>
>Does anyone have any suggestions?
>
>thanx for any help,
>Kevin D.
>ksdr1@home.com
>
>