Jump to content
  • Advertisement
Sign in to follow this  
phil67rpg

mfc application

This topic is 3741 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am unclear as to what this code does. I think it opens a file open dialog box. bool SelectFile(CString& PathFileName, LPCTSTR sTitle) { CFileDialog fDlg(true); char dir[_MAX_PATH]; strcpy(dir, PathFileName); strcat(dir,"\0"); char filter[] = {"Open (*.TXT)\0*.TXT\0\0"}; fDlg.m_ofn.lpstrInitialDir = dir; fDlg.m_ofn.lpstrTitle = sTitle; fDlg.m_ofn.lpstrFilter = filter; if ( fDlg.DoModal() != IDOK ) { return false; } PathFileName = fDlg.GetPathName(); return true; }

Share this post


Link to post
Share on other sites
Advertisement
Why not run it and see?

It opens an "open file" dialog with the specified title and initial path, searching for text files (*.txt) and fills in the passed in string with the selected file and returns true if the user clicks the "OK" button, or returns false if they click "Cancel".

Incidently, there's at least 3 issues I see with that:
1. This does nothing: strcat(dir,"\0");
2. If PathFileName is longer than MAX_PATH characters, you'll corrupt your stack.
3. The initial directory passed to the CFileDialog points at a file, not a path (Although I don't tknow if this is a problem).

Share this post


Link to post
Share on other sites
Here is a short piece of code that I used to something that you want (open a file presumably)


CString szFile(TEXT("*.bmp"));
CString szFilter(TEXT("Bitmap Files (*.BMP)|*.bmp|JPEG Files (*.JPG)|*.jpg||"));

CFileDialog fDialog(TRUE, TEXT("bmp"), szFile, 0, szFilter, this);

m_bImageLoaded = FALSE;

if(fDialog.DoModal() == IDOK)
{
// load in the selected file
}
Check the MSDN for information on what parameters the CFileDialog class actually uses.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!