* 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 RETURNPW_WINDOW prints the entire window
* 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