VFP程序执行时,将当前窗口内容(截图)复制到粘贴板,没找到Prtsc键码,无法模拟截屏操作
VFP程序执行时,将当前窗口内容(截图)复制到粘贴板,没找到Prtsc键码,无法模拟截屏操作问题1:文件复制到粘贴板,知道,但截图复制到粘贴板,不知VFP代码如何做
问题2:尝试模拟键盘按下,但没搜到Prtsc键码,尝试keypress获取Prtsc,显示为空?
** ** 窗口区域截图 ** 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 of = CREATEOBJECT("form1") of.Show READ EVENTS CLEAR DLLS RETURN DEFINE CLASS Form1 As Form Height = 300 Width = 300 AutoCenter = .T. BackColor = 0x808080 ADD OBJECT Command1 AS COmmandButton WITH top=100,left=100,height=100,width=100,caption="表单区域截图" PROCEDURE Destroy 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
** ** 窗口区域截图到剪贴板 ** DECLARE long GetDC IN user32 long DECLARE long ReleaseDC IN user32 long,long DECLARE long OpenClipboard IN user32 long DECLARE long EmptyClipboard IN user32 DECLARE long CloseClipboard IN user32 DECLARE long SetClipboardData 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 of = CREATEOBJECT("form1") of.show(1) RETURN DEFINE CLASS form1 As Form backcolor = 0x808080 ADD OBJECT cmd1 as commandbutton WITH top=30,left=30,width=200,height=50,caption="窗口区域截图到剪贴板" PROCEDURE cmd1.click LOCAL nX, nY, nWidth, nHeight, hDC, pDC, hBitmap nX = 0 nY = 0 nWidth = thisform.width nHeight = thisform.height hDC = GetDC(thisform.hWnd) pDC = CreateCompatibleDC(hDC) hBitmap = CreateCompatibleBitmap(hDC, nWidth, nHeight) SelectObject(pDC, hBitmap) BitBlt(pDC, 0, 0, nWidth, nHeight, hDC, nX, nY, 0xCC0020) && SRCCOPY IF OpenClipboard(0) == 0 MESSAGEBOX("打开剪贴板失败") RETURN ENDIF EmptyClipboard() SetClipboardData(2, hBitmap) &&CF_BITMAP CloseClipboard() MESSAGEBOX("图像装入剪贴板") DeleteObject(hBitmap) DeleteDC(pDC) ReleaseDC(thisform.hWnd, hDC) ENDPROC ENDDEFINE