Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need an Open Dialog 1

Status
Not open for further replies.

jvff

Programmer
Apr 1, 2001
64
BR
Hello,
I need a dialog for opening files. Is there already one in Microsoft VC++? If there is, how do I acces it? If not, how do I make one? Thanks,
:)
JVFF
 
There's one in Windows. You can access it with the GetOpenFileNAme() and GetSaveFileName() functions. In MFC you can use the CFileDialog class object. :) Hope that this helped! ;-)
 
How can I access CFileDialog in MFC? Can somebody send me a source-code example, please? ThanQ. ;-) Thank you,

JVFF (Janito Vaqueiro Ferreira Filho)
 
CFileDialog dlg(TRUE);

if (dlg.DoModal()==IDOK)
{
actions
}
HTW
 
Play with this code if you like. Just copy and paste. It will work. It will create a text file and print the time and date in it if you select .txt. If you don't select .txt you get a message box.

You'll need #include <fstream.h>


char Types[3][5] = {&quot;NULL&quot;,&quot;.txt&quot;,&quot;.ipd&quot;};
// setup save dialog
char saveFileName[50] = &quot;Sort&quot;;
CFileDialog dlgFile(FALSE);
dlgFile.m_ofn.lpstrTitle = &quot;Sort Save&quot;; // set window title
dlgFile.m_ofn.lpstrFile = saveFileName;
dlgFile.m_ofn.nMaxFile = sizeof(saveFileName);
dlgFile.m_ofn.lpstrFilter = &quot;Text File (.txt)\0*.txt\0Mpv File (.mpv)\0*.mpv&quot;;

// display save dialog
if(dlgFile.DoModal() == IDCANCEL){
return;
}

// add extention to file
strcat(dlgFile.m_ofn.lpstrFile,Types[dlgFile.m_ofn.nFilterIndex]);

// if user selected text
if(dlgFile.m_ofn.nFilterIndex == 1){

ofstream TextFile(dlgFile.m_ofn.lpstrFile);

CTime t = CTime::GetCurrentTime();
CString s = t.Format( &quot;%A, %B %d, %Y %H:%M &quot; );

TextFile << s << endl;
TextFile.close();
}
else{
AfxMessageBox(&quot;This save type is not implemented&quot;);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top