当前位置: 代码迷 >> VFP >> 怎么将vfp中的表单以图片的格式插入word文档
  详细解决方案

怎么将vfp中的表单以图片的格式插入word文档

热度:8148   发布时间:2013-02-26 00:00:00.0
如何将vfp中的表单以图片的格式插入word文档?
如题

------解决方案--------------------------------------------------------
*WIN API-保存当前一个窗口到一个bmp文件

*----------------------------------------------------

*你可以在command 窗口执行 bmpform.prg,不过最好在要保存的form调用这个子程序.
*bmpform.prg

********
DO decl

PRIVATE hMemDC, hMemBmp, lnWidth, lnHeight, lnBitsPerPixel,;
lnBytesPerScan, lcBFileHdr, lcBIHdr, lpBitsArray, lnBitsSize,;
lcRgbQuad, lnRgbQuadSize, lcBInfo, lnFileSize

STORE " " TO lcBIHdr, lcBInfo, lcRgbQuad
STORE 0 TO hMemDC, hMemBmp, lnWidth, lnHeight, lnFileSize,;
lnBitsPerPixel, lnBytesPerScan, lnRgbQuadSize, lpBitsArray, lnBitsSize

= MakeSnapshot()
= InitBitmapInfo()
= InitBitsArray()

#DEFINE DIB_RGB_COLORS 0
= GetDIBits (hMemDC, hMemBmp, 0, lnHeight, lpBitsArray,;
@lcBInfo, DIB_RGB_COLORS)

LOCAL lcFilename
**保存的文件名
lcFilename = "c:\myfile.bmp "

IF bmp2file (lcFilename)
ACTI SCREEN
? "file: ", lcFilename
? "Size: ", LTRIM(TRANS(lnFileSize, "999,999,999,999 "))
? "Width: ", LTRIM(STR(lnWidth)) + " pixels "
? "Height: ", LTRIM(STR(lnHeight)) + " pixels "
? "Bits per pixel: ", LTRIM(STR(lnBitsPerPixel))
ENDIF

= GlobalFree (lpBitsArray)
= DeleteObject (hMemBmp)
= DeleteDC (hMemDC)
RETURN && main

PROCEDURE InitBitmapInfo()
#DEFINE BI_RGB 0
#DEFINE RGBQUAD_SIZE 4 && RGBQUAD
#DEFINE BHDR_SIZE 40 && BITMAPINFOHEADER

* forcing 24-bit format
lnBitsPerPixel = 24
lnBytesPerScan = lnWidth * 3

* line width should be DWORD-aligned (4 bytes)
* important for 16- and 24-bit color palettes
IF Mod(lnBytesPerScan, 4) <> 0
lnBytesPerScan = lnBytesPerScan + 4 - Mod(lnBytesPerScan, 4)
ENDIF

* initializing BitmapInfoHeader structure
lcBIHdr = num2dword(BHDR_SIZE) + num2dword(lnWidth) +;
num2dword(lnHeight) + num2word(1) + num2word(lnBitsPerPixel) +;
num2dword(BI_RGB) + num2dword(0) + num2dword(0) + num2dword(0) +;
num2dword(0) + num2dword(0)

* creating a buffer for the color table
IF lnBitsPerPixel <= 8
lnRgbQuadSize = (2^lnBitsPerPixel) * RGBQUAD_SIZE
lcRgbQuad = Repli(Chr(0), lnRgbQuadSize)
ELSE
lnRgbQuadSize = 0
lcRgbQuad = " "
ENDIF

* merging two pieces together
lcBInfo = lcBIHdr + lcRgbQuad
RETURN

PROCEDURE InitBitsArray()
#DEFINE GMEM_FIXED 0
lnBitsSize = lnHeight * lnBytesPerScan
lpBitsArray = GlobalAlloc (GMEM_FIXED, lnBitsSize)
= ZeroMemory (lpBitsArray, lnBitsSize)

FUNCTION bmp2file (lcTargetFile)
* store all gathered pieces to a disk file
#DEFINE GENERIC_WRITE 1073741824 && 0x40000000
#DEFINE FILE_SHARE_WRITE 2
#DEFINE CREATE_ALWAYS 2
#DEFINE FILE_ATTRIBUTE_NORMAL 128
#DEFINE INVALID_HANDLE_value -1
#DEFINE BFHDR_SIZE 14 && BITMAPFILEHEADER

LOCAL hFile, lnOffBits

* resulting BMP file size
lnFileSize = BFHDR_SIZE + BHDR_SIZE + lnRgbQuadSize + lnBitsSize

* offset to the bitmap bits
lnOffBits = BFHDR_SIZE + BHDR_SIZE + lnRgbQuadSize
  相关解决方案