将表单的内容直接打印.doc

上传人:壹****1 文档编号:550456227 上传时间:2023-02-02 格式:DOC 页数:8 大小:32.50KB
返回 下载 相关 举报
将表单的内容直接打印.doc_第1页
第1页 / 共8页
将表单的内容直接打印.doc_第2页
第2页 / 共8页
将表单的内容直接打印.doc_第3页
第3页 / 共8页
将表单的内容直接打印.doc_第4页
第4页 / 共8页
将表单的内容直接打印.doc_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《将表单的内容直接打印.doc》由会员分享,可在线阅读,更多相关《将表单的内容直接打印.doc(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 = getDefaultPrnD

3、C() & 没有进行错误检查xOffsPrn = GetDeviceCaps(hPrnDC, PHYSICALOFFSETX)yOffsPrn = GetDeviceCaps(hPrnDC, PHYSICALOFFSETY)*- 得到屏幕的窗口句柄,及她们的宽度、高度等。hwnd = GetFocus() & a window with keyboard focushFormDC = GetWindowDC(hwnd)= getWinRect (hwnd, pnWidth, pnHeight)*- 根据屏幕和打印机得到缩放值xScale = GetDeviceCaps(hPrnDC, LOGP

4、IXELSX)/GetDeviceCaps(hFormDC,LOGPIXELSX)yScale = GetDeviceCaps(hPrnDC, LOGPIXELSY)/GetDeviceCaps(hFormDC,LOGPIXELSY)*- 将屏幕的内容创建为位图图象数据hMemDC = CreateCompatibleDC (hFormDC)hMemBmp = CreateCompatibleBitmap (hFormDC, pnWidth, pnHeight)hSavedBitmap = SelectObject(hMemDC, hMemBmp)*- 将位图数据从屏幕拷贝到虚拟设备上= Bi

5、tBlt (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 =

6、 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)= StretchDIBits (hPrnDC, xOffsPrn, yOffsPrn,;xOffsPrn + Int(xScale * pnWidth),;yOffsPr

7、n + Int(yScale * pnHeight),;0,0, pnWidth, pnHeight,;lpBitsArray, lcBInfo, DIB_RGB_COLORS, SRCCOPY)= EndPage(hPrnDC)= EndDoc(hPrnDC)ENDIF*- 退出时释放系统资源= GlobalFree(lpBitsArray)= DeleteObject(hMemBmp)= DeleteDC(hMemDC)= DeleteDC(hPrnDC)= ReleaseDC(hwnd, hFormDC)RETURNPROCEDURE getWinRect (lnHwnd, lnWidt

8、h, lnHeight)*- 返回指定句柄的窗口的宽和高#DEFINE maxDword 4294967295 & 0xffffffffLOCAL lpRect, lnLeft, lnTop, lnRight, lnBottomlpRect = 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

9、 lnRightlnLeft = lnLeft - maxDwordENDIFlnTop = buf2dword(SUBSTR(lpRect, 5,4)IF lnTop lnBottomlnTop = lnTop - maxDwordENDIFlnWidth = lnRight - lnLeftlnHeight = lnBottom - lnTopRETURNFUNCTION getDefaultPrnDC* returns device context for the default printer#DEFINE PD_RETURNDC 256#DEFINE PD_RETURNDEFAULT

10、 1024LOCAL lcStruct, lnFlagslnFlags = PD_RETURNDEFAULT + PD_RETURNDC* fill PRINTDLG structurelcStruct = num2dword(66) + Repli(Chr(0), 16) +;num2dword(lnFlags) + Repli(Chr(0), 42)IF PrintDlg (lcStruct) 0RETURN buf2dword (SUBSTR(lcStruct, 17,4)ENDIFRETURN 0FUNCTION InitBitmapInfo(hTargetDC)#DEFINE BI_

11、RGB 0#DEFINE RGBQUAD_SIZE 4 & RGBQUAD#DEFINE BHDR_SIZE 40 & BITMAPINFOHEADERLOCAL lnRgbQuadSize, lcRgbQuad, lcBIHdr* use printer BitPerPixel valuelnBitsPerPixel = 24* initializing BitmapInfoHeader structurelcBIHdr = num2dword(BHDR_SIZE) +;num2dword(pnWidth) + num2dword(pnHeight) +;num2word(1) + num2

12、word(lnBitsPerPixel) +;num2dword(BI_RGB) + Repli(Chr(0), 20)* creating a buffer for the color tableIF lnBitsPerPixel = 8lnRgbQuadSize = (2lnBitsPerPixel) * RGBQUAD_SIZElcRgbQuad = Repli(Chr(0), lnRgbQuadSize)ELSElcRgbQuad = ENDIFRETURN lcBIHdr + lcRgbQuadPROCEDURE InitBitsArray()#DEFINE GMEM_FIXED 0

13、LOCAL lnPtr, lnAllocSize* making sure the value is DWORD-alignedlnBytesPerScan = Int(pnWidth * lnBitsPerPixel)/8)IF Mod(lnBytesPerScan, 4) 0lnBytesPerScan = lnBytesPerScan + 4 - Mod(lnBytesPerScan, 4)ENDIFlnAllocSize = pnHeight * lnBytesPerScanlnPtr = GlobalAlloc (GMEM_FIXED, lnAllocSize)= ZeroMemor

14、y (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 16777216LOCAL b0, b1, b2, b3b3 = Int(lnvalue/m2)b2 = Int(lnvalue - b3*m2)/m1)b1 = Int(lnvalue - b3*m2 - b2*m1)/m0)b0

15、 = 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 declared hereDECLARE INTEGER

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 社会民生

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号