VFP 图形文件与剪切板互换的API解决方法
在 VFP 中,凡遇图形处理,大多数情况下,都会涉及到图形文件与剪切板互换的情况。下面给出利用 API 解决的方法。这是原来从网上摘下来的,版权归原作者。
基本处理的代码如下,你可以将其应用到你的代码中。
DECLARE INTEGER OpenClipboard IN User32 INTEGER
DECLARE INTEGER CloseClipboard IN User32
DECLARE INTEGER EmptyClipboard IN User32
DECLARE INTEGER SetClipboardData IN User32 INTEGER,INTEGER
DECLARE INTEGER LoadImage IN WIN32API INTEGER,String,INTEGER,INTEGER,INTEGER,INTEGER
DECLARE INTEGER GetClipboardData IN User32 INTEGER
DECLARE INTEGER GdipCreateBitmapFromHBITMAP IN GdiPlus.dll INTEGER, INTEGER, INTEGER @
DECLARE INTEGER GdipSaveImageToFile IN GdiPlus.dll INTEGER,String,String @,String @
DECLARE Long GdipCreateHBITMAPFromBitmap IN GDIPLUS.DLL Long nativeImage, Long @, Long
DECLARE Long GdipCreateBitmapFromFile IN GDIPLUS.DLL String FileName, Long @nBitmap
DECLARE Long CopyImage IN WIN32API Long hImage, Long, Long, Long , Long
#Define CF_BITMAP 2
#Define CF_DIB 8
#Define IMAGE_BITMAP 0
#Define LR_LOADFROMFILE 16
*1.将图形文件保存到剪切板
nBitmap=0
hbm=0
imagefile='图形文件名'
GdipCreateBitmapFromFile(STRCONV(imagefile+0h00,5),@nBitmap)
GdipCreateHBITMAPFromBitmap(nBitmap,@hbm,0)
lhBmp = CopyImage(hbm, 0, 0, 0, 0)
IF OpenClipboard(0)!= 0
EmptyClipboard()
SetClipboardData(CF_BITMAP, lhBmp)
CloseClipboard()
ENDIF
*2.将剪切板图形保存到本地
OpenClipboard(0)
hBitmap = GetClipboardData(CF_BITMAP)
hDib = GetClipboardData(CF_DIB)
CloseClipboard()
uBitmap=0
GdipCreateBitmapFromHBITMAP(hBitmap,2,@uBitmap)
lcOutputFile=STRCONV('C:\_Temp1.jpg'+CHR(0),5)
*!* lqEncoderClsID_BMP=0h00F47C55041AD3119A730000F81EF32E &&BMP格式
lqEncoderClsID_JPG=0h01F47C55041AD3119A730000F81EF32E &&JPG格式
*!* lqEncoderClsID_GIF=0h02F47C55041AD3119A730000F81EF32E &&GIF格式
*!* lqEncoderClsID_TIF=0h05F47C55041AD3119A730000F81EF32E &&TIF格式
*!* lqEncoderClsID_PNG=0h06F47C55041AD3119A730000F81EF32E &&PNG格式
GdipSaveImageToFile(uBitmap,lcOutputFile,lqEncoderClsID_JPG,NULL)