There was an article in the November 2008 issue of FoxRockx that showed how to do it using GDI+. (Who says commenting your code is never helpful? :-) It shows how to capture the active form or the entire VFP window and save to the Windows desktop.
--
rk -----Original Message----- From: ProfoxTech [mailto:profoxtech-bounces@leafe.com] On Behalf Of Mike Copeland Sent: Friday, October 28, 2016 1:28 PM To: profoxtech@leafe.com Subject: Re: Taking a screenshot of "yourself"
Man-wai Chang wrote:
Is there a VFP function that does it? Win32API needed?
Here's what I use. It creates a snapshot of the entire screen and saves it as "error.emf" which is a bit-map format that compresses extremely well. Mike ======================== PROCEDURE screensnap DECLARE INTEGER GetFocus IN user32 DECLARE INTEGER ReleaseDC IN user32 INTEGER, INTEGER DECLARE INTEGER GetWindowRect IN user32 INTEGER, STRING @ DECLARE INTEGER GetDeviceCaps IN gdi32 INTEGER, INTEGER DECLARE INTEGER CloseEnhMetaFile IN gdi32 INTEGER DECLARE INTEGER DeleteEnhMetaFile IN gdi32 INTEGER DECLARE INTEGER GetWindowDC IN user32 INTEGER DECLARE INTEGER CreateEnhMetaFile IN gdi32 INTEGER, STRING, STRING @, STRING DECLARE INTEGER BitBlt IN gdi32 INTEGER, INTEGER, INTEGER, INTEGER, INTEGER, INTEGER, INTEGER, INTEGER, INTEGER hwndsrc= &main..HWND hdcsrc = getwindowdc(hwndsrc) hsize = getdevicecaps(hdcsrc, 4)*100 vsize = getdevicecaps(hdcsrc, 6)*100 hres = getdevicecaps(hdcsrc, 8) vres = getdevicecaps(hdcsrc, 10) rcsrc = REPLICATE(CHR(0), 16) = getwindowrect(hwndsrc, @rcsrc) nleftsrc = buf2dword(SUBSTR(rcsrc, 1, 4)) ntopsrc = buf2dword(SUBSTR(rcsrc, 5, 4)) nrightsrc = buf2dword(SUBSTR(rcsrc, 9, 4)) nbotsrc = buf2dword(SUBSTR(rcsrc, 13, 4)) nrightsrc = nrightsrc-nleftsrc nbotsrc = nbotsrc-ntopsrc STORE 0 TO nleftsrc, ntopsrc nmetaleft = (nleftsrc*hsize)/hres nmetatop = (ntopsrc*vsize)/vres nmetaright = (nrightsrc*hsize)/hres nmetabot = (nbotsrc*vsize)/vres rcmeta = num2dword(nmetaleft)+num2dword(nmetatop)+num2dword(nmetaright)+num2dword(nmetabot) hmetadc = createenhmetafile(hdcsrc, "error.emf", @rcmeta, .NULL.) = bitblt(hmetadc, 0, 0, nrightsrc, nbotsrc, hdcsrc, 0, 0, 13369376) hmetafile = closeenhmetafile(hmetadc) = deleteenhmetafile(hmetafile) = releasedc(hwndsrc, hdcsrc) ENDPROC