Otprilike ovako nekako /netestirano/:
GetDC() - Prozor bez naslovne linije
GetWindowDC - Prozor sa naslovnom linijom
GetDC(0) - Desktop
GetDC( Nesto ) - Handle na prozor
Code:
// bool All, da li sa naslovnom linijom ili bez
// AHandle, da li prozor ili screen
// takodje proveri da li treba provera ako je All == true i AHandle == 0, ne znam sta bi se dogodilo
Graphics::TBitmap* ScreenCapture( bool All, HDC AHandle, int ALeft, int ATop, int AWidth, int AHeight )
{
TRect r = Rect(ALeft, ATop, AWidth, AHeight);
Graphics::TBitmap *bmp = new Graphics::TBitmap();
bmp->Width = r.Width();
bmp->Height = r.Height();
bmp->PixelFormat = pf32bit;
HDC hdc;
if ( All )
hdc = ::GetWindowDC( AHandle );
else
hdc = ::GetDC( AHandle );
::BitBlt( bmp->Canvas->Handle, 0, 0, bmp->Width, bmp->Height, hdc, ALeft, ATop, SRCCOPY);
::ReleaseDC( AHandle, hdc );
return bmp;
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Image1->Picture->Bitmap->Assign( ScreenCapture( true, Form1->Handle, 10, 10, 100, 100 ) );
}
... a moze i sa CopyRect(), ako uspem da odradim, stavicu ovde kao EDIT:
Code:
Graphics::TBitmap* ScreenCapture2( bool All, HDC AHandle, int ALeft, int ATop, int AWidth, int AHeight )
{
TRect r1 = Rect( ALeft, ATop, AWidth, AHeight );
Graphics::TBitmap *bmp = new Graphics::TBitmap();
bmp->Width = r1.Width();
bmp->Height = r1.Height();
bmp->PixelFormat = pf32bit;
TCanvas *ScreenCanvas = new TCanvas();
try
{
if ( All )
ScreenCanvas->Handle = ::GetWindowDC( AHandle );
else
ScreenCanvas->Handle = ::GetDC( AHandle );
try
{
TRect r2 = Rect( 0, 0, bmp->Width, bmp->Height );
bmp->Canvas->CopyRect( r2, ScreenCanvas, r1 );
}
__finally
{
::ReleaseDC( AHandle, ScreenCanvas->Handle );
}
}
__finally
{
delete ScreenCanvas;
}
return bmp;
}
[Ovu poruku je menjao X Files dana 23.05.2007. u 11:43 GMT+1]
[Ovu poruku je menjao X Files dana 23.05.2007. u 12:00 GMT+1]