Fortune Telling Collection - Comprehensive fortune-telling - How to print vf form
How to print vf form
*-Program Name: Print Form Contents Directly-*
*-Print window contents as bitmap-*
*-Author of the program: unknown, reproduced by the source forum-*
*-Usage: You can execute the program in the form of-*
* Example: Commands in a Form-*
* press the button to execute the doprintform. PRG-*
*-define constants
# Define LOGPIXELSX 88
# Define LOGPIXELSY 90
# Define the physical offset X 1 12.
# Define physical offset 1 13
# Define SRCCOPY 13369376
# Define DIB_RGB_COLORS 0
*-Call the subprocess in this program segment.
Do decl
*-Define variables
Private pnWidth, pnHeight, lnBitsPerPixel, lnBytesPerScan
Store 0 in pnWidth, pnHeight, lnBitsPerPixel, lnBytesPerScan.
Local hwnd, hFormDC, hPrnDC, hMemDC, hMemBmp, hSavedBitmap.
xOffsPrn,yOffsPrn,xScale,yScale,lcDocInfo,lcBInfo,lpBitsArray
*-Get the coordinate offset of the printer device.
HPR NDC = getDefaultPrnDC()& amp; & No error checking was performed.
xOffsPrn = GetDeviceCaps(hPrnDC,PHYSICALOFFSETX)
yOffsPrn = GetDeviceCaps(hPrnDC,PHYSICALOFFSETY)
*-Get the window handles of the screen, as well as their width, height, etc.
hwnd = GetFocus()& amp; & Windows with keyboard focus
hFormDC = GetWindowDC(hwnd)
= getWinRect (hwnd,@pnWidth,@pnHeight)
*-Get the zoom value according to the screen and printer.
xScale = GetDeviceCaps(hPrnDC,LOGPIXELSX)/GetDeviceCaps(hFormDC,LOGPIXELSX)
yScale = GetDeviceCaps(hPrnDC,LOGPIXELSY)/GetDeviceCaps(hFormDC,LOGPIXELSY)
*-Create the screen content as bitmap image data.
hme MDC = CreateCompatibleDC(hFormDC)
hme mbmp = CreateCompatibleBitmap(hFormDC,pnWidth,pnHeight)
hSavedBitmap = select object(hme MDC,hMemBmp)
*-Copy bitmap data from the screen to the virtual device.
= BitBlt (hMemDC,0,0,pnWidth,pnHeight,hFormDC,0,0,SRCCOPY)
= SelectObject(hMemDC,hSavedBitmap)
* Retrieve the bits in the compatible bitmap into the buffer.
* as a device-independent bitmap (DIB) with BitsPerPixel value.
* as one of the printer device contexts
lcBInfo = InitBitmapInfo(hPrnDC)
lpBitsArray = InitBitsArray()
= GetDIBits (hMemDC,hMemBmp,0,pnHeight,;
lpBitsArray,@lcBInfo,DIB_RGB_COLORS)
LcDocInfo = Chr(20)+Repli(Chr(0),19) & docinfo structure-20 bytes.
IF StartDoc(hPrnDC,@ lcDocInfo)& gt; 0
= Start Page (hPrnDC)
= StretchDIBits (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
*-Release system resources when exiting.
= GlobalFree(lpBitsArray)
= delete object (hMemBmp)
= DeleteDC(hMemDC)
= DeleteDC(hPrnDC)
= ReleaseDC(hwnd,hFormDC)
return
Procedure getWinRect (lnHwnd, lnWidth, lnHeight)
*-Returns the width and height of the window with the specified handle.
# Define maxdword 4294967295 & 0xffffffff
Local lpRect, lnLeft, lnTop, lnRight, lnBottom
lpRect = REPLI (Chr(0), 16)
= GetWindowRect (lnHwnd,@lpRect)
lnRight = buf 2d word(SUBSTR(lpRect,9,4))
ln bottom = buf 2d word(SUBSTR(lpRect, 13,4))
lnLeft = buf2dword(SUBSTR(lpRect, 1,4))
If lnLeft & gtlnRight
lnLeft = lnLeft - maxDword
ENDIF
lnTop = buf2dword(SUBSTR(lpRect,5,4))
If lnTop & gtlnBottom
lnTop = lnTop - maxDword
ENDIF
lnWidth = lnRight - lnLeft
ln height = ln bottom-in top
return
Function getDefaultPrnDC
* Returns the device context of the default printer.
#DEFINE PD_RETURNDC 256
# DEFINE PD _ return default 1024
Local structure, marking
ln flags = PD _ return default+PD _ return DC
* fill PRINTDLG structure
LC struct = num 2 dword(66)+Repli(Chr(0), 16)+;
num2dword(lnFlags) + Repli(Chr(0),42)
IF print DLG(@ LC struct)& lt; & gt0
Returns buf2dword (SUBSTR(lcStruct,17,4))
ENDIF
Return 0
Function InitBitmapInfo(hTargetDC)
# define BI_RGB 0
# DEFINE RGBQUAD _ SIZE 4 & amp& ampRGBQUAD
# define bhdr _ size40 & ampbitmapinfoheader
Local lnRgbQuadSize, lcRgbQuad, lcBIHdr
* use the BitPerPixel value of the printer
lnBitsPerPixel = 24
* initialize BitmapInfoHeader structure
lcBIHdr = num 2 dword(BHDR _ SIZE)+;
num 2 dword(pn width)+num 2 dword(pn height)+;
num 2 word( 1)+num 2 word(lnBitsPerPixel)+;
num2dword(BI_RGB) + Repli(Chr(0),20)
* create a buffer for the color table
If lnbitsperpixel < = 8
lnrgbquadsize =(2^lnbitsperpixel)* rgbquad _ size
lcRgbQuad = Repli(Chr(0),lnRgbQuadSize)
other
lcRgbQuad = " "
ENDIF
Return lcBIHdr+lcRgbQuad
InitBitsArray () process
# Define GMEM _ Fixed 0
Local lnPtr, lnAllocSize
* Make sure the value is DWORD aligned.
lnBytesPerScan = Int((pn width * lnBitsPerPixel)/8)
IF Mod(lnBytesPerScan,4)& lt; & gt0
lnBytesPerScan = lnBytesPerScan+4-Mod(lnBytesPerScan,4)
ENDIF
lnAllocSize = pn height * lnBytesPerScan
LnPtr = global alloc(GMEM _ fixed, lnAllocSize)
= ZeroMemory (lnPtr,lnAllocSize)
Return input
Function num2word (lnvalue)
RETURN Chr(MOD(m.lnvalue,256)) + CHR(INT(m.lnvalue/256))
Function num2dword (lnvalue)
# Definition m0 256
# Definition m 1 65536
# Definition m2 167772 16
Local b0, b 1, b2, b3
b3 = Int(lnvalue/m2)
B2 = Int((ln value-B3 * m2)/m 1)
b 1 = Int((ln value-B3 * m2-B2 * m 1)/m0)
b0 = Mod(lnvalue,m0)
Returns chr (B0)+chr (b1)+chr (B2)+chr (B3).
Function buf2word (lcBuffer)
Returns Asc(SUBSTR(lcBuffer, 1,1))+;
Asc(SUBSTR(lcBuffer,2, 1)) * 256
Function buf2dword (lcBuffer)
Returns Asc(SUBSTR(lcBuffer, 1,1))+;
Asc(SUBSTR(lcBuffer,2, 1))* 256+;
Asc(SUBSTR(lcBuffer,3, 1))* 65536+;
Asc(SUBSTR(lcBuffer,4, 1)) * 167772 16
The program decl & & many of them declare here.
Declare the integer GetFocus in user32.
Declaring integer EndDoc in gdi32 integer hdc
Declare the integer GetWindowDC in user32 INTEGER hwnd.
Declare INTEGER DeleteObject in gdi32 INTEGER hObject.
Declaring INTEGER CreateCompatibleDC in gdi32 INTEGER hdc
Declare integer ReleaseDC in user32 INTEGER hwnd, INTEGER hdc.
Declare INTEGER GetWindowRect, STRING @lpRect in user32 INTEGER hwnd.
Declare INTEGER GlobalAlloc in kernel32 INTEGER wFlags, INTEGER dwBytes.
Declare integer GetDeviceCaps INTEGER hdc, INTEGER nIndex in gdi32.
Declare INTEGER SelectObject in gdi32 INTEGER hdc, INTEGER hObject.
Declare the integer StartDoc, STRING @ lpdi in gdi32 INTEGER hdc.
Declare the integer GlobalFree in kernel32 INTEGER hMem.
Declare integer PrintDlg in comdlg32 STRING @ lppd.
Declare the integer DeleteDC in gdi32 integer hdc.
Declaring an integer start page in gdi32 integer hdc
Declaring an integer end page in gdi32 integer hdc
Declare RtlZeroMemory in kernel32 as ZeroMemory.
Integer target, integer numeric byte
Declare the integer CreateCompatibleBitmap in gdi32.
Integer hdc, integer nWidth, integer nHeight
Declare integer BitBlt in gdi32
Integer hDestDC, integer x, integer y,;
INTEGER nWidth,INTEGER nHeight,INTEGER hSrcDC,;
Integer xSrc, integer ySrc, integer dwRop
Declare the integer StretchDIBits in gdi32.
Integer hdc, integer XDest, integer YDest,;
INTEGER nDestWidth,INTEGER nDestHeight,INTEGER XSrc,;
Integer YSrc, integer nSrcWidth, integer nSrcHeight,;
Integer lpBits, STRING @lpBitsInfo,;
Integer usage
Declare the integer GetDIBits in gdi32.
Integer hdc, integer hbmp, integer uStartScan,;
INTEGER cScanLines,INTEGER lpvBits,STRING @lpbi,;
Integer usage
Return & & deviation
▲ Can I control the printing area in the form?
●
Of course. Just adjust the left, top, width and height of the following code, for example, the following code prints the whole form.
*-Copy bitmap data from the screen to the virtual device.
= BitBlt (hMemDC,0,0,pnWidth,pnHeight,hFormDC,0,0,SRCCOPY)
= SelectObject(hMemDC,hSavedBitmap)
The following code only prints a part of the middle area of the form.
*-Copy bitmap data from the screen to the virtual device.
= BitBlt (hMemDC,-30,-30,pnWidth+60,pnHeight+60,hFormDC,0,0,SRCCOPY)
= SelectObject(hMemDC,hSavedBitmap)
- Previous article:1987 where is the rabbit's fortune?
- Next article:Ruyang Fortune Teller _ Ruyang Fortune Teller is the most accurate person.
- Related articles
- What do you mean by excellent eight characters?
- Time drama "fortune teller" cast _ time drama "fortune teller" cast introduction
- Brother Lan tells fortune.
- Fortune teller 73
- Fortune-telling in rural novels
- The "mole" grows continuously on the waist, and the three "big moles" are very neat. What does it stand for?
- What does 32 1 mean? What does 32 1 mean?
- Free inquiry and fortune telling of baby's birth date _ calculation of baby's birth date
- Where can I see the full version of the surveillance video of Hubei bald father?
- Seek Zhao Benshan Song Xiaobao sketch blind date 2 line full version!