能力值:
( LV9,RANK:260 )
|
-
-
2 楼
一个小例子,自己看
#include <Windows.h>
#include <Stdio.h>
#include <Tchar.h>
#include <ShlObj.h>
HANDLE GetHandleByFiles(LPCTSTR pszFileList, INT cbFileList, BOOL fWide)
{
LPVOID lpvBuf;
DROPFILES dropFiles;
HGLOBAL hGblFiles;
INT nGblFiles;
//填充DROPFILES结构
dropFiles.pFiles = sizeof(DROPFILES);//DROPFILES结构的长度
dropFiles.pt.x = 0; //文件拖放的位置坐标x
dropFiles.pt.y = 0;//文件拖放的位置坐标y
dropFiles.fNC = FALSE;//pt值是否为客户区坐标(FALSE表明是屏幕坐标)
dropFiles.fWide = fWide;//是否是宽字符
nGblFiles = sizeof(DROPFILES) + cbFileList;
hGblFiles = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, nGblFiles);
lpvBuf = (LPTSTR)GlobalLock(hGblFiles);
memcpy(lpvBuf, &dropFiles, sizeof(DROPFILES));
memcpy((LPSTR)lpvBuf + sizeof(DROPFILES), pszFileList, cbFileList);
GlobalUnlock(hGblFiles);
return hGblFiles;
}
HANDLE GetCutOrCopyHandle(BOOL bCopy)
{
LPDWORD lpDropEffect;
HGLOBAL hGblEffect;
hGblEffect = GlobalAlloc(GMEM_MOVEABLE| GMEM_DDESHARE, sizeof(DWORD));
lpDropEffect = (LPDWORD)GlobalLock(hGblEffect);
if (bCopy)
*lpDropEffect = DROPEFFECT_COPY;
else
*lpDropEffect = DROPEFFECT_MOVE;
GlobalUnlock(hGblEffect);
return hGblEffect;
}
VOID SetClipBoardFiles(HWND hWnd, HGLOBAL hGblFiles, HGLOBAL hGblEffect)
{
UINT uiFormat;
uiFormat = RegisterClipboardFormat(_T("Preferred DropEffect"));
if(OpenClipboard(hWnd))
{
//先清空剪贴板
EmptyClipboard();
//设置剪贴板内容
SetClipboardData(CF_HDROP, hGblFiles);
SetClipboardData(uiFormat, hGblEffect);
CloseClipboard();
}
}
int _tmain(
int argc,
TCHAR *argv[]
)
{
//假说你要复制C盘的dfg目录,和123.txt
TCHAR szFileList[] = "C:\\dfg\0C:\\123.txt\0\0";//文件列表,多个文件以零相隔,以两个零结尾
HGLOBAL hGblFiles;
HGLOBAL hGblEffect;
#ifdef UNICODE
hGblFiles = GetHandleByFiles(szFileList, sizeof(szFileList), TRUE);//将文件列表转换成句柄
#else
hGblFiles = GetHandleByFiles(szFileList, sizeof(szFileList), FALSE);//将文件列表转换成句柄
#endif
hGblEffect = GetCutOrCopyHandle(TRUE);//是剪切还是复制文件列表里面的文件
SetClipBoardFiles(GetConsoleWindow(), hGblFiles, hGblEffect);//设置到剪贴板上
return 0;
}
|
能力值:
( LV6,RANK:80 )
|
-
-
3 楼
感谢帅哥!!昨天也找了一些资料,这里一并附上吧。
http://www.vckbase.com/index.php/wv/261.html
|
能力值:
( LV2,RANK:10 )
|
-
-
4 楼
mark,收藏备用
|
|
|