//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Graphics::TBitmap* bmp = new Graphics::TBitmap();
TRect r(0,0,320,320);//设定相对当前窗口的裁剪矩形大小
TRect r2;
HDC dc;
AnsiString filename = "c://temp//2.bmp";
GetWindowRect(Handle,&r2);
bmp->Width = r.Right - r.Left;
bmp->Height = r.Bottom - r.Top;
dc = GetDC(GetDesktopWindow());
r.Left += r2.Left;
r.Top += r2.Top;
BitBlt(bmp->Canvas->Handle, 0, 0, bmp->Width, bmp->Height, dc, r.Left, r.Top, SRCCOPY);
ReleaseDC(GetDesktopWindow(), dc);
bmp->SaveToFile(filename);
delete bmp;
}
//---------------------------------------------------------------------------