
void
TCommDlgWnd::CmFileOpen()
{
TFileOpenDialog::TData FilenameData
(OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST,
"All Files (*.*)|*.*|Text Files (*.txt)|*.txt|",
0, "", "*");
if (TFileOpenDialog(this, FilenameData).Execute() != IDOK) {
if (FilenameData.Errval) {
char msg[50];
wsprintf(msg, "GetOpenFileName returned Error #%ld", Errval);
MessageBox(msg, "WARNING", MB_OK | MB_ICONSTOP);
}
}
}
The file-save common dialog box serves as a single, consistent replacement
Using file save
for the many different types of dialog boxes that applications have
common dialog
previously used to let users choose file names.
boxes
TOpenSaveDialog::TData is used by both file-open and file-save common
dialog boxes.
In the following example, a file-save common dialog box prompts the user
for a file name to save under The default directory is \WINDOWS and the.
default extension is .BMP.
void
TCanvasWindow::CmFileSaveAs()
{
TOpenSaveDialog::TData data
(OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"Bitmap Files (*.BMP)|*.bmp|",
0,
"\\windows",
"BMP");
if (TFileSaveDialog(this, data).Execute() == IDOK) {
// save data to file
ifstream is(FileData->FileName);
if (!is)
MessageBox("Unable to open file", "File Error",
MB_OK | MB_ICONEXCLAMATION);
else
// Do file output
}
}
Chapter 8, Dialog box objects
191