明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1068|回复: 2

获得剪贴板中的文件列表(源码)

[复制链接]
发表于 2017-9-16 23:47:37 | 显示全部楼层 |阅读模式
Private Declare Function OpenClipboard Lib "USER32" (ByVal hWnd As Long) As Long
Private Declare Function CloseClipboard Lib "USER32" () As Long
Private Declare Function IsClipboardFormatAvailable Lib "USER32" (ByVal wFormat As Long) As Long
Private Declare Function GetClipboardData Lib "USER32" (ByVal wFormat As Long) As Long
'Private Declare Function AbortDoc Lib "gdi32" (ByVal hdc As Long) As Long
'Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
'Private Declare Function GlobalSize Lib "kernel32" (ByVal hMem As Long) As Long
'Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
'Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function DragQueryFile Lib "shell32.dll" Alias "DragQueryFileA" (ByVal hDrop As Long, ByVal UINT As Long, ByVal lpStr As String, ByVal ch As Long) As Long
'Private Const CF_UNICODETEXT = 13
Private Const CF_HDROP = 15
Private Const MAX_PATH = 260
'Function getClipboardText() As String
'获得剪贴板中的文本
'    Dim lpData As Long
'    Dim nSize As Long
'    Dim hMem As Long
'    Dim s As String
'
'    OpenClipboard ByVal 0&
'    If IsClipboardFormatAvailable(CF_UNICODETEXT) Then
'        hMem = GetClipboardData(CF_UNICODETEXT)
'        lpData = GlobalLock(hMem)
'        nSize = GlobalSize(hMem)
'        s = String(nSize, 0)
'        CopyMemory ByVal StrPtr(s), ByVal lpData, ByVal nSize
'        GlobalUnlock hMem
'        getClipboardText = Left(s, InStr(s, Chr(0)) - 1)
'    End If
'    CloseClipboard
'End Function

Public Function GetClipboardFile() As String()
Dim hDrop As Long
Dim iFile As Long, sFiles() As String
Dim sBuff As String * MAX_PATH
Dim iPos As Long
ReDim sFiles(0)
'sBuff = String$(MAX_PATH, 0) '260,0
Call OpenClipboard(ByVal 0&) '打开剪贴板
If IsClipboardFormatAvailable(CF_HDROP) Then '如果剪贴板内容是文件
    hDrop = GetClipboardData(CF_HDROP) '获得句柄
    If Not hDrop = 0 Then '如果成功
       iFileCount = DragQueryFile(hDrop, -1&, "", 0) '文件数量

       If (iFileCount > 0) Then
          ReDim sFiles(1 To iFileCount) As String

          For iFile = 1 To iFileCount
             DragQueryFile hDrop, iFile - 1, sBuff, MAX_PATH
             iPos = InStr(sBuff, vbNullChar)
             If (iPos <> 0) Then
                sFiles(iFile) = Left$(sBuff, iPos - 1)
             Else
                sFiles(iFile) = sBuff
             End If
          Next

       End If
    End If
End If
CloseClipboard '关闭
GetClipboardFile = sFiles
End Function

发表于 2017-9-17 08:12:19 | 显示全部楼层
学习了,谢谢分享
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 10:14 , Processed in 0.167808 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表