WinAPI/GDI:为什么大窗口的快照包括任务栏?
我正在使用 GDI+ 拍摄窗口快照,代码是:
CComBSTR bstrfname (fname);
HDC hdc = CreateCompatibleDC (hDC);
HBITMAP hbmp = CreateCompatibleBitmap (hDC, CFG_WIDTH, CFG_HEIGHT);
HBITMAP hbmp0 = (HBITMAP)SelectObject (hdc, hbmp);
BitBlt (hdc, 0, 0, CFG_WIDTH, CFG_HEIGHT, hDC, 0, 0, SRCCOPY);
Gdiplus::Bitmap *bmp = new Gdiplus::Bitmap (hbmp, NULL);
CLSID encoderClsid; GetEncoderClsid (L"image/png", &encoderClsid);
bmp->Save (bstrfname, &encoderClsid, NULL);
delete bmp;
SelectObject (hdc, hbmp0);
DeleteObject (hbmp);
DeleteDC (hdc);
hDC 之前设置的位置:
hWnd=CreateWindowEx(...); hDC=GetDC(hWnd);
这非常适合小窗口,但是一旦我尝试更大的窗口 比屏幕。
即任务栏也被保存。什么给了?
I am using GDI+ to take window snapshot, the code is:
CComBSTR bstrfname (fname);
HDC hdc = CreateCompatibleDC (hDC);
HBITMAP hbmp = CreateCompatibleBitmap (hDC, CFG_WIDTH, CFG_HEIGHT);
HBITMAP hbmp0 = (HBITMAP)SelectObject (hdc, hbmp);
BitBlt (hdc, 0, 0, CFG_WIDTH, CFG_HEIGHT, hDC, 0, 0, SRCCOPY);
Gdiplus::Bitmap *bmp = new Gdiplus::Bitmap (hbmp, NULL);
CLSID encoderClsid; GetEncoderClsid (L"image/png", &encoderClsid);
bmp->Save (bstrfname, &encoderClsid, NULL);
delete bmp;
SelectObject (hdc, hbmp0);
DeleteObject (hbmp);
DeleteDC (hdc);
where hDC is set before with:
hWnd=CreateWindowEx(...); hDC=GetDC(hWnd);
this works perfectly for small windows, but once I try windows bigger
than screen.
i.e. taskbar is getting saved too. what gives?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是正常的,这样的屏幕截图可以准确地显示您在显示器上看到的内容。包括任务栏。您需要将捕获的区域限制在要捕获的窗口的边界内。使用 GetWindowRect() 并相应地调整位图的大小和传递给 BitBlt() 的参数。
仅当目标窗口实现了 WM_PRINT 和 WM_PRINTCLIENT 消息时,PrintWindow 才能工作。易于实施但经常被忽视。
This is normal, a screen-shot like this gives you exactly what you are looking at on your monitor. Including the taskbar. You will need to restrict the area you capture to the bounds of the window you want to capture. Use GetWindowRect() and adjust the size of the bitmap and the arguments you pass to BitBlt() accordingly.
PrintWindow can only work if the target window implements the WM_PRINT and WM_PRINTCLIENT message. Easy to implement but often overlooked.