需要刮擦分层窗口的帮助

发布于 2024-10-24 21:57:04 字数 1089 浏览 4 评论 0原文

我正在尝试抓取(拍摄屏幕截图)分层窗口,但它似乎无法正常工作。有些分层窗口工作正常,有些则不然。以下是我的做法:

IntPtr display_dc = GetDC(IntPtr.Zero);
IntPtr bitmap_dc = CreateCompatibleDC(display_dc);
IntPtr bitmap = CreateCompatibleBitmap(display_dc, rect.Width, rect.Height);
IntPtr null_bitmap = SelectObject(bitmap_dc, bitmap);

IntPtr window_dc = GetWindowDC(Handle);
BitBlt(bitmap_dc, 0, 0, rect.Width, rect.Height, window_dc, 0, 0, 
    TernaryRasterOperations.SRCCOPY | TernaryRasterOperations.SRCPAINT);

ReleaseDC(Handle, window_dc);
SelectObject(bitmap_dc, null_bitmap);
DeleteDC(bitmap_dc);

using (Bitmap temp = Bitmap.FromHbitmap(bitmap))
{
     temp.Save(String.Format(@"C:\{0}_test.bmp", Handle.ToString("x")));
}

DeleteObject(bitmap);
ReleaseDC(IntPtr.Zero, display_dc);

问题是,当通过 UpdateLayeredWindow 更新分层窗口时,我为通过 SetLayeredWindowAttributes 创建的窗口获得了正确的图像,并获得了黑色位图。有人可以告诉我是否有一种方法可以通过 UpdateLayeredWindow win api 调用来抓取更新的分层窗口?

到目前为止,我的解决方法是拍摄整个屏幕的屏幕截图,然后从中复制窗口位图,问题是窗口应该始终位于顶部才能正常工作。

TIA

I'm trying to scrape (take a screen shot) a layered window and it doesn't seem work correctly. Some layered windows are working fine and some are not. Below is how I'm doing this:

IntPtr display_dc = GetDC(IntPtr.Zero);
IntPtr bitmap_dc = CreateCompatibleDC(display_dc);
IntPtr bitmap = CreateCompatibleBitmap(display_dc, rect.Width, rect.Height);
IntPtr null_bitmap = SelectObject(bitmap_dc, bitmap);

IntPtr window_dc = GetWindowDC(Handle);
BitBlt(bitmap_dc, 0, 0, rect.Width, rect.Height, window_dc, 0, 0, 
    TernaryRasterOperations.SRCCOPY | TernaryRasterOperations.SRCPAINT);

ReleaseDC(Handle, window_dc);
SelectObject(bitmap_dc, null_bitmap);
DeleteDC(bitmap_dc);

using (Bitmap temp = Bitmap.FromHbitmap(bitmap))
{
     temp.Save(String.Format(@"C:\{0}_test.bmp", Handle.ToString("x")));
}

DeleteObject(bitmap);
ReleaseDC(IntPtr.Zero, display_dc);

The problem is that, I'm getting correct images for windows created via SetLayeredWindowAttributes and a black bitmap when layered window is updated via UpdateLayeredWindow. Can somebody tell me if there us a way to scrape a layered windows updated via UpdateLayeredWindow win api call?

Workaround I have so far is to take screen shot of the entire screen and then copy the window bitmap from it, the problem is that window should be always on top for this to work correctly.

TIA

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文