1 if (::OpenClipboard(NULL) && ::IsClipboardFormatAvailable(CF_HDROP)) 2 { 3 HDROP hDrop = (HDROP)::GetClipboardData(CF_HDROP); 4 if (hDrop != NULL) 5 { 6 TCHAR filename[MAX_PATH]; 7 int fileCount = ::DragQueryFile(hDrop, 0xFFFFFFFF, filename, MAX_PATH); 8 for (int i = 0; i < fileCount; ++i) 9 {} 10 } 11 }
1.OpenClipboard,
BOOL OpenClipboard(
__in HWND hWndNewOwner
);
參數
返回值
如果函數執行成功,返回非零值.
如果函數執行失敗,返回零,為了獲得更多的錯誤信息,調用GetLastError.
2.IsClipboardFormatAvailable
常用
剪貼板數據格式:
CF_TEXT 以NULL結尾的ASCII字符的文本格式
CF_BITMAP 圖像句柄HBITMAP
注:若應用程序要識別多個剪貼板格式,應使用函數GetPriorityClipboardFormat 達到目的。
3.GetClipboardData
獲得剪切板的數據。
4.DragQueryFile(hDrop, 0xFFFFFFFF, filename, MAX_PATH)
DragQueryFile是一個成功拖放操作后獲取被拖放文件的名稱等信息的函數。
UINT DragQueryFile(
HDROP
hDrop,
UINT
iFile,
LPTSTR
lpszFile,
UINT
cch
);
hDrop
Identifier of the structure containing the file names of the dropped files.
用於區分”包含被拖拽文件名稱結構”的句柄。
即存放所拖放文件名稱的數據結構的句柄,也就是文件名
緩沖區的句柄
iFile
Index of the file to query. If the value of the
iFileparameter is 0xFFFFFFFF,DragQueryFilereturns a count of the files dropped. If the value of the
iFileparameter is between zero and the total number of files dropped,DragQueryFilecopies the file name with the corresponding value to the buffer pointed to by the
lpszFileparameter.
文件索引編號(用於指明所要查詢文件的序號, 如果拖進多個文件,則索引編號從零開始),如果iFile值為 0xFFFFFFFF 時,返回的是拖曳到
窗體上的文件的個數。如果iFile值在0和拖拽文件總數之間時,DragQueryFile拷貝與文件名存儲
緩沖區大小適應的文件名稱到緩沖區中。
lpszFile
Address of a buffer to receive the file name of a dropped file when the function returns. This file name is a null-terminated string. If this parameter is NULL,DragQueryFilereturns the required size, in characters, of the buffer.
函數返回時,用於存儲拖拽文件名稱的
緩沖區
指針。文件名稱是一個以空終止“\0”結尾的字符串。如果此參數是NULL,DragQueryFile函數返回拖拽的文件名的長度。函數DragQueryFile得到的文件名,是帶完整路徑的文件名。
cch
Size, in characters, of the
lpszFilebuffer.
http://baike.baidu.com/link?url=8iXrSheAjTSKFIVYCjnMh2t6dmcym2LQyQ5_RjKSLDzryNRPWt4Wsulq00OF3_wk43iwPRNjwU9_g4poBmulG05_IyVJrA8fYwXCLWqZoOa
