🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Reading pixel from another application - Not Working!

#9267
From: Henry
Date: Wed, 21 Jul 2004 08:39
71 lines
3203 bytes
> Specify an actual window handle when calling GetDC() instead of getting
the
> screen's DC.  The screen DC only contains the pixels that are actually
> visible onscreen, whereas a window DC contains all of the pixels for a
> particular window regardless of what's on top of it..
>
>
> Gambit

Thanks for the answer. I developed the following code that copies a portion
of the target application form to an image within my test application:

// ---------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{ RECT MyRect;
  HDC dc;
  Graphics::TCanvas *ScreenCanvas;

  // Edit1->Text contains the handler of the target application
  Target_Hwnd = (HWND)StrToInt(Edit1->Text);

  if (!IsWindow(Target_Hwnd))
    Target_Hwnd = 0;

  ScreenCanvas = new Graphics::TCanvas();
  dc = GetDC(Target_Hwnd);
  ScreenCanvas->Handle = dc;

  MyRect = Rect(0, 0, 200, 200);

  Image1->Canvas->CopyRect(MyRect, ScreenCanvas, MyRect);

  delete ScreenCanvas;
  ReleaseDC(Target_Hwnd, dc);
}
// ---------------------------------------------------------------

My test program works correctly only when the target application is normally
visible; if the target form is covered by another window, my program copies
a portion of that windows (not a portion of the target application form). Is
there something wrong with my code ? (By the way: I am using Windows XP Pro,
and BCB 6).
Thanks again for help.
Henry

"Henry" <eangelo@libero.it> ha scritto nel messaggio
news:40fd37c8@newsgroups.borland.com...
> Hi to all!
>
> I am working on a supervisor program that waits for an area within another
> application to become red. As a first solution I tried the following code:
>
>  HDC dc;
>  Graphics::TCanvas ScreenCanvas;
>
>  ScreenCanvas = new Graphics::TCanvas();
>  dc = GetDC(NULL);
>  ScreenCanvas->Handle = dc;
>
>  If (ScreenCanvas->Pixels[_DNS_Mike_St_X_Coord_][_DNS_Mike_St_Y_Coord_] ==
> clRed)
>
> which worked correctly. My problem is: what if the target windows is
covered
> by another windows or it is minimized ? Is there an API to be used to
> directly read pixel from another application? Can anybody provide me with
a
> piece of code ?
> Thank un advance.
>
> Henry - Italy
Technical Details
Message-ID: <40fe2bdd@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!news.linkpendium.com!news.linkpendium.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <40fd37c8@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,b592d6567f6c1e9
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
Reply-To: "Henry" <eangelo@libero.it>
From: "Henry" <eangelo@libero.it>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <40fd37c8@newsgroups.borland.com>
Subject: Re: Reading pixel from another application - Not Working!
Date: Wed, 21 Jul 2004 10:39:53 +0200
Lines: 74
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 151.30.195.70
Message-ID: <40fe2bdd@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1090399197 151.30.195.70 (21 Jul 2004 01:39:57 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!news.linkpendium.com!news.linkpendium.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail