파일을 선택해서 원하는 위치에 복사하는 프로그램

fileCopyDlg.cpp

void CFilecopyDlg::OnFrom()
{
 // TODO: Add your control notification handler code here
 m_ctrlListBox.ResetContent();
 char szFilter[] = "All Files(*.*)|*.*||";
 
 CFileDialog dlg(TRUE, NULL, NULL, OFN_ALLOWMULTISELECT, szFilter);
 if(IDOK == dlg.DoModal())
  for(POSITION pos = dlg.GetStartPosition(); pos!=NULL;)
   m_ctrlListBox.AddString(dlg.GetNextPathName(pos));
}

void CFilecopyDlg::OnTo()
{
 // TODO: Add your control notification handler code here
 ITEMIDLIST *pidlBrowse;
 char pszPathname[MAX_PATH];

 BROWSEINFO BrInfo;
 BrInfo.hwndOwner = GetSafeHwnd();
 BrInfo.pidlRoot = NULL;
 
 memset(&BrInfo, 0, sizeof(BrInfo));
 BrInfo.pszDisplayName = pszPathname;
 BrInfo.lpszTitle = "복사할 폴더를 선택하시오";
 BrInfo.ulFlags = BIF_RETURNONLYFSDIRS;

 //대화상자 띄우기
 pidlBrowse = ::SHBrowseForFolder(&BrInfo);

 if(pidlBrowse != NULL)
 {
  //Path를 얻어옴
  SHGetPathFromIDList(pidlBrowse, pszPathname);
  m_strDest = pszPathname;
  UpdateData(FALSE);
 }
 
}

void CFilecopyDlg::OnStartCopy()
{
 // TODO: Add your control notification handler code here
 UpdateData();

 SHFILEOPSTRUCT *pF0 = new SHFILEOPSTRUCT;
 pF0->hwnd = NULL;
 pF0->wFunc = FO_COPY;
 pF0->fFlags = FOF_NOCONFIRMMKDIR;
 pF0->fAnyOperationsAborted = TRUE;
 pF0->lpszProgressTitle = _T("파일 복사중");

 CMemFile file;
 CArchive ar(&file, CArchive::store);

 CString str;
 int nCount = m_ctrlListBox.GetCount();
 char null = 0;
 for(int i=0;i<nCount;i++)
 {
  m_ctrlListBox.GetText(i, str);
  ar.WriteString(str);
  ar.Write(&null, 1);
 }
 ar.Write(&null, 1);
 ar.Close();

 pF0->pFrom = (char *)file.Detach();
 
 //복사될 디렉토리명(Destination)
 pF0->pTo = new char[m_strDest.GetLength()+1];
 strcpy((LPSTR)pF0->pTo, (LPSTR)(LPCTSTR)m_strDest);
 ((LPSTR)pF0->pTo)[m_strDest.GetLength()]=0;

 AfxBeginThread(ThreadFunc, pF0);
}

UINT ThreadFunc(LPVOID pParam)
{
 SHFILEOPSTRUCT *pF0 = (SHFILEOPSTRUCT *)pParam;
 ::SHFileOperation(pF0);

 delete [] (char *)pF0->pFrom;
 delete [] (char *)pF0->pTo;
 delete pF0;

 return 0;
}


fileCopyDlg.h

class CFileCopyDlg : public Cdialog
외부에

UINT ThreadFunc(LPVOID pParam);
를 선언해줌

+ Recent posts