窗口截图
参考示例:
**
** test.prg
**
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
PUBLIC oForm
oForm
= NEWOBJECT("Form1")
oForm.Show
READ EVENTS
CLEAR DLLS
RETURN
DEFINE CLASS Form1 As Form
Height = 300
Width
= 300
AutoCenter = .T.
ADD OBJECT Command1 AS COmmandButton WITH top=100,left=100,height=100,width=100,caption="表单区域截图"
PROCEDURE UnLoad
CLEAR EVENTS
ENDPROC
PROCEDURE Command1.Click
LOCAL szOutFile, ppX, ppY, ppWidth, ppHeight,;
stGSI, lpGDI, hDC, hppDC, hBitmap, lpBitmap
* 截图文件名
szOutFile = GETFILE("jpg","截图文件名")
IF EMPTY(szOutFile)
RETURN
ENDIF
* 截图区域
ppX = 80
ppY = 80
ppWidth
= 140
ppHeight = 140
* 初始化GDI
stGSI = 0h01000000000000000000000000000000
lpGDI = 0
GdiplusStartup(@lpGDI, @stGSI, 0)
* 获取截图设备句柄
hDC
= GetDC(thisform.hWnd)
hppDC
= CreateCompatibleDC(hDC)
hBitmap = CreateCompatibleBitmap(hDC, ppWidth, ppHeight)
* 获取截图
SelectObject(hppDC, hBitmap)
BitBlt(hppDC, 0, 0, ppWidth, ppHeight, hDC, ppX, ppY, 0xCC0020)
&& SRCCOPY
* 保存截图
szOutFile = STRCONV(szOutFile + 0h00, 5)
jpgGUID
= 0h01F47C55041AD3119A730000F81EF32E
lpBitmap
= 0
GdipCreateBitmapFromHBITMAP(hBitmap, 2, @lpBitmap)
GdipSaveImageToFile(lpBitmap, @szOutFile, @jpgGUID, 0)
* 释放资源
GdipDisposeImage(lpBitmap)
DeleteObject(hBitmap)
DeleteDC(hppDC)
ReleaseDC(thisform.hWnd, hDC)
GdiplusShutdown(lpGDI)
MESSAGEBOX("截图文件: " + STRCONV(szOutFile, 6))
ENDPROC
ENDDEFINE