博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
vba截屏保存
阅读量:5875 次
发布时间:2019-06-19

本文共 1595 字,大约阅读时间需要 5 分钟。

    Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

    Enum JpMode
          theScreen = 0 '全屏截图
          theForm = 1 '当前焦点窗口截图
    End Enum
    Private Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Long) As Long
    Private Declare Function CloseClipboard Lib "user32" () As Long
    Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (PicDesc As PicBmp, RefIID As Guid, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
    Private Const CF_BITMAP = 2
    Private Type PicBmp
        Size As Long
        Type As Long
        hBmp As Long
        hPal As Long
        Reserved As Long
    End Type
    Private Type Guid
        Data1 As Long
        Data2 As Integer
        Data3 As Integer
        Data4(0 To 7) As Byte
    End Type
   
    Function ApiGetClipBmp() As IPicture
        On Error Resume Next
   
        Dim Pic As PicBmp, IID_IDispatch As Guid
        OpenClipboard 0 'OpenClipboard
        With IID_IDispatch
            .Data1 = &H20400
            .Data4(0) = &HC0
            .Data4(7) = &H46
        End With
        With Pic
            .Size = Len(Pic)
            .Type = 1
            .hBmp = GetClipboardData(CF_BITMAP)
        End With
       
        OleCreatePictureIndirect Pic, IID_IDispatch, 1, ApiGetClipBmp
        'stdole.SavePicture ApiGetClipBmp, "c:\clipboard.bmp"
        CloseClipboard
    End Function
   
    Function KeyJp(Optional ByVal TheMode As JpMode = theScreen) As IPictureDisp
       '版权所有,请保留作者信息.QQ:1085992075   '如需商业用途请联系作者
          Call keybd_event(vbKeySnapshot, TheMode, 0, 0) '
          DoEvents
          'Set KeyJp = Clipboard.GetData
    End Function

    Sub dd()

      KeyJp (theScreen)
      SavePicture ApiGetClipBmp, "c:\2.bmp"
    End Sub

转载于:https://www.cnblogs.com/lbnnbs/p/4784601.html

你可能感兴趣的文章
centos 7下独立的python 2.7环境安装
查看>>
[日常] 算法-单链表的创建
查看>>
前端工程化系列[01]-Bower包管理工具的使用
查看>>
使用 maven 自动将源码打包并发布
查看>>
Spark:求出分组内的TopN
查看>>
Python爬取豆瓣《复仇者联盟3》评论并生成乖萌的格鲁特
查看>>
关于跨DB增量(增、改)同步两张表的数据小技巧
查看>>
飞秋无法显示局域网好友
查看>>
学员会诊之03:你那惨不忍睹的三层架构
查看>>
vue-04-组件
查看>>
Golang协程与通道整理
查看>>
解决win7远程桌面连接时发生身份验证错误的方法
查看>>
C/C++ 多线程机制
查看>>
js - object.assign 以及浅、深拷贝
查看>>
python mysql Connect Pool mysql连接池 (201
查看>>
Boost在vs2010下的配置
查看>>
android camera(四):camera 驱动 GT2005
查看>>
一起谈.NET技术,ASP.NET伪静态的实现及伪静态的意义
查看>>
20款绝佳的HTML5应用程序示例
查看>>
string::c_str()、string::c_data()及string与char *的正确转换
查看>>