实现类似“另存为”的功能

来源:互联网 发布:mac air怎么有两个账户 编辑:程序博客网 时间:2024/05/16 14:57

当选中的是一个文件的路径时:

void CXXXDlg::OnSelFile()
{
UpdateData();

CFileDialog dlg(TRUE, NULL, NULL, OFN_OVERWRITEPROMPT,
TEXT("all file(*.*)|*.*|"), NULL);

if(IDCANCEL == dlg.DoModal())
return;

m_strSelPath = dlg.GetPathName();

UpdateData(FALSE);
}
当选中的是单纯一个路径时:

void CXXXDlg::OnSelPath()
{
 UpdateData();
 CString m_fileDir;
 BROWSEINFO bi;
 ZeroMemory(&bi, sizeof(BROWSEINFO));
 bi.hwndOwner = m_hWnd;
 bi.ulFlags = BIF_RETURNONLYFSDIRS;
 LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
 BOOL bRet = FALSE;
 TCHAR szFolder[MAX_PATH*2];
 szFolder[0] = _T('/0');
 if (pidl)
 {
  if (SHGetPathFromIDList(pidl, szFolder))
  {
   bRet = TRUE;
  }
  IMalloc *pMalloc = NULL;
  if (SUCCEEDED(SHGetMalloc(&pMalloc)) && pMalloc)
  {
   pMalloc->Free(pidl);
   pMalloc->Release();
  }
 }
 m_strSelPath = szFolder;
 UpdateData(FALSE);
}
原创粉丝点击