Friday, October 24, 2014

Easy ways to Capture images

I have not blogged for a long time and you guys know why.  Anyway, here is something that may be useful to you so I am making this entry here.  This is about FoxForm shared to us in Foxite Forum.  This combined with other things will allow us to easily capture our form, our app's screen and the desktop itself; with only few lines of codes.  In addition, you can send those captured images as well direct to printer.  Here are the steps:




  1. You have to download FoxForm in Foxite (you have to be a member).   Go to its download section and search for FoxForm (original codes written and submitted by Eric Den Doop).  Once downloaded, extract foxform.dll to your app's main folder and register it via going to CMD, going to your main app's folder and typing regsvr32 /foxform.dll.  You have to have an administrative right to register it.
  2. Once it is registered, here are some easy ways to capture things.  Anyway, let us declare some things first like ShellExecute()


Declare Integer ShellExecute In shell32.dll ;
      INTEGER hndWin, ;
      STRING cAction, ;
      STRING cFileName, ;
      STRING cParams, ;
      STRING cDir, ;
      INTEGER nShowWin

Okay we are on the go, let us start with capturing

Capture your active form

Local loTmp, HWnd, lcFile
loTmp = CREATEOBJECT("FoxForm.Form")
HWnd = _WhToHwnd(_wfindtitl(Thisform.Caption))
lcFile = Addbs(Getenv("TMP"))+Sys(3)+".bmp"
loTmp.SaveAsBMP(HWnd,m.lcFile)
* Show the result outright
ShellExecute(0,"open",m.lcFile,"","",1)

Capture your entire's app screen

Local loTmp, HWnd, lcFile
loTmp = CREATEOBJECT("FoxForm.Form")
HWnd = _WhToHwnd(_wfindtitl(_Screen.Caption))
lcFile = Addbs(Getenv("TMP"))+Sys(3)+".bmp"
loTmp.SaveAsBMP(HWnd,m.lcFile)
ShellExecute(0,"open",m.lcFile,"","",1)  

There may be a chance that your app's screen is not on a maximized state, so if what you really wanted is to capture the entire screen without relying onto your app's WindowState?

Capture entire desktop screen

* Declare this first if not yet declared somewhere else
Declare Integer GetDesktopWindow In user32

LOCAL loTmp, hWnd, lcFile
loTmp = CREATEOBJECT("FoxForm.Form")
hWnd = GetDeskTopWindow()
lcFile = ADDBS(GETENV("TMP"))+SYS(3)+".bmp"
loTmp.SaveAsBMP(hWnd,m.lcFile)
ShellExecute(0,"open",m.lcFile,"","",1)  

And finally, here is how you can send the result direct to printer instead of into a file

Capture Desktop and Print


Declare Integer GetDesktopWindow In user32

LOCAL loTmp, hWnd
loTmp = CREATEOBJECT("FoxForm.Form")
hWnd = GetDeskTopWindow()
lotmp.SendToPrinter(hWnd)

Although we can likewise use ShellExecute() for that

Declare Integer GetDesktopWindow In user32

LOCAL loTmp, hWnd, lcFile
loTmp = CREATEOBJECT("FoxForm.Form")
hWnd = GetDeskTopWindow()
lcFile = ADDBS(GETENV("TMP"))+SYS(3)+".bmp"
loTmp.SaveAsBMP(hWnd,m.lcFile)
ShellExecute(0,"print",m.lcFile,"","",1)  


The first one though allows us to send to the printer direct while the 2nd one using ShellExecute() requires us to save the result first onto a file then later send to printer.

When I found the original codes inside Foxite, it uses Foxtools.fll.  But when I tried it here, it works without it.  In case it do not work properly on your end though, then you have to add this line on top

SET LIBRARY TO HOME()+"foxtools.fll" ADDITIVE 


Cheers!

No comments:

Post a Comment