Article View: borland.public.cppbuilder.nativeapi
Article #9903How to click a button in another program?
From: TerryC
Date: Thu, 03 Jun 2004 20:22
Date: Thu, 03 Jun 2004 20:22
84 lines
2810 bytes
2810 bytes
I am trying to replicate the functionality of a nice utility
called "Click Yes". This program watches for the MS Outlook
warning dialog that pops up when you try to automate sending
email programmatically. "Click Yes" works wonderfully, but
I need to be able to do it from within my own app.
Here's what I have tried:
int __stdcall ChildEnumProc(HWND wnd, void *Nada)
{
char buf[256];
char caption[256];
AnsiString CName;
AnsiString Cap;
GetClassName( wnd, buf, sizeof(buf) );
SendMessage( wnd, WM_GETTEXT, sizeof(caption), (long)caption);
CName = buf;
Cap = caption;
if(CName == "Button")
if(Cap == "Yes"){
BtnHandle = wnd; // global HWND
Repeat->Enabled = false; // global TTimer*
Delay->Enabled = true; // global TTimer*
}
return -1;
}
int __stdcall EnumProc(HWND wnd, void *Nada)
{
char caption[256];
AnsiString Cap;
SendMessage( wnd, WM_GETTEXT, sizeof(caption), (long)caption);
Cap = caption;
if(Cap == "Microsoft Office Outlook")
EnumChildWindows(wnd,
(WNDENUMPROC)ChildEnumProc, NULL);
return -1;
}
void __fastcall TfMain::DlyTimer(TObject *Sender)
{
int XPos;
int YPos;
WORD ClickPos;
WINDOWPLACEMENT WinPlc;
RECT WinRect;
WinPlc.length = sizeof(WINDOWPLACEMENT);
GetWindowPlacement(BtnHandle, &WinPlc);
WinRect = WinPlc.rcNormalPosition;
XPos = WinRect.left + 10;
YPos = (WinRect.top + 10) * 65536;
ClickPos = YPos + XPos;
SendMessage(BtnHandle, WM_LBUTTONDOWN,
MK_LBUTTON, ClickPos);
Sleep(50);
SendMessage(BtnHandle, WM_LBUTTONUP,
MK_LBUTTON, ClickPos);
Dly->Enabled = false;
Rpt->Enabled = true;
}
void __fastcall TfMain::RptTimer(TObject *Sender)
{
EnumWindows((WNDENUMPROC)EnumProc, NULL);
}
This appears to click the button -- the button goes down and
back up -- but the dialog never closes! What gives?
-Terry
Technical Details
Message-ID:
<40bf8884$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,6be234126fe720da,start X-Google-Attributes: gid10cc67,public From: "TerryC" <terryc.dont_spam_me@sweetwaterhsa.com> Sender: "TerryC" <terryc.dont_spam_me@sweetwaterhsa.com> Reply-To: "TerryC" <terryc.dont_spam_me@sweetwaterhsa.com> Subject: How to click a button in another program? Newsgroups: borland.public.cppbuilder.nativeapi X-User-Info: 63.250.179.198 NNTP-Posting-Host: 207.105.83.66 Message-ID: <40bf8884$1@newsgroups.borland.com> Date: 3 Jun 2004 13:22:28 -0700 X-Trace: newsgroups.borland.com 1086294148 207.105.83.66 (3 Jun 2004 13:22:28 -0700) Lines: 84 Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail