Print the contents of the form in the VFP

xiaoxiao2021-03-06  76

Print the contents of the form in the VFP

********************************* - Program Name: Will form content directly Print - ** - print the contents of the window as a bitmap - ** - author: unknown source Forum Posts - ** - Usage: in form Execute the program or - **: in a form of a command - ** Press DO Printform.PRG - ** - Honghoo.Net to organize, arrangement - * ************************ - Define constants

#DEFINE LOGPIXELSX 88 # DEFINE LOGPIXELSY 90 # DEFINE PHYSICALOFFSETX 112 # DEFINE PHYSICALOFFSETY 113 # DEFINE SRCCOPY 13369376 # DEFINE DIB_RGB_COLORS 0 * - DO decl subroutine calls in the present block * - definition of variables PRIVATE pnWidth, pnHeight, lnBitsPerPixel, lnBytesPerScanSTORE 0 tO pnWidth, pnHeight, lnBitsPerPixel, lnBytesPerScanLOCAL hwnd, hFormDC, hPrnDC, hMemDC, hMemBmp, hSavedBitmap ,; xOffsPrn, yOffsPrn, xScale, yScale, lcDocInfo, lcBInfo, lpBitsArray * - obtained coordinate offset printer apparatus hPrnDC = getDefaultPrnDC ( ) && No error Check XoffSprn = getDeviceCaps (Hprn = getDeviceCaps (HPRNDC, PhysicalOffSety) * - Get window handles of the screen, and their width, height, etc..

hwnd = GetFocus () && a window with keyboard focushFormDC = GetWindowDC (hwnd) = getWinRect (hwnd, @pnWidth, @pnHeight) * - xScale = GetDeviceCaps obtained scaling value depending on the screen and printer (hPrnDC, LOGPIXELSX) / GetDeviceCaps (hFormDC, LOGPIXELSX) yScale = GetDeviceCaps (hPrnDC, LOGPIXELSY) / GetDeviceCaps (hFormDC, LOGPIXELSY) * - the contents of the screen to create the bitmap image data hMemDC = CreateCompatibleDC (hFormDC) hMemBmp = CreateCompatibleBitmap (hFormDC, pnWidth, pnHeight) hSavedBitmap = SelectObject (HMEMDC, HMEMBMP) * - copy bitmap data from the screen to the virtual device = Bitblt (HMEMDC, 0, 0, PnWidth, PnHeight, HFORMDC, 0, 0, Srccopy) = SelectObject (HMEMDC, HSAVedbitmap) * Retrieving Bits from the compatible bitmap into a buffer * as a device-independent bitmap (DIB) with a BitsPerPixel value * as one of the printer device contextlcBInfo = InitBitmapInfo (hPrnDC) lpBitsArray = InitBitsArray () = GetDIBits (hMemDC, hMemBmp, 0, pnHeight, LPBITSARRAY, @lcbinfo, dib_rgb_colors) LCDocinfo = CHR (20) Repli (CHR (0), 19) && Docinfo Struct - 20 Bytesif StartDoc (hprndc, @lcdocinfo)> 0 = StartPage (HPRNDC) = Stret chDIBits (hPrnDC, xOffsPrn, yOffsPrn ,; xOffsPrn Int (xScale * pnWidth) ,; yOffsPrn Int (yScale * pnHeight) ,; 0,0, pnWidth, pnHeight ,; lpBitsArray, @lcBInfo, DIB_RGB_COLORS, SRCCOPY) = EndPage ( hPrnDC) = EndDoc (hPrnDC) ENDIF * - free system resources when you quit = GlobalFree (lpBitsArray) = DeleteObject (hMemBmp) = DeleteDC (hMemDC) = DeleteDC (hPrnDC) = ReleaseDC (hwnd, hFormDC) RETURNPROCEDURE getWinRect (lnHwnd, lnWidth, lnHeight) * - returns a handle to the specified width and height of the window #DEFINE maxDword 4294967295 && 0xffffffff LOCAL lpRect, lnLeft, lnTop, lnRight, lnBottom lpRect = REPLI (Chr (0), 16) = GetWindowRect (lnHwnd, @lpRect) lnRight =

