Results 1 to 8 of 8

Thread: [RESOLVED] Capture a screen area underneath a Form

  1. #1

    Thread Starter
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Resolved [RESOLVED] Capture a screen area underneath a Form

    The application I am making, a screen magnifier, requires a partly transparent Form to remain visible but to capture part of the screen underneath the Form. This is easy to do in VB.Net using Graphics.CopyFromScreen, but it has one drawback: CopyFromScreen can't "see" other Windows Forms with opacity less than 1 -- in other words, anything with partial transparency. The only other method I know to capture an area of screen, using BitBlt, captures exactly the pixels that are visible on the screen; but this requires the Form to be hidden during capturing. That causes ugly blinking of the magnifier.

    Can anyone here think of another way to capture an area of screen "underneath" a visible form? For example, is there some API-based method to capture all the virtual window rectangles that intersect with the area to be captured, and to use that data to build up an image of what would be visible if the Form is hidden?

    BB

  2. #2
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Capture a screen area underneath a Form

    Hey!

    Not sure if this will help, but searching for magnifying glass here I found this: http://www.vbforums.com/showthread.php?t=368322

    The code is mixed in with BB tags, but there is the attachment as well so might be easier reading it from there!


    Has someone helped you? Then you can Rate their helpful post.

  3. #3
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Capture a screen area underneath a Form

    Also just found this: http://www.vbforums.com/showthread.p...gnifying+glass

    Looks even more promising


    Has someone helped you? Then you can Rate their helpful post.

  4. #4
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Capture a screen area underneath a Form

    Quote Originally Posted by manavo11 View Post
    Also just found this: http://www.vbforums.com/showthread.p...gnifying+glass

    Looks even more promising
    To capture layered windows in that post I changed the BitBlt call to vbSrcCopy Or CAPTUREBLT in Sub UpDateImage().


    Code:
    Private Const CAPTUREBLT As Long = &H40000000

  5. #5

    Thread Starter
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Capture a screen area underneath a Form

    Thanks manovo11 and Edgemeal for your attention to this question. I have been reading further but so far I haven't seen signs of an alternative to either BitBlt with ROP = SRCCOPY OR CAPTUREBLT or GDI+'s CopyFromScreen. I suppose I ought to look at WPF too, but that will have to wait. I now realize I could improve the "blinking" problem in several ways -- use a separate window area to magnify the area round the mouse cursor, or take advantage of a memory copy of the whole screen as in Edgemeal's code. In fact it's not too bad as long as the area of the blink is small and the blink rate isn't too fast.

    Unlike CopyFromScreen, BitBlt with CaptureBLT can detect Forms with Opacity<100% as long as the area isn't covered; I'm planning to try that out with per-pixel alpha blended windows too. Unfortunately I've found it cannot see certain Web content displayed in a .Net WebBrowser control, such as the screen text and thumbnails in YouTube (but it does get the Flash video). CopyFromScreen performs better in that respect. I know next to nothing about web browser technicalities (ActiveX?) or about DCs etc. So I'd be glad of any suggestions for overcoming that problem.

    Meanwhile it looks like I am stuck with two imperfect techniques. One can't capture transparent, the other can't capture certain web material. I suppose I could offer two modes, one with BitBlt and the other with CopyFromScreen but that is hardly a seamless user exerience. I want a magnifier that will just magnify whatever's on the screen

    BB

  6. #6
    New Member
    Join Date
    Nov 2008
    Posts
    3

    Re: Capture a screen area underneath a Form

    I use Printwindow. It copies the entire window, even if the window if off screen or beneath another window. I'm not sure about web stuff. Hope that helps.

    http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx

  7. #7
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Capture a screen area underneath a Form

    Quote Originally Posted by McBluffin View Post
    I use Printwindow. It copies the entire window, even if the window if off screen or beneath another window. I'm not sure about web stuff. Hope that helps.

    http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx
    Printwindow doesn't work as expected on layered windows or where opacity has been set AFAIK.

  8. #8

    Thread Starter
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Capture a screen area underneath a Form

    Thanks for the suggestion McBluffin. I wondered about PrintWindow but I clearly needed to capture the whole stack of windows under the form including transparent ones.

    Anyway, it turns out that the failure of BitBlt + SrcCopy Or CaptureBlt wasn't a matter of web content. It only happens with the VS2008 WebBrowser (Version 2.something) which I was using and not to FireFox, IE7 or anthing else I have tried. The WebBrowser in VS2010 (Version 4.something) is also okay and so is WPF.

    I suppose I can live without capturing WebBrowser2 displays and their ilk. Still, I wonder how it is that Graphics.CopyFromscreen, which is supposed to be a managed wrapper for BitBlt, does succeed in capturing the blighters?

    Now I realise that the problem of having to hide the part of the form over the area captured is largely a question of design. So I can consider this thread resolved.

    EDIT: by the way, both BitBlt with CaptureBlt and CopyFromScreen work in their own way with layered windows with per-pixel alpha. CaptureBlt captures everything, CopyFromScreen ignores pixels with alpha < 255.

    Thanks all for your help. BB
    Last edited by boops boops; Sep 1st, 2010 at 09:26 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width