19,469
社区成员
发帖
与我相关
我的任务
分享
typedef BOOL ( __stdcall *pPrintWindow )(HWND hWnd,HDC hdcBlt,UINT nFlags);
//RECT rect;
HMODULE h;
h = LoadLibrary( L"user32.dll" );
pPrintWindow p;
if( h )
{
p = ( pPrintWindow )::GetProcAddress( h, "PrintWindow" );
}
p(hWnd,*bitcdc,0);
CDC memDC;//内存DC
memDC.CreateCompatibleDC(pDC);
CBitmap memBitmap, *oldmemBitmap;、
memBitmap.CreateCompatibleBitmap(pDC, width, height);
oldmemBitmap = memDC.SelectObject(&memBitmap);
这个部分就是截图的:
CDC *pDC = CDC::FromHandle(::GetDC(hwnd));
int BitPerPixel = pDC->GetDeviceCaps(BITSPIXEL);
if(width==0 && height==0)
{
width = pDC->GetDeviceCaps(HORZRES);
height= pDC->GetDeviceCaps(VERTRES);
}
memDC.BitBlt(0, 0, Width, Height, pDC, 0, 0, SRCCOPY);
pDC->DeleteObject();
销毁的时候:
memDC.SelectObject(oldmemBitmap);
每次贴图区域OnDraw或OnPaint时,
把MemDC的图Bitblt过去。这样的方法比较规范。
你用的PrintScreen是微软没有公开的函数,使用时可能需要考虑许多别的情况,比如绘制的同步什么的,也许那些窗口还来不及绘制自己就函数就结束了。