日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

同步/异步移动文件列表框选中的文件

發布時間:2023/12/15 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 同步/异步移动文件列表框选中的文件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
//PlayBackDlg.h

CStringArray m_ArrayFiles; HANDLEm_hThreadMoveFiles;//異步移動文件句柄 unsigned int ThreadID;

void OnRefresh(); void OnMoveTo();????????????//這個同步移動文件 void OnMoveToAsync();????????//使用線程, 異步

//PlayBackDlg.cpp //m_listVideo是文件列表框(CListCtrl)
unsigned int _stdcall RunMoveFilesThread( LPVOID lpParam ) { CStringArray* pArryFiles = NULL; pArryFiles = (CStringArray*)lpParam;
if(pArryFiles == NULL || pArryFiles->IsEmpty())? { return 0; }
CWaitCursorwait; // CString ItemText; CString nFileText; CString NewItemText;
int n = pArryFiles->GetCount();
CString strPath = pArryFiles->GetAt(n-1);
for (int i =0; i < n-1; i++) { ItemText ?= pArryFiles->GetAt(i);?? ?//old file full path int pos = ItemText.ReverseFind('\\'); nFileText = ItemText.Mid(pos+1);//filename
NewItemText.Format(_T("%s%s"), strPath, nFileText);?//new file full path
MoveFile(ItemText, NewItemText);
//DeleteFile(arrayFiles[i]); }
return 0; }
// // 同步移動文件 void CPlayBackDlg::OnMoveTo() { //collect of selected video files POSITION pos = m_listVideo.GetFirstSelectedItemPosition (); if (!pos) return;//所以空的視頻沒有讓它彈出來
m_ArrayFiles.RemoveAll(); int nItem = 0; while (pos) { nItem = m_listVideo.GetNextSelectedItem (pos); m_ArrayFiles.Add (m_listVideo.GetFullPath(nItem)); }
CPathDialog ?dlg( TEXT("Folder Selection"),? TEXT("Select Image Directory to Browse"), NULL, this); ? // show path dialog if ( dlg.DoModal() == IDOK ) { CString strPath = dlg.GetPathName(); if (strPath != m_DIR) { CString ItemText; CString nFileText; CString NewItemText;
AddBackSlash(strPath);
// //start move file m_listVideo.SetRedraw(FALSE);//avoid flash CWaitCursorwait;
int n = m_ArrayFiles.GetCount(); for (int i =0; i<n; i++) { ItemText ?= m_ArrayFiles[i];?? ?//old file full path int pos = ItemText.ReverseFind('\\'); nFileText = ItemText.Mid(pos+1);//filename
NewItemText.Format(_T("%s%s"), strPath, nFileText);?//new file full path
MoveFile(ItemText, NewItemText);
//DeleteFile(arrayFiles[i]); }
OnRefresh(); m_listVideo.Arrange(LVA_ALIGNTOP); m_listVideo.SetRedraw(TRUE);
} } }
// // 異步移動文件 void CPlayBackDlg::OnMoveToAsync() {
//collect of selected video files POSITION pos = m_listVideo.GetFirstSelectedItemPosition (); if (!pos) return;//所以空的視頻沒有讓它彈出來
m_ArrayFiles.RemoveAll(); int nItem = 0; while (pos) { nItem = m_listVideo.GetNextSelectedItem (pos); m_ArrayFiles.Add (m_listVideo.GetFullPath(nItem)); }
CPathDialog ?dlg( TEXT("Folder Selection"),? TEXT("Select Image Directory to Browse"), NULL, this); //選擇目的文件夾
// show path dialog if ( dlg.DoModal() == IDOK ) { CString strPath = dlg.GetPathName(); if (strPath != m_DIR) { AddBackSlash(strPath);
m_ArrayFiles.Add(strPath);//最后一個item為要傳遞目的文件夾
// //start move file m_hThreadMoveFiles = (HANDLE)_beginthreadex(NULL,? 0, RunMoveFilesThread, (LPVOID)&m_ArrayFiles,????//傳遞參數 0, &ThreadID);
CloseHandle(m_hThreadMoveFiles); } } }

附錄: 里面用到的一個函數
/ //private
void CPlayBackDlg::AddBackSlash(CString &strPath) { int nLength = strPath.GetLength(); if (strPath.GetAt (nLength - 1) != '\\') strPath += TEXT ("\\"); } 


總結

以上是生活随笔為你收集整理的同步/异步移动文件列表框选中的文件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。