标题:VFP程序执行时,将当前窗口内容(截图)复制到粘贴板,没找到Prtsc键码,无 ...
只看楼主
shschy
Rank: 1
等 级:新手上路
帖 子:33
专家分:5
注 册:2022-3-13
结帖率:0
 问题点数:0 回复次数:12 
VFP程序执行时,将当前窗口内容(截图)复制到粘贴板,没找到Prtsc键码,无法模拟截屏操作
VFP程序执行时,将当前窗口内容(截图)复制到粘贴板,没找到Prtsc键码,无法模拟截屏操作
问题1:文件复制到粘贴板,知道,但截图复制到粘贴板,不知VFP代码如何做
问题2:尝试模拟键盘按下,但没搜到Prtsc键码,尝试keypress获取Prtsc,显示为空?
搜索更多相关主题的帖子: 操作 模拟 内容 VFP 复制 
2022-03-27 11:43
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:432
帖 子:10064
专家分:41463
注 册:2014-5-20
得分:0 
参考示例
程序代码:
** 
** 窗口区域截图
**
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
2022-03-27 14:18
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:432
帖 子:10064
专家分:41463
注 册:2014-5-20
得分:0 
程序代码:
**
** 窗口区域截图到剪贴板
**
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
2022-03-27 14:29
schtg
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:https://t.me/pump_upp
等 级:贵宾
威 望:67
帖 子:1355
专家分:2534
注 册:2012-2-29
得分:0 
非常好!谢谢!
2022-12-07 07:03
gs2536785678
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:45
帖 子:565
专家分:1668
注 册:2017-7-16
得分:0 
键盘上的 PrtScr 键
2022-12-07 09:27
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:432
帖 子:10064
专家分:41463
注 册:2014-5-20
得分:0 
以下是引用gs2536785678在2022-12-7 09:27:03的发言:

键盘上的 PrtScr 键

PrtScr最快捷,但这是截屏。
如果是手动,还要手动继续去截取所要的部分。
2022-12-07 11:09
pvm2000
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:24
帖 子:159
专家分:256
注 册:2022-12-22
得分:0 
学习中
2022-12-23 08:27
nbwww
Rank: 6Rank: 6
等 级:贵宾
威 望:10
帖 子:222
专家分:468
注 册:2021-1-9
得分:0 
以下是引用吹水佬在2022-3-27 14:29:28的发言:

**
** 窗口区域截图到剪贴板
**
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


请教一下吹版,能不按当前窗口来截图吗?按屏幕来截图可行吗? 想要截图当前屏幕显示的其他程序界面
2022-12-26 11:48
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:432
帖 子:10064
专家分:41463
注 册:2014-5-20
得分:0 
以下是引用nbwww在2022-12-26 11:48:57的发言:



请教一下吹版,能不按当前窗口来截图吗?按屏幕来截图可行吗? 想要截图当前屏幕显示的其他程序界面

试试 hWnd=0
2022-12-26 12:46
pvm2000
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:24
帖 子:159
专家分:256
注 册:2022-12-22
得分:0 
回复 3楼 吹水佬
参考
2022-12-26 18:14



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-508674-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.161095 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved