🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Click another app's button

#3485
From: Jeff
Date: Fri, 02 Jun 2006 22:45
65 lines
3469 bytes
What happens is that if the application I'm trying to close has a dialog box 
(modal window) open, then Windows thinks it was terminated incorrectly when 
I send it the WM_CLOSE message.  I was just thinking I could close all the 
dialogs and then send the WM_CLOSE to the parent window to close it 
gracefully.

I'll have to investigate your suggestions below, thanks a lot.


"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message 
news:4480bc1c$1@newsgroups.borland.com...
>
> "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: <4480bfa4@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news3.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
References: <4480a43a$1@newsgroups.borland.com> <4480bc1c$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: "Jeff" <Jeff@nospam.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <4480a43a$1@newsgroups.borland.com> <4480bc1c$1@newsgroups.borland.com>
Subject: Re: Click another app's button
Date: Fri, 2 Jun 2006 16:45:56 -0600
Lines: 67
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.61
Message-ID: <4480bfa4@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1149288356 198.68.195.61 (2 Jun 2006 15:45:56 -0700)
Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news3.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