buf2dword (SUBSTR (lpRect, 9,4)) lnBottom = buf2dword (SUBSTR (lpRect, 13,4)) lnLeft = buf2dword (SUBSTR (lpRect, 1,4)) IF lnLeft> lnRight lnLeft = lnLeft - maxDword ENDIF lnTop = buf2dword (SUBSTR (lpRect, 5,4)) IF lnTop> lnBottom lnTop = lnTop - maxDword ENDIF lnWidth = lnRight - lnLeft lnHeight = lnBottom - lnTop RETURNFUNCTION getDefaultPrnDC * returns device context for the default printer #DEFINE PD_RETURNDC 256 #DEFINE PD_RETURNDEFAULT 1024 LOCAL lcStruct , lnFlags lnFlags = PD_RETURNDEFAULT PD_RETURNDC * fill PRINTDLG structure lcStruct = num2dword (66) Repli (Chr (0), 16) ; num2dword (lnFlags) Repli (Chr (0), 42) IF PrintDlg (@lcStruct) < > 0 RETURN buf2dword (SUBSTR (lcStruct, 17,4)) ENDIF RETURN 0FUNCTION InitBitmapInfo (hTargetDC) #DEFINE BI_RGB 0 #DEFINE RGBQUAD_SIZE 4 && RGBQUAD #DEFINE BHDR_SIZE 40 && BITMAPINFOHEADER LOCAL lnRgbQuadSize, lcRgbQuad, lcBIHdr * use printer BitPerPixel value lnBitsPerPixel = 24 * Initializing BitmapInfoHeader Str ucture lcBIHdr = num2dword (BHDR_SIZE) ; num2dword (pnWidth) num2dword (pnHeight) ; num2word (1) num2word (lnBitsPerPixel) ; num2dword (BI_RGB) Repli (Chr (0), 20) * creating a buffer for the color table IF lnBitsPerPixel <= 8 lnRgbQuadSize = (2 ^ lnBitsPerPixel) * RGBQUAD_SIZE lcRgbQuad = Repli (Chr (0), lnRgbQuadSize) ELSE lcRgbQuad = "" ENDIF RETURN lcBIHdr lcRgbQuadPROCEDURE InitBitsArray () #DEFINE GMEM_FIXED 0 LOCAL lnPtr, lnAllocSize * MAKING SURE THE VALUE IS DWORD-ALIGNED LNBYTESPERSCAN = INT (PnWidth * LnBitsPixel) / 8) IF MOD (Lnbytesperscan, 4) <> 0 lnbytesperscan =

lnBytesPerScan 4 - Mod (lnBytesPerScan, 4) ENDIF lnAllocSize = pnHeight * lnBytesPerScan lnPtr = GlobalAlloc (GMEM_FIXED, lnAllocSize) = ZeroMemory (lnPtr, lnAllocSize) RETURN lnPtrFUNCTION num2word (lnValue) RETURN Chr (MOD (m.lnValue, 256)) CHR (INT (M.LnValue / 256)) Function Num2dword (LnValue) #define M0 256 #define M1 65536 #define M2 16777216 Local B0, B1, B2, B3 B3 = Int (LnValue / M2) B2 = Int ((LnValue) - B3 * m2) / m1) B1 = INT ((LnValue - B3 * M2 - B2 * M1) / M0) B0 = MOD (LnValue, M0) RETURN CHR (B0) CHR (B1) CHR (B2) CHR (B3) Function BUF2WORD (LCBuffer) Return ASC (Substr (LCBuffer, 1, 1)) ; ASC (Substr (LCBuffer, 2, 1)) * 256Function BUF2DWORD (LCBuffer) Return ASC (Substr (LCBuffer, 1, 1 ))) ; ASC (Substr (LCBuffer, 2, 1)) * 256 ; ASC (Substr (LCBuffer, 3, 1)) * 65536 ; ASC (Substr (LCBuffer, 4, 1)) * 16777216Procedure Decl && So Many of Them Decless Here Declare Integer Getfocus In User32 Declare Integer Enddoc in GDI32 Integer HDC Declare Integer GetWindowdc in User32 Integer HWnd Declar E INTEGER DeleteObject IN gdi32 INTEGER hObject DECLARE INTEGER CreateCompatibleDC IN gdi32 INTEGER hdc DECLARE INTEGER ReleaseDC IN user32 INTEGER hwnd, INTEGER hdc DECLARE INTEGER GetWindowRect IN user32 INTEGER hwnd, STRING @lpRect DECLARE INTEGER GlobalAlloc IN kernel32 INTEGER wFlags, INTEGER dwBytes DECLARE INTEGER GetDeviceCaps IN gdi32 INTEGER hdc, INTEGER nIndex DECLARE INTEGER SelectObject IN gdi32 INTEGER hdc, INTEGER hObject DECLARE INTEGER StartDoc IN gdi32 INTEGER hdc, STRING @ lpdi DECLARE INTEGER GlobalFree IN kernel32 INTEGER hMem DECLARE INTEGER PrintDlg IN comdlg32 STRING @

转载请注明原文地址:https://www.9cbs.com/read-122866.html

New Post(0)