C++打開剪切板,獲取剪切板數據


 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
);
參數
hWndNewOwne Long類型,與打開 剪切板相關聯的 窗口句柄。如果這個參數為NULL,打開剪貼板與當前任務相關聯。
返回值
如果函數執行成功,返回非零值.
如果函數執行失敗,返回零,為了獲得更多的錯誤信息,調用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.
存儲拖拽文件名稱 緩沖區的大小,即lpszFile 指針所指緩沖區的字符數。
 
http://baike.baidu.com/link?url=8iXrSheAjTSKFIVYCjnMh2t6dmcym2LQyQ5_RjKSLDzryNRPWt4Wsulq00OF3_wk43iwPRNjwU9_g4poBmulG05_IyVJrA8fYwXCLWqZoOa
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM