专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > VFP

球问一个VFP表单转图片直接打印的有关问题

发布时间:2010-05-24 21:24:11 文章来源:www.iduyao.cn 采编人员:星星草
球问一个VFP表单转图片直接打印的问题
*-- 定义常量
#DEFINE LOGPIXELSX 88
#DEFINE LOGPIXELSY 90
#DEFINE PHYSICALOFFSETX 112
#DEFINE PHYSICALOFFSETY 113
#DEFINE SRCCOPY 13369376
#DEFINE DIB_RGB_COLORS 0

*-- 调用本程序段中的子过程
DO decl

*-- 定义变量
PRIVATE pnWidth, pnHeight, lnBitsPerPixel, lnBytesPerScan
STORE 0 TO pnWidth, pnHeight, lnBitsPerPixel, lnBytesPerScan
LOCAL hwnd, hFormDC, hPrnDC, hMemDC, hMemBmp, hSavedBitmap,;
xOffsPrn, yOffsPrn, xScale, yScale, lcDocInfo, lcBInfo, lpBitsArray

*-- 得到打印机设备的坐标偏移量
hPrnDC = getDefaultPrnDC() && 没有进行错误检查
xOffsPrn = GetDeviceCaps(hPrnDC, PHYSICALOFFSETX)
yOffsPrn = GetDeviceCaps(hPrnDC, PHYSICALOFFSETY)

*-- 得到屏幕的窗口句柄,及她们的宽度、高度等。
hwnd = GetFocus() && a window with keyboard focus
hFormDC = GetWindowDC(hwnd)
= getWinRect (hwnd, @pnWidth, @pnHeight)

*-- 根据屏幕和打印机得到缩放值
xScale = GetDeviceCaps(hPrnDC, LOGPIXELSX)/GetDeviceCaps(hFormDC,LOGPIXELSX)
yScale = GetDeviceCaps(hPrnDC, LOGPIXELSY)/GetDeviceCaps(hFormDC,LOGPIXELSY)

*-- 将屏幕的内容创建为位图图象数据
hMemDC = CreateCompatibleDC (hFormDC)
hMemBmp = CreateCompatibleBitmap (hFormDC, pnWidth, pnHeight)
hSavedBitmap = SelectObject(hMemDC, hMemBmp)

*-- 将位图数据从屏幕拷贝到虚拟设备上
= 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)

* 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 context
lcBInfo = InitBitmapInfo(hPrnDC)
lpBitsArray = InitBitsArray()
= GetDIBits (hMemDC, hMemBmp, 0, pnHeight,;
lpBitsArray, @lcBInfo, DIB_RGB_COLORS)

lcDocInfo = Chr(20) + Repli(Chr(0), 19) && DOCINFO struct - 20 bytes
IF StartDoc(hPrnDC, @lcDocInfo) > 0
= StartPage(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

*-- 退出时释放系统资源
= GlobalFree(lpBitsArray)
= DeleteObject(hMemBmp)
= DeleteDC(hMemDC)
= DeleteDC(hPrnDC)
= ReleaseDC(hwnd, hFormDC)
RETURN

PROCEDURE getWinRect (lnHwnd, lnWidth, lnHeight)
*-- 返回指定句柄的窗口的宽和高
#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
RETURN

FUNCTION 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 0

FUNCTION InitBitmapInfo(hTargetDC)
#DEFINE IDCANCEL 1  &&横向1(纵向)或 2(横向)
#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 structure
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
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: