写个类似功能的示例参考
**
** 屏幕截图
**
DECLARE LONG GetDC
IN user32 LONG
DECLARE LONG ReleaseDC IN user32 LONG, LONG
DECLARE LONG CreateCompatibleDC
IN gdi32 LONG
DECLARE LONG DeleteDC
IN gdi32 LONG
DECLARE LONG CreateCompatibleBitmap IN gdi32 LONG, LONG, LONG
DECLARE LONG SelectObject
IN gdi32 LONG, LONG
DECLARE LONG DeleteObject
IN gdi32 LONG
DECLARE LONG BitBlt
IN gdi32 LONG, LONG, LONG, LONG, LONG, LONG, LONG, LONG, LONG
DECLARE LONG GdiplusStartup
IN gdiplus LONG@, STRING@, LONG
DECLARE LONG GdiplusShutdown
IN gdiplus LONG
DECLARE LONG GdipCreateBitmapFromHBITMAP IN gdiplus LONG, LONG, LONG@
DECLARE LONG GdipDisposeImage
IN gdiplus LONG
DECLARE LONG GdipSaveImageToFile
IN gdiplus LONG, STRING@, STRING@, LONG
_FormToBmp(0, "C:\TEMP\Test.bmp", 0, 0, 1000, 1000)
_FormToBmp(0, "C:\TEMP\Test.jpg", 0, 0, 1000, 1000)
CLEAR DLLS
RETURN
FUNCTION _FormToBmp(hWnd, OutFile, X, Y, Width, Height)
LOCAL szExtName, bmpGUID, hDC, stGSI, lpGDI, hppDC, hBitmap, lpBitmap
* 图像GUID
szExtName = LOWER(JUSTEXT(OutFile))
bmpGUID = ICASE(szExtName == "bmp", 0h00,;
szExtName == "jpg", 0h01,;
szExtName == "gif", 0h02,;
szExtName == "tif", 0h05,;
szExtName == "png", 0h06, "")
IF ("" == bmpGUID)
MESSAGEBOX("调用_FormToBmp(),无效的输出文件名")
RETURN .F.
ENDIF
bmpGUID = bmpGUID + 0hF47C55041AD3119A730000F81EF32E
* 获取窗口设备句柄
hDC = GetDC(hWnd)
IF (hDC == 0)
MESSAGEBOX("调用_FormToBmp(),获取窗口设备句柄失败")
RETURN .F.
ENDIF
* 初始化GDI
stGSI = 0h01000000000000000000000000000000
lpGDI = 0
GdiplusStartup(@lpGDI, @stGSI, 0)
* 获取截图设备句柄
hppDC
= CreateCompatibleDC(hDC)
hBitmap = CreateCompatibleBitmap(hDC, Width, Height)
* 获取截图
SelectObject(hppDC, hBitmap)
BitBlt(hppDC, 0, 0, Width, Height, hDC, X, Y, 0xCC0020)
&& SRCCOPY
* 保存截图
OutFile = STRCONV(OutFile + 0h00, 5)
lpBitmap
= 0
GdipCreateBitmapFromHBITMAP(hBitmap, 2, @lpBitmap)
GdipSaveImageToFile(lpBitmap, @OutFile, @bmpGUID, 0)
* 释放资源
GdipDisposeImage(lpBitmap)
DeleteObject(hBitmap)
DeleteDC(hppDC)
ReleaseDC(hWnd, hDC)
GdiplusShutdown(lpGDI)
RETURN .T.
ENDFUNC
[此贴子已经被作者于2016-8-31 15:29编辑过]