|
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
Graphics::TBitmap *Bm = new Graphics::TBitmap();
ScreenShot(0,0,Screen->Width,Screen->Height,Bm);
DrawCursor(Bm);
Bm->SaveToFile("mouseCapture.bmp");
delete Bm;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ScreenShot(int x,int y,int width,int height,Graphics::TBitmap *Bm)
{
HDC dc;
LOGPALETTE *lpPal;
if(width==0 || height==0) return;
Bm->Width = width;
Bm->Height = height;
dc = GetDC(0);
if(dc == 0) return;
if(GetDeviceCaps(dc,RASTERCAPS)&RC_PALETTE == RC_PALETTE) {
lpPal = (LOGPALETTE*)malloc(sizeof(LOGPALETTE)+(255+sizeof(PALETTEENTRY)));
ZeroMemory(lpPal,sizeof(LOGPALETTE)+(255+sizeof(PALETTEENTRY)));
lpPal->palVersion = 0x300;
lpPal->palNumEntries = GetSystemPaletteEntries(dc,0,256,lpPal->palPalEntry);
if(lpPal->palNumEntries != 0) {
Bm->Palette = CreatePalette(lpPal);
}
free(lpPal);
}
BitBlt(Bm->Canvas->Handle,0,0,width,height,dc,x,y,SRCCOPY);
ReleaseDC(0,dc);
};
void __fastcall TForm1::DrawCursor(Graphics::TBitmap *ScreenShotBitmap)
{
TRect r;
TCursorInfo CI;
TIcon *Icon;
TIconInfo II;
r = ScreenShotBitmap->Canvas->ClipRect;
Icon = new TIcon();
CI.cbSize = sizeof(CI);
if(GetCursorInfo(&CI)) {
if(CI.flags == CURSOR_SHOWING) {
Icon->Handle = CopyIcon(CI.hCursor);
if(GetIconInfo(Icon->Handle,&II)) {
ScreenShotBitmap->Canvas->Draw(
CI.ptScreenPos.x - II.xHotspot - r.left,
CI.ptScreenPos.y - II.yHotspot - r.Top,
Icon
);
}
}
}
delete Icon;
}
|