分享
 
 
 

获取从“资源管理器”发送到 Clipboard 里面的文件列表

王朝other·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

当从“资源管理器”复制/剪贴文件时,文件列表会被存放到“剪贴板”Clipboard。可以用下面的程序获取得这时的文件列表,包括是“复制”还是“剪贴”的情况。

在VB里面新建一个类模块,添加如下的代码即可。

'//本文由 Virtualalloc 原创,转载请注明出处。

Private Type POINTAPI

x As Long

y As Long

End Type

Private Type DROPFILES

pFiles As Long

pt As POINTAPI

fNC As Long

fWide As Long

End Type

'//global memory

Private Declare Function GlobalAlloc Lib "kernel32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long

Private Declare Function GlobalFree Lib "kernel32" (ByVal hMem As Long) As Long

Private Declare Function GlobalLock 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" (pDest As Any, pSrc As Any, ByVal ByteLen As Long)

'clipboard

Private Declare Function SetClipboardData Lib "user32" (ByVal wFormat As Long, ByVal hMem As Long) As Long

Private Declare Function EmptyClipboard Lib "user32" () As Long

Private Declare Function RegisterClipboardFormat Lib "user32" Alias "RegisterClipboardFormatA" (ByVal lpString As String) As Long

Private Declare Function IsClipboardFormatAvailable Lib "user32" (ByVal wFormat As Long) As Long

Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long

Private Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Long) As Long

Private Declare Function CloseClipboard Lib "user32" () As Long

Private Declare Function DragQueryFile Lib "shell32.dll" Alias "DragQueryFileA" (ByVal hDrop As Long, ByVal iFile As Long, ByVal lpszFile As String, ByVal cch As Long) As Long

Public Enum FileDropEffectConstants

fdDropEffectNone = 0

fdDropEffectCopy = 1

fdDropEffectMove = 2

fdDropEffectLink = 4

End Enum

'//Clipboard Formats

Private Const CF_TEXT = 1

Private Const CF_BITMAP = 2

Private Const CF_METAFILEPICT = 3

Private Const CF_SYLK = 4

Private Const CF_DIF = 5

Private Const CF_TIFF = 6

Private Const CF_OEMTEXT = 7

Private Const CF_DIB = 8

Private Const CF_PALETTE = 9

Private Const CF_PENDATA = 10

Private Const CF_RIFF = 11

Private Const CF_WAVE = 12

Private Const CF_UNICODETEXT = 13

Private Const CF_ENHMETAFILE = 14

Private Const CF_HDROP = 15

Private Const CF_LOCALE = 16

Private Const CF_MAX = 17

'other clipboard formats

Private Const CFSTR_SHELLIDLIST As String = "Shell IDList Array"

Private Const CFSTR_SHELLIDLISTOFFSET As String = "Shell Object Offsets"

Private Const CFSTR_NETRESOURCES As String = "Net Resource"

Private Const CFSTR_FILEDESCRIPTOR As String = "FileGroupDescriptor"

Private Const CFSTR_FILECONTENTS As String = "FileContents"

Private Const CFSTR_FILENAME As String = "FileName"

Private Const CFSTR_PRINTERGROUP As String = "PrinterFriendlyName"

Private Const CFSTR_FILENAMEMAP As String = "FileNameMap"

Private Const CFSTR_PREFERREDDROPEFFECT As String = "Preferred DropEffect"

'global memory

Private Const GMEM_FIXED = &H0

Private Const GMEM_MOVEABLE = &H2

Private Const GMEM_NOCOMPACT = &H10

Private Const GMEM_NODISCARD = &H20

Private Const GMEM_ZEROINIT = &H40

Private Const GMEM_MODIFY = &H80

Private Const GMEM_DISCARDABLE = &H100

Private Const GMEM_NOT_BANKED = &H1000

Private Const GMEM_SHARE = &H2000

Private Const GMEM_DDESHARE = &H2000

Private Const GMEM_NOTIFY = &H4000

Private Const GMEM_LOWER = GMEM_NOT_BANKED

Private Const GMEM_VALID_FLAGS = &H7F72

Private Const GMEM_INVALID_HANDLE = &H8000

Private Const GHND = (GMEM_MOVEABLE Or GMEM_ZEROINIT)

Private Const GPTR = (GMEM_FIXED Or GMEM_ZEROINIT)

Public Function ClipboardSetFiles(sfiles() As String, ByVal lcount As Long) As Boolean

'//send files to clipboard

Dim sTmp As String

Dim dfs As DROPFILES

Dim hGlobal As Long

Dim lpGlobal As Long

Dim i As Long

'//Open clipboard

If OpenClipboard(0) Then

EmptyClipboard 'empty clipboard

'//combine files

For i = 0 To lcount - 1

sTmp = sTmp & sfiles(i) & vbNullChar

Next

sTmp = sTmp & vbNullChar

hGlobal = GlobalAlloc(GHND, Len(dfs) + Len(sTmp)) 'Allocate

If hGlobal Then

'//make DROPFILES

lpGlobal = GlobalLock(hGlobal)

dfs.pFiles = Len(dfs)

CopyMemory ByVal lpGlobal, dfs, Len(dfs)

CopyMemory ByVal lpGlobal + Len(dfs), ByVal sTmp, Len(sTmp)

GlobalUnlock hGlobal

ClipboardSetFiles = SetClipboardData(CF_HDROP, hGlobal) 'copy sTmp to clipboard

End If

CloseClipboard 'close

End If

End Function

Public Function ClipboardGetFiles(sfiles() As String, lcount As Long, _

Optional ByRef DropEffect As FileDropEffectConstants) As Boolean

'//get files from clipboard

'//If Clipboard.GetFormat(vbCFFiles) Then........

Dim hDrop As Long

Dim sTmp As String

Dim i As Long

Const MAX_PATH As Long = 260

'//open clipboard

If IsClipboardFormatAvailable(CF_HDROP) Then

If OpenClipboard(0) Then

'Get Filelist data

hDrop = GetClipboardData(CF_HDROP)

lcount = DragQueryFile(hDrop, -1, vbNullString, 0)

'file entries

lcount = lcount

ReDim sfiles(lcount - 1)

sTmp = String(MAX_PATH, Chr(0))

'get file

For i = 0 To lcount - 1

DragQueryFile hDrop, i, sTmp, MAX_PATH

sfiles(i) = NullTrim(sTmp)

Next i

Dim lngFormat As Long

Dim lngEffect As Long

lngFormat = RegisterClipboardFormat(CFSTR_PREFERREDDROPEFFECT)

hDrop = GetClipboardData(lngFormat)

If (hDrop) Then

CopyMemory lngEffect, ByVal hDrop, 4

DropEffect = lngEffect

End If

'close

Call CloseClipboard

ClipboardGetFiles = True 'return

End If

End If

End Function

Private Function NullTrim(ByRef inString As String) As String

Dim iPos As Integer

iPos = InStr(inString, Chr$(0))

If iPos > 0 Then

NullTrim = Left$(inString, iPos - 1)

Else

NullTrim = inString

End If

End Function

'//本文由 Virtualalloc 原创,转载请注明出处。

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有