On 4/13/2011 4:31 PM, Mike Copeland wrote:
> Okay, I confess I'm ignorant about DC and HWND and associated Windows stuff.
>
> With that said, here's what I need...
> I have an error routine that sends me an email when the user trips over
> an error. It has all the needed info but I thought it would be great to
> create a snapshot of the screen, save it to a file, and attach that
> image file to the error email. So far, I have that working, but the
> problem is that the routine uses a call to "GetFocus()" to determine the
> window "handle" it creates the snapshot from and sometimes that is not
> what I want. Sometimes I get a really nice snapshot of one of the DBI
> OCX controls on my Foxpro form, sometimes I get the form (that triggered
> the error)....which is what I wanted...and sometimes I get a snapshot of
> the form but it is empty. Totally blank without controls (buttons, text
> fields, etc.) This approach has a great potential, but so far has been
> minimal value.
Perhaps not the exact answer, but this is what's in the form.load of my
User Comments submission form. Credit to Cesar Chalom in comments below:
DODEFAULT()
#DEFINE HKEY_CURRENT_USER -2147483647 && BITSET(0,31)+1
LOCAL loGdiPlusX as Object, lcKey as String, lnError as Integer,
loRegistry as Object, loException as Exception, ;
lcValue as String, loCaptureBmp AS xfcBitmap, loForm as Form, n
as
Integer, lcCmd as String
TRY
loGdiPlusX = newobject("xfcSystem", ".\classes\system.vcx")
*loBmp = loGdiPlusX.Drawing.Bitmap.FromScreen()
*you can also use this syntax to capture the current form
*loBmp = loGdiPlusX.Drawing.Bitmap.FromScreen(Thisform)
*or this syntax to capture the vfp screen area
*loBmp = loGdiPlusX.Drawing.Bitmap.FromScreen(_screen)
*loBmp.Save("ScreenCapture.jpg",
loGdiPlusX.Drawing.Imaging.ImageFormat.Jpeg)
* clear out any previous screenshots
DELETE FILE CapturedForm*.*
* mjb 06-01-07 taken form Cesar Chalom's publishing on Foxite
n = 1
FOR EACH loForm IN _Screen.Forms
loCaptureBmp = loGdiPlusX.Drawing.Bitmap.FromScreen(loForm.HWnd)
loCaptureBmp.Save("CapturedForm" + TRANSFORM(n) + ".png",
loGdiPlusX.Drawing.Imaging.ImageFormat.Png)
n = n + 1
ENDFOR
lcCmd = [RUN /N 7za.exe a -tzip screenshots.zip CapturedForm*.png
-pabc!]
&lcCmd
this.lAttachImage = .T.
lcKey = "Software\MB Software Solutions\" + JUSTSTEM(oUtils.cAppName)
lcValue = SPACE(100)
loRegistry = NEWOBJECT("registry",".\classes\registry.vcx")
lnError =
loRegistry.GetRegKey("SupportEmail",@lcValue,lcKey,HKEY_CURRENT_USER)
IF NOT EMPTY(lcValue) THEN
this.cEmailaddress = ALLTRIM(lcValue)
ENDIF && NOT EMPTY(lcValue)
CATCH TO loException
this.lAttachImage = .F.
FINALLY
ENDTRY
--
Mike Babcock, MCP
MB Software Solutions, LLC
President, Chief Software Architect
http://mbsoftwaresolutions.com
http://fabmate.com
http://twitter.com/mbabcock16
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message:
http://leafe.com/archives/byMID/profox/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the
author, and do not constitute legal or medical advice. This statement is added
to the messages for those lawyers who are too stupid to see the obvious.