def clip_files(file_list):
offset = ctypes.sizeof(DROPFILES)
length = sum(len(p) + 1 for p in file_list) + 1
size = offset + length * ctypes.sizeof(ctypes.c_wchar)
buf = (ctypes.c_char * size)()
df = DROPFILES.from_buffer(buf)
df.pFiles, df.fWide = offset, True
for path in file_list:
path = path.decode('gbk')
print "copying to clipboard, filename = " + path
array_t = ctypes.c_wchar * (len(path) + 1)
path_buf = array_t.from_buffer(buf, offset)
path_buf.value = path
offset += ctypes.sizeof(path_buf)
stg = pythoncom.STGMEDIUM()
stg.set(pythoncom.TYMED_HGLOBAL, buf)
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
try:
win32clipboard.SetClipboardData(win32clipboard.CF_HDROP, stg.data)
print "clip_files() succeed"
finally:
win32clipboard.CloseClipboard()
评论列表
文章目录