🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Click another app's button

#3583
From: Remy Lebeau (TeamB)
Date: Fri, 02 Jun 2006 22:22
49 lines
2803 bytes
"Jeff" <Jeff@nospam.com> wrote in message
news:4480a43a$1@newsgroups.borland.com...

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

Just send WM_CLOSE and/or WM_QUIT messages to the main windows instead.  You
don't need to deal with the buttons just to close the application.

> I can't seem to find a way to click another application's buttons

You have to send a WM_COMMAND message to the button's parent window,
specifying BN_CLICKED.  Or a BM_CLICK message to the button itself.

> or find them for that matter.

That is because you are not looking correctly.

> I tried ... 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?

That is correct.  GetWindowText() needs you to pass it a memory address to a
buffer that will receive the text.  A memory address in one application is
not a valid memory address in another application.  You would have to write
a custom DLL and then use DLL injection, such as with a message hook via
SetWindowHookEx(), to force the DLL's code to run in the context of the
other application.  Then the DLL can use GetWindowText() and copy the text
back to the application, such as with WM_COPYDATA.

>  char *ptr_chrText = ""; //Control text

That won't work.  You are not allocating a memory buffer to receive the
text.  You are pointing to a string constant that is located in the
application's read-only memory.

>  POINT pPoint;   //Coordinate structure
>  WINDOWINFO WinInfo;     //Window information structure
>  WinInfo.cbSize = sizeof(WINDOWINFO);
>
>  if (!GetWindowInfo(hParentWin, &WinInfo)); //Get the dimensions of the
> window

Get rid of all of that.  Use GetWindow() or EnumChildWindows() instead.


Gambit
Technical Details
Message-ID: <4480bc1c$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news.germany.com!newsfeed.cw.net!cw.net!news-FFM2.ecrc.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4480a43a$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,4b00671b0054e23d
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <4480a43a$1@newsgroups.borland.com>
Subject: Re: Click another app's button
Date: Fri, 2 Jun 2006 15:22:47 -0700
Lines: 51
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <4480bc1c$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1149287452 68.69.17.41 (2 Jun 2006 15:30:52 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news.germany.com!newsfeed.cw.net!cw.net!news-FFM2.ecrc.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail