This project is read-only.

GdiPlusX - Capture form's object

Topics: General, Attention VFPX Admins
Jun 17, 2008 at 9:39 AM
Hi,
I need to capture and print the image of an object in a form. I'm using  .Drawing.Bitmap.FromScreen(Thisform.Viewer) 
This function does not work if my form has a menu or has no border or HalfHeightCaption = .T. . I get a cropped image.

Can anyone help with this problem ?
Thanks
Jun 17, 2008 at 1:12 PM
Hi SP,

Thanks for reporting this.
This function will probably need some tweaks for the situations you've mentioned here.
I hope to work on this in the next few days, and probably the fix will be included in the next update.

Is that ok for you, Bo ?
Jun 17, 2008 at 1:31 PM

It’ ok for me. It would be interesting to have a version of Bitmap.FromScreen() where passing the form and the coordinates (top, left, width, height) to  capture only a part of the form. Actually to achieve this functionality I have to add a temporary object to the form, call Bitmap.FromScreen() with this object as argument and then remove the object just added..

Thanks.


Jun 17, 2008 at 2:09 PM


sp wrote:

It’ ok for me. It would be interesting to have a version of Bitmap.FromScreen() where passing the form and the coordinates (top, left, width, height) to  capture only a part of the form. Actually to achieve this functionality I have to add a temporary object to the form, call Bitmap.FromScreen() with this object as argument and then remove the object just added..

Thanks.


Nice idea !
I'll try to add this as well !
Jun 17, 2008 at 4:15 PM
I've just talked about this with Carlos Alloatti, and we got the conclusion that the problem must be in the HWND. As you're working with a TopLevel form, the function should deal with it for this case, and also when the form contains scrollbars.

That will be probably a very easy and simple fix, I hope to do it tonight.
Jun 17, 2008 at 5:10 PM
Just talked to Bo. We think that the problem has to do with both the need to use the client HWND (if the client area is a window)  and the wrong HDC being retrieved. Also, we're thinking that the method should be modified so that if you sent in Thisform.Hwnd then the x, y, w, h will be based on the entire window, whereas if just Thisform is sent in then the dimensions would be based on the client area of the form (form coordinates). This allows a developer to easily get a screenshot of the entire window or just the form's design area or any portion thereof. The problem with the object coordinates will be addressed as well.
Jun 17, 2008 at 5:11 PM
I think the problem is that we are using GetWindowDC and subtracting the title bar height and border width. We should be using GetDC instead.

GetWindowDC returns a device context for the entire window, borders, title bars and all. GetDC returns just the "paintable" area of the Window.
Jun 17, 2008 at 6:31 PM

Hey Bo,

Have a look at this piece of code, that is the relevant part in our problem:


 

CASE VARTYPE(m.tHWnd) = "O" AND m.tHWnd.BaseClass = "Form"
m.lnFunctionType = 2

&& VFP Form

m.loForm = m.tHWnd
IF m.tlEnsureVisible
   IF m.loForm.Left < 0 OR m.loForm.Top < 0
   *!ToDo: Need to check if too far right also
      m.lnLeft0 = m.loForm.Left
      m.lnTop0 = m.loForm.Top
      m.loForm.Move(0,0)
      m.llMoved = .T.
   ENDIF
ENDIF

m.tHWnd = loForm.HWnd

 

 


 

See the last line of code ?
There I'm using the Form HWND, without checking if it is a TopLevel or a form that contains ScrollBars.

So, I stand with the HWND problem, for the problem related by "SP", the original question.

About the difference betwee GetDC and GetWindowDC, for me, it does not matter, I would leave this to the users to choose, maybe adding a flag for it ? 

Jun 18, 2008 at 12:18 AM
I believe Bo was speaking directly to the clipped image based on the object coordinates being figure from the entire window instead of the form's client area. I think the thinking here is that if it used the client area then there would be no need to have to figure out the height of a title bar, menu bar, or anything else in order to figure out where the object is.