FileDialog用于保存具体文件,但不是路径,怎样自己选择保存路径,有现成的控件或类吗?用Tree做好像有点麻烦!!!!!
SHBrowseForFolder(..)
void CHistory::OnFileSave()
{ CFileDialog dlgSave (FALSE, "rtf", "*.rtf", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "*.rtf");
if ( IDOK == dlgSave.DoModal())
{
//save CFile fSaveFile;
CFileException e;
if (!fSaveFile.Open(dlgSave.GetPathName(), CFile::modeCreate | CFile::modeWrite , &e))
{
#ifdef _DEBUG
afxDump << "File could not be opened " << e.m_cause << "\n";
#endif return;
}
SetSel(0,-1);
CString szText = GetSelText();
int iTextLength = GetWindowTextLength();
SetSel(iTextLength,iTextLength);
int iBufferSize = szText.GetLength();
LPCSTR lpBuffer = szText.LockBuffer();
TRY {
fSaveFile.Write(lpBuffer, iBufferSize);
} CATCH( CFileException, e )
{
#ifdef _DEBUG
afxDump << "File could not save " << e->m_cause << "\n";
#endif
}
END_CATCH
TRY {
fSaveFile.Close();
} CATCH( CFileException, e )
{
#ifdef _DEBUG
afxDump << "File could be closed " << e->m_cause << "\n";
#endif
}
END_CATCH
szText.UnlockBuffer();
}
}
象FAICHEN(CC)说的用SHBrowseForFolder(..),现成的东西!