WEB开发网
开发学院软件开发C++ 拷屏代码 阅读

拷屏代码

 2008-03-08 12:45:20 来源:WEB开发网   
核心提示:TCanvas *dtCanvas = new TCanvas; dtCanvas->Handle=GetDC(0); Graphics::TBitmap *bitmap=new Graphics::TBitmap; bitmap->Width=Width; bitmap->Height=Height

  TCanvas *dtCanvas = new TCanvas;
dtCanvas->Handle=GetDC(0);

Graphics::TBitmap *bitmap=new Graphics::TBitmap;
bitmap->Width=Width;
bitmap->Height=Height;

int nColors=GetDeviceCaps(Canvas->Handle,SIZEPALETTE);
LOGPALETTE* logPal=(LOGPALETTE*)new Byte[sizeof(LOGPALETTE)+(nColors-1)*sizeof(PALETTEENTRY)];
logPal->palVersion=0x300; logPal->palNumEntries=(Word)nColors;
GetSystemPaletteEntries(Canvas->Handle,0,nColors,logPal->palPalEntry);
bitmap->Palette=CreatePalette(logPal);
delete[] logPal;

TRect src=BoundsRect;
TRect dest=Rect(0,0,Width,Height);
bitmap->Canvas->CopyRect(dest,dtCanvas,src);

bitmap->SaveToFile("Screen.bmp");

delete bitmap;
delete dtCanvas;

Tags:代码

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接