| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1999 人关注过本帖, 1 人收藏
标题:VFP程序执行时,将当前窗口内容(截图)复制到粘贴板,没找到Prtsc键码,无 ...
只看楼主 加入收藏
shschy
Rank: 2
等 级:论坛游民
帖 子:87
专家分:20
注 册:2022-3-13
结帖率:33.33%
收藏(1)
 问题点数:0 回复次数:12 
VFP程序执行时,将当前窗口内容(截图)复制到粘贴板,没找到Prtsc键码,无法模拟截屏操作
VFP程序执行时,将当前窗口内容(截图)复制到粘贴板,没找到Prtsc键码,无法模拟截屏操作
问题1:文件复制到粘贴板,知道,但截图复制到粘贴板,不知VFP代码如何做
问题2:尝试模拟键盘按下,但没搜到Prtsc键码,尝试keypress获取Prtsc,显示为空?
搜索更多相关主题的帖子: 操作 模拟 内容 VFP 复制 
2022-03-27 11:43
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10608
专家分:43190
注 册:2014-5-20
收藏(2)
得分: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
等 级:版主
威 望:451
帖 子:10608
专家分:43190
注 册:2014-5-20
收藏(1)
得分: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: 12Rank: 12Rank: 12
来 自:Usa
等 级:贵宾
威 望:67
帖 子:1744
专家分:3333
注 册:2012-2-29
收藏
得分:0 
非常好!谢谢!
2022-12-07 07:03
gs2536785678
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:45
帖 子:610
专家分:1784
注 册:2017-7-16
收藏
得分:0 
键盘上的 PrtScr 键
2022-12-07 09:27
吹水佬
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:451
帖 子:10608
专家分:43190
注 册:2014-5-20
收藏
得分:0 
以下是引用gs2536785678在2022-12-7 09:27:03的发言:

键盘上的 PrtScr 键

PrtScr最快捷,但这是截屏。
如果是手动,还要手动继续去截取所要的部分。
2022-12-07 11:09
pvm2000
Rank: 6Rank: 6
等 级:贵宾
威 望:24
帖 子:180
专家分:312
注 册:2022-12-22
收藏
得分:0 
学习中
2022-12-23 08:27
nbwww
Rank: 8Rank: 8
等 级:贵宾
威 望:11
帖 子:333
专家分:810
注 册: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
等 级:版主
威 望:451
帖 子:10608
专家分:43190
注 册:2014-5-20
收藏
得分:0 
以下是引用nbwww在2022-12-26 11:48:57的发言:



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

试试 hWnd=0
2022-12-26 12:46
pvm2000
Rank: 6Rank: 6
等 级:贵宾
威 望:24
帖 子:180
专家分:312
注 册:2022-12-22
收藏
得分:0 
回复 3楼 吹水佬
参考
2022-12-26 18:14
快速回复:VFP程序执行时,将当前窗口内容(截图)复制到粘贴板,没找到Prtsc键码 ...
数据加载中...
 
   



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

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