Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello everyone i'm a "noob" to MFC programming. I created a dialog based application, and i want to do 2 things with it, first i have the user fill in a bunch of edit boxes and other things that manipulate variables. How do i make it save like a normal windows app so i can load it later and all the variables would be loaded, and changed and updated appropiately. I know how to do ofstream not really ifstream, but thats not really what i want. I want that default Save As dialog most GUIs have. Thanks in advance for any help you guys provide.

========================================================
You indicate MFC but not the language so specific examples are not possible right now. You have two choices. First, as you have guessed, save all that data to a file (it doesn't really matter too much what method you use as long as you read it back the same way you wrote it) and then when the program starts it can check for the files existence and if it exists it can then initialize those variable before displaying the dialog box. Your second option is to save these values to the registry and then read the same values back (if they exist) and initialize your variables in that manner. The only real difference is the speed of loading the values but unless your program has an exceptionally large number of values to keep track of, the difference will be negligable.borelli35

CFileDialog(
BOOL bOpenFileDialog,
LPCTSTR lpszDefExt = NULL,
LPCTSTR lpszFileName = NULL,
DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
LPCTSTR lpszFilter = NULL,
CWnd* pParentWnd = NULL );bOpenFileDialog = TRUE for "File Open" or FALSE for "Save As" dialog box
lpszDefExt = default file extension
lpszFileName = current file name
dwFlags = customization flags
lpszFilter = filters for File List box
pParentWnd = pointer to parent windowExample for File Open:
CFileDialog filedlg (TRUE, "*.BMP", "*.BMP",
OFN_FILEMUSTEXIST | OFN_NOREADONLYRETURN | OFN_LONGNAMES,
"Bitmap Files (*.BMP)|*.bmp|Bitmap Files (*.DIB)|*.DIB||", NULL);Example for Save As:
CFileDialog filedlg (FALSE, "*.BMP", "*.BMP",
OFN_HIDEREADONLY OFN_NOREADONLYRETURN | OFN_LONGNAMES,
"Bitmap Files (*.BMP)|*.bmp|Bitmap Files (*.DIB)|*.DIB||", NULL);

Actually i'm using C++ i didn't try the second reply yet so if that works i'll reply back if you don't see a reply i still need help

Ok i put this in my function for when you click save and it gave me these errors
Compiling resources...
Compiling...
StdAfx.cpp
Compiling...
BFArmoryWG.cpp
BFArmoryWGDlg.cpp
C:\Steve's Projects\BFArmoryWG\BFArmoryWGDlg.cpp(309) : error C2275: 'BOOL' : illegal use of this type as an expression
c:\program files\microsoft visual studio\vc98\include\windef.h(142) : see declaration of 'BOOL'
C:\Steve's Projects\BFArmoryWG\BFArmoryWGDlg.cpp(309) : error C2146: syntax error : missing ')' before identifier 'bOpenFileDialog'
C:\Steve's Projects\BFArmoryWG\BFArmoryWGDlg.cpp(309) : error C2059: syntax error : ')'
Help.cpp
objects.cpp
Projectile.cpp
urrectFeatures.cpp
Generating Code...
Error executing cl.exe.BFArmoryWG.exe - 3 error(s), 0 warning(s)

You mean you wanted a perfect working example???
#include <fstream.h>
...
CString filename;
ofstream out;// declare "Save As" file dialog
CFileDialog filedlg (FALSE, "*.txt", "*.txt",
OFN_HIDEREADONLY | OFN_NOREADONLYRETURN | OFN_LONGNAMES,
"Text Files (*.txt)|*.txt|All Files (*.*)|*.*||", NULL);
// show "Save As" file dialog
if (filedlg.DoModal () == IDOK) // user has chosen a file, so
{
filename = filedlg.GetPathName (); // extract its filename
out.open(filename); // open file
out << "test data" << endl; // write data
out.close(); // close file
}

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |