GDIPlus: Using FromScreen() to capture a scrollable form

Topics: General
Oct 15, 2008 at 1:54 PM
I have been using System.Drawing.Bitmap.FromScreen() to capture an image of a VFP form. It works fine if the form is not scrollable. But I can't get it to work with a scrollable form.

Let's say I have a form which is 400 x 400, with objects all over the form. At run time, I resize it to 200 x 200, and add scroll bars to let the user navigate. I'd like to capture the entire 400 x 400 area, but whatever values I pass to FromScreen(), I can't get it to give more than 200 x 200 (give or take the title bar, borders, etc.)

Does anyone know how I can go about this? Thanks in advance.

Mike Lewis
Oct 15, 2008 at 6:11 PM
Hi Mike, just a quick idea that may solve your problem.

You can try the following:
1) Right before your screen capture, lock screen updates using WINAPI function LockWindowUpdate, syntax follows:
       
        DECLARE INTEGER LockWindowUpdate IN WIN32API INTEGER lnhandle
        = LockWindowUpdate(_VFP.hwnd)

2) Once screen updates are locked, resize your form to 400 x 400, obviously the screen will continue to look as if the form is at 200 x 200 due to screen lock.
3) Capture the screen using System.Drawing.Bitmap.FromScreen()
4) Revert form size to 200 x 200
5) Remove screen lock by issuing:  = LockWindowUpdate(0)

Try this, it may solve your problem.

Victor Espinoza




Oct 16, 2008 at 8:48 AM
Hi Victor,

Thanks for your reply.

I followed your advice, but unfortunately it didn't work. What happened was that the image was the correct size (400 x 400 in my example), but only the 200 x 200 area was visible. The rest of the image was solid black.

I should have mentioned that my form fills the client area of _SCREEN. So even after I programmatically increased its size, the physical size stayed the same. That might explain the solid black areas.

Still, it was worth a try. If you've got any other ideas, I'd be glad to hear them, otherwise I might have to  look for some other solution.

Mike