开发者

Need help with scraping layered windows

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 = Create开发者_StackOverflow中文版CompatibleDC(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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