关于剪贴板问题
对于剪贴板问题,遇到了一个棘手的问题,就是在CopyFile的时候出现错误,大家给看看是什么原因。
附上代码:
void CCopyFileOrDirDlg::OnBnClickedOk(){ // TODO: 在此添加控件通知处理程序代码 TCHAR szBuffer[4096]; memset(szBuffer,0,4096*sizeof(TCHAR)); UINT uDropEffect = RegisterClipboardFormat(_T("Preferred DropEffect")); UINT cFiles = 0; DWORD dwEffect, *dw; if ( OpenClipboard() ) { //GlobalLock() HDROP hDrop = HDROP(GetClipboardData(CF_HDROP)); if (hDrop) { GlobalLock(hDrop); dw = (DWORD*)(GetClipboardData(uDropEffect)); if (NULL == dw ) { dwEffect = DROPEFFECT_COPY; } else { dwEffect = *dw; } CloseClipboard(); cFiles = DragQueryFile(hDrop,(UINT)-1,NULL,0); TCHAR szFile[MAX_PATH]; for (UINT count = 0; count < cFiles; count++) { DragQueryFile(hDrop,count,szFile,sizeof(szFile)); lstrcat(szBuffer,szFile); lstrcat(szBuffer,_T("\r\n")); } //EmptyClipboard(); if (dwEffect & DROPEFFECT_MOVE) { BOOL b = MoveFileEx(szBuffer,_T("D:\\a.doc"),TRUE); ::MessageBox(NULL,szBuffer,_T("Move Files"),MB_OK); } else if (dwEffect & DROPEFFECT_COPY) { strFileName = szBuffer; int x = strFileName.ReverseFind('\\'); CString strPath = strFileName.Mid(0,x); strPath = strPath + _T("\\Dui\\") + strFileName.Mid(x +1, strFileName.GetAllocLength()); WIN32_FIND_DATA fd; memset(&fd,0,sizeof(fd)); BOOL b = CopyFile(strFileName,strPath,FALSE); if (b == FALSE) { AfxMessageBox((_T("Error!!!"))); } //BOOL bx = CopyFileEx(str, strPath, NULL, NULL, FALSE, COPY_FILE_FAIL_IF_EXISTS ); DWORD dwError = GetLastError(); ::MessageBox(NULL,szBuffer,_T("Copy Files"),MB_OK); GlobalUnlock(hDrop); } CloseClipboard(); } } OnOK();}