《将表单的内容直接打印》由会员分享,可在线阅读,更多相关《将表单的内容直接打印(8页珍藏版)》请在金锄头文库上搜索。
1、将表单的内容直接打印将表单的内容直接打印*- 程序名称:将表单的内容直接打印 -*- 将窗口中的内容以一个位图的形式打印 -*- 程序作者:未知,来源论坛转帖 -*- 使用方法:在表单中执行该程序既可 -* 例:在某表单的一个 command -* 按纽中执行 do PrintForm.prg -*- 定义常量#DEFINE LOGPIXELSX 88#DEFINE LOGPIXELSY 90#DEFINE PHYSICALOFFSETX 112#DEFINE PHYSICALOFFSETY 113#DEFINE SRCCOPY 13369376#DEFINE DIB_RGB_COLORS 0
2、*- 调用本程序段中的子过程DO decl*- 定义变量PRIVATE pnWidth, pnHeight, lnBitsPerPixel, lnBytesPerScanSTORE 0 TO pnWidth, pnHeight, lnBitsPerPixel, lnBytesPerScanLOCAL hwnd, hFormDC, hPrnDC, hMemDC, hMemBmp, hSavedBitmap,;xOffsPrn, yOffsPrn, xScale, yScale, lcDocInfo, lcBInfo, lpBitsArray*- 得到打印机设备的坐标偏移量hPrnDC = get
3、DefaultPrnDC() lpBitsArray, lcBInfo, DIB_RGB_COLORS)lcDocInfo = Chr(20) + Repli(Chr(0), 19) xOffsPrn + Int(xScale * pnWidth),;yOffsPrn + Int(yScale * pnHeight),;0,0, pnWidth, pnHeight,;lpBitsArray, lcBInfo, DIB_RGB_COLORS, SRCCOPY)= EndPage(hPrnDC)= EndDoc(hPrnDC)ENDIF*- 退出时释放系统资源= GlobalFree(lpBits
4、Array)= DeleteObject(hMemBmp)= DeleteDC(hMemDC)= DeleteDC(hPrnDC)= ReleaseDC(hwnd, hFormDC)RETURNPROCEDURE getWinRect (lnHwnd, lnWidth, lnHeight)*- 返回指定句柄的窗口的宽和高#DEFINE maxDword 4294967295 num2dword(lnFlags) + Repli(Chr(0), 42)IF PrintDlg (lcStruct) 0RETURN buf2dword (SUBSTR(lcStruct, 17,4)ENDIFRETU
5、RN 0FUNCTION InitBitmapInfo(hTargetDC)#DEFINE BI_RGB 0#DEFINE RGBQUAD_SIZE 4 num2dword(pnWidth) + num2dword(pnHeight) +;num2word(1) + num2word(lnBitsPerPixel) +;num2dword(BI_RGB) + Repli(Chr(0), 20)* creating a buffer for the color tableIF lnBitsPerPixel 0lnBytesPerScan = lnBytesPerScan + 4 - Mod(ln
6、BytesPerScan, 4)ENDIFlnAllocSize = pnHeight * lnBytesPerScanlnPtr = 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
7、16777216LOCAL b0, b1, b2, b3b3 = 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)RET
8、URN Asc(SUBSTR(lcBuffer, 1,1) + ;Asc(SUBSTR(lcBuffer, 2,1) * 256 +;Asc(SUBSTR(lcBuffer, 3,1) * 65536 +;Asc(SUBSTR(lcBuffer, 4,1) * 16777216PROCEDURE decl INTEGER dest, INTEGER numBytesDECLARE INTEGER CreateCompatibleBitmap IN gdi32;INTEGER hdc, INTEGER nWidth, INTEGER nHeightDECLARE INTEGER BitBlt I
9、N gdi32;INTEGER hDestDC, INTEGER x, INTEGER y,;INTEGER nWidth, INTEGER nHeight, INTEGER hSrcDC,;INTEGER xSrc, INTEGER ySrc, INTEGER dwRopDECLARE INTEGER StretchDIBits IN gdi32;INTEGER hdc, INTEGER XDest, INTEGER YDest,;INTEGER nDestWidth, INTEGER nDestHeight, INTEGER XSrc,;INTEGER YSrc, INTEGER nSrc
10、Width, INTEGER nSrcHeight,;INTEGER lpBits, STRING lpBitsInfo,;INTEGER iUsage, INTEGER dwRopDECLARE INTEGER GetDIBits IN gdi32;INTEGER hdc, INTEGER hbmp, INTEGER uStartScan,;INTEGER cScanLines, INTEGER lpvBits, STRING lpbi,;INTEGER uUsageRETURN & decl可否控制表单中的打印区域?可以。只需要调整下面代码的 left、top、width、height 就可以,比如下面代码打印整个表单*- 将位图数据从屏幕拷贝到虚拟设备上= BitBlt (hMemDC, 0,0, pnWidth,pnHeight, hFormDC, 0,0, SRCCOPY)= SelectObject(hMemDC, hSavedBitmap)而下面代码只打印表单中间的一部分区域*- 将位图数据从屏幕拷贝到虚拟设备上= BitBlt (hMemDC, -30,-30, pnWidth+60,pnHeight+60, hFormDC, 0,0, SRCCOPY)= SelectObject(hMemDC, hSavedBitmap)本文来自编程入门网:http:/