WinAPI/GDI:为什么大窗口的快照包括任务栏?

发布于 2024-09-09 03:49:24 字数 722 浏览 2 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绮筵 2024-09-16 03:49:24

这是正常的,这样的屏幕截图可以准确地显示您在显示器上看到的内容。包括任务栏。您需要将捕获的区域限制在要捕获的窗口的边界内。使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文