🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #3582

Click another app's button

#3582
From: Jeff
Date: Fri, 02 Jun 2006 20:49
41 lines
2423 bytes
I'm trying to search through another application's client area and click any 
"Cancel" or "Close" buttons found in an attempt to safely close the 
application.  I can't seem to find a way to click another application's 
buttons, or find them for that matter.  I tried getting the child handles 
(see code below) and getting the text using GetWindowText() but Microsoft 
states, "However, GetWindowText cannot retrieve the text of a control in 
another application."  How do I do this?

void TfrmMain::CancelDialogs(HWND hParentWin)
{
 HWND hChild; //Child window handle
 char *ptr_chrText = ""; //Control text
 POINT pPoint;   //Coordinate structure
 WINDOWINFO WinInfo;     //Window information structure
 WinInfo.cbSize = sizeof(WINDOWINFO);

 if (!GetWindowInfo(hParentWin, &WinInfo)); //Get the dimensions of the 
window
 {
  for (pPoint.x = WinInfo.rcClient.left; pPoint.x <= WinInfo.rcClient.right; 
pPoint.x = pPoint.x + 1)
  {
   for (pPoint.y = WinInfo.rcClient.top; pPoint.y <= 
WinInfo.rcClient.bottom; pPoint.y = pPoint.y + 1)
   {
    hChild = ChildWindowFromPoint(hParentWin, pPoint); //Get a handle to any 
child window
    if (hChild != NULL)
    {
     GetWindowText(hChild, ptr_chrText, GetWindowTextLength(hChild) + 1); 
//Get the text of the control
     if ((StrComp(ptr_chrText, CANCEL_BTN) == 0) || (StrComp(ptr_chrText, 
CLOSE_BTN) == 0))
      Application->MessageBox(ptr_chrText, "Test", MB_OK);
      //SendMessage(hChild, WM_CLICK, NULL, NULL); //Click the Cancel or 
Close button
    }
   }
  }
 }
} 
Technical Details
Message-ID: <4480a43a$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,4b00671b0054e23d,start
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Jeff" <Jeff@nospam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Click another app's button
Date: Fri, 2 Jun 2006 14:49:00 -0600
Lines: 43
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2869
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869
NNTP-Posting-Host: 198.68.195.136
Message-ID: <4480a43a$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1149281338 198.68.195.136 (2 Jun 2006 13:48:58 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail