Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
More screen print info
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00124126
Message ID:
00124378
Views:
18
>Explain in detail how to do a screen print in Visual FoxPro?

I have used the method Edward provided and it will work. I found that it would only work for me if my forms had Desktop set .T. and it would only print the entire FoxPro screen and not a single form.

I ran across a much better method of doing screen prints that relies a DLL (DIBAPI32.DLL) that MS provides with the WINCAP sample application. It can be found on the MSDN CD that came with Visual Studio or can be downloaded from the Microsoft.com. Search either for WINCAP.

Here is an example of the method I use to print a form:
* PrintWindow Method
LOCAL lnHWnd
LOCAL lcJobName
LOCAL lnRetVal

DECLARE INTEGER GetFocus IN WIN32API
DECLARE INTEGER PrintWindow IN DibApi32 ;
	INTEGER HWnd, ;
	INTEGER fPrintArea, ;
	INTEGER fPrintOpt, ;
	INTEGER wxScale, ;
	INTEGER wyScale, ;
	STRING @ szJobName
	
#DEFINE PW_WINDOW 1
#DEFINE PW_CLIENT 2
#DEFINE PW_BESTFIT 1
#DEFINE PW_STRETCHTOPAGE 2
#DEFINE PW_SCALE 3

lnHWnd = GetFocus()    && Use this to print a form
*lnHWnd = MainhWnd()   && Use this to print the VFP screen

lcJobName = "Print job name" + CHR(0)
lnRetVal = PrintWindow( lnHWnd, PW_WINDOW, PW_STRETCHTOPAGE, 0, 0, @lcJobName)
IF lnRetVal != 0
	IF lnRetVal != 6	&& 6 = User canceled printing
		= MESSAGEBOX("Unable to print the window" + CRLF + ;
						"PrintWindow API call returned " + STR(lnRetVal), ;
					MB_ICONEXCLAMATION + MB_OK, ;
					oApp.cApplicationName)
	ENDIF
ENDIF
RETURN
PW_WINDOW prints the entire window
PW_CLIENT prints just the client area

PW_STRETCHTOPAGE scales the screen print to fill the page.
PW_BESTFIT scales the printout for a best fit.

The screen print looks great especially using PW_STRETCHTOPAGE in landscape mode (the report generated using the copy the clipboard to a general field method was a little fuzzy).

The DLL also has a function to save a window as a bitmap file (DIB format). Here is how that works:
* SaveAsBitmap Method
LPARAMETERS tnHWnd, tcDefaultName
LOCAL tnHWnd
LOCAL lcDefaultName
LOCAL lnHBitmap && Handle to bitmap
LOCAL lcFileName	&& Name of file

LOCAL lnRetVal 	&& API call returned value

DECLARE INTEGER GetFocus IN WIN32API
DECLARE INTEGER CopyWindowToDIB IN DibAPI32 INTEGER hWnd, INTEGER fPrintArea
DECLARE INTEGER SaveDIB IN DibAPI32 INTEGER hBitmap, STRING @ cFileName

#DEFINE PW_WINDOW 1
#DEFINE PW_CLIENT 2

lnHWnd = GetFocus()
*lnHWnd = MainhWnd()
lcDefaultName = "Whatever"

lcFileName = PUTFILE("Save as Bitmap", lcDefaultName, "BMP")
IF EMPTY(lcFileName)
	RETURN
ENDIF

lnHBitmap = CopyWindowToDIB(lnHWnd, PW_WINDOW)
IF EMPTY(lnHBitmap)
	= MESSAGEBOX("Unable to create Bitmap from window", ;
				MB_ICON_EXCLAMATION + MB_OK, ;
				oApp.cApplicationName )
	RETURN
ENDIF

lnRetVal = SaveDIB(lnHBitmap, @lcFileName)
IF lnRetVal != 0
	= MESSAGEBOX("Unable to save the bitmap as: " + lcFileName + CRLF + ;
					"PrintDIB returned " + STR(lnRetVal), ;
				MB_ICONEXCLAMATION + MB_OK, ;
				oApp.cApplicationName)
ENDIF

RETURN
Steve Ruhl
CitiMortgage, Inc.
steven.ruhl@citibank.com Office
Steve@steven-ruhl.com Home
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform