-
April 12th, 2013, 11:18 AM
#1
CFileDialog saves file in Project File, not Specified File
Hello,
I'm very new to MFC & VisualC++. I'm using MSVS2010 Pro
I am trying to write/debug a simple form that saves and restores the content of some edit controls. It seems to work as expected, except the file saves only to the Project Folder, regardless of where I browse and select to save the file. I wonder if I'm missing a parameter and someone could help me?
(I hope this makes sense...)
Code:
void CMFC_FileDialogDlg::OnBnClickedbtnsave()
{
this->UpdateData();
CFile f;
//Kinda Correct, Works but still saves in Project Folder
BOOL b_OpenFileDialog = FALSE; //this doesn't act as bool in CFileDialog?
LPCTSTR lpszDefExt = L"bcr";
LPCTSTR lpszFileName = L"Car_Description";
DWORD dwFlags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
LPCTSTR lpszFilter = L"BCR Files (*.bcr) |*.bcr|All Files (*.*)|*.*|";
LPCTSTR pParentWind = NULL;
int dwSize = 0;
int bVistaStyle = 1;
CFileDialog FileDlg( FALSE, lpszDefExt, lpszFileName, dwFlags, lpszFilter, NULL, dwSize, bVistaStyle);
if( FileDlg.DoModal() == IDOK )
{
//CString m_strPathname = FileDlg.GetPathName(); //This actually gets intended folder name
f.Open( FileDlg.GetFileName(), CFile::modeCreate | CFile::modeWrite);
CArchive ar(&f, CArchive::store); //This seems to be the save & restore cmd
ar << m_Make << m_Model << m_Year << m_Doors << m_Owner; //These are the edit controls we're saving/restoring
ar.Close();
}
else
return;
f.Close();
}
My only experience is a little simple VB programming in Excel, so any specific examples would be much appreciated!
Also, rules seem to change from version to version? I have to "update" a number of undocumented programs. If anyone knows of any online tutorials I could read/follow along with that are somewhat up-to-date I would really appreciate it.
Thank you!
-
April 12th, 2013, 11:30 AM
#2
Re: CFileDialog saves file in Project File, not Specified File
Code:
//CString m_strPathname = FileDlg.GetPathName(); //This actually gets intended folder name
f.Open( FileDlg.GetFileName(), CFile::modeCreate | CFile::modeWrite);
You had it right in the line that's commented out.
-
April 12th, 2013, 11:41 AM
#3
Re: CFileDialog saves file in Project File, not Specified File
Is that actually a command? Do I need to implement it somewhere?
If I watch m_strPathname it's correct for where I intended it to save, but it still saves in the Project Folder.
-
April 12th, 2013, 11:49 AM
#4
Re: CFileDialog saves file in Project File, not Specified File
I meant GetPathname vs GetFileName
-
April 12th, 2013, 12:48 PM
#5
Re: CFileDialog saves file in Project File, not Specified File
Oh! That did it - thank you!
Must have been a typo in the tutorial.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|