Board index » Visual Studio » How to save a file using a default name

How to save a file using a default name

Visual Studio372
Hi everyone,



I'm using CFileDialog to save a file. How can I set a default file name

under which to be saved in this dialog?



I tried to do the following, it did not work:



CFileDialog saveFileDlg(FALSE, NULL, NULL,

OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,

"Output Files (*.txt)|*.txt||");



saveFileDlg.m_ofn.lpstrFile = "Out.txt";

saveFileDlg.m_ofn.nMaxFile = strlen("Out.txt");

saveFileDlg.DoModal();





I appreciate any help,



Geo


-
 

Re:How to save a file using a default name

The third parameter (1,2,3) is actually the name you want to use by default.

The ofn stuff is really only useful for opening files. So you would put



CFileDialog saveFileDlg(FALSE, NULL, "Out.txt",

OFN_HIDEREADONLY |

OFN_OVERWRITEPROMPT,

"Output Files (*.txt)|*.txt||");



The other buffer is used for returning multiple filenames. The

documentation is a little fuzzy. nMaxFile would tell the CFileDialog how

many characters the buffer can hold:



dlg.m_ofn.lpstrFile = FileBuffer.GetBuffer(16384);

dlg.m_ofn.nMaxFile = 16384;



You can then read through the file list after the DoModal() call returns

IDOK:



POSITION Pos = dlg.GetStartPosition();

while(Pos != NULL) {

csFile = dlg.GetNextPathName(Pos);

}



Of course, you wouldn't do this for saving a file.. and I don't know why I

dropped in this bit of trivia, but now that I've typed it all...



I hope the other answer helps some.



Tom



"Geo" <Geo@discussions.microsoft.com>wrote in message

Quote
Hi everyone,



I'm using CFileDialog to save a file. How can I set a default file name

under which to be saved in this dialog?



I tried to do the following, it did not work:



CFileDialog saveFileDlg(FALSE, NULL, NULL,

OFN_HIDEREADONLY |

OFN_OVERWRITEPROMPT,

"Output Files (*.txt)|*.txt||");



saveFileDlg.m_ofn.lpstrFile = "Out.txt";

saveFileDlg.m_ofn.nMaxFile = strlen("Out.txt");

saveFileDlg.DoModal();





I appreciate any help,



Geo





-

Re:How to save a file using a default name

Thank you very much Tom for your generosity.



Geo



"Tom Serface" wrote:



Quote
The third parameter (1,2,3) is actually the name you want to use by default.

The ofn stuff is really only useful for opening files. So you would put



CFileDialog saveFileDlg(FALSE, NULL, "Out.txt",

OFN_HIDEREADONLY |

OFN_OVERWRITEPROMPT,

"Output Files (*.txt)|*.txt||");



The other buffer is used for returning multiple filenames. The

documentation is a little fuzzy. nMaxFile would tell the CFileDialog how

many characters the buffer can hold:



dlg.m_ofn.lpstrFile = FileBuffer.GetBuffer(16384);

dlg.m_ofn.nMaxFile = 16384;



You can then read through the file list after the DoModal() call returns

IDOK:



POSITION Pos = dlg.GetStartPosition();

while(Pos != NULL) {

csFile = dlg.GetNextPathName(Pos);

}



Of course, you wouldn't do this for saving a file.. and I don't know why I

dropped in this bit of trivia, but now that I've typed it all...



I hope the other answer helps some.



Tom



"Geo" <Geo@discussions.microsoft.com>wrote in message

news:E008BE97-51D2-468E-B0A9-41C63BA9D4C5@microsoft.com...

>Hi everyone,

>

>I'm using CFileDialog to save a file. How can I set a default file name

>under which to be saved in this dialog?

>

>I tried to do the following, it did not work:

>

>CFileDialog saveFileDlg(FALSE, NULL, NULL,

>OFN_HIDEREADONLY |

>OFN_OVERWRITEPROMPT,

>"Output Files (*.txt)|*.txt||");

>

>saveFileDlg.m_ofn.lpstrFile = "Out.txt";

>saveFileDlg.m_ofn.nMaxFile = strlen("Out.txt");

>saveFileDlg.DoModal();

>

>

>I appreciate any help,

>

>Geo







-