Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

moucard

error with GetOpenFileName

This topic is 5274 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

Hello to everyone. I've written a post last Friday but got no response. I did some tricks to remove my bug but they didn't catch so here goes one more try: In my program I need to save a trace file of the mouse events. All this is good. Last Friday I needed to add a file open operation so the user can select which level to load. What better I thought than to use window's own file open dialog (used it last week in another project, no trouble). This is the function I call to get the file name from the user:
void CGame::OpenFile()
{
	OPENFILENAME file;
	char szFile[MAX_PATH];
	//const short int maxPath = 260;

	char currDirectory[MAX_PATH];
	
	GetCurrentDirectory(MAX_PATH, currDirectory);
	strcat(currDirectory, "\\Levels");

	ZeroMemory(&file, sizeof(file));
	file.lStructSize = sizeof(file);
	file.hwndOwner = NULL;
	file.lpstrFile = szFile;

	file.lpstrFile[0] = '\0';
	file.nMaxFile = sizeof(szFile);
	file.lpstrFilter = "Coucou Cache Level\0*.lvl\0All\0*.*\0";
	file.nFilterIndex = 1;
	file.lpstrFileTitle = NULL;
	file.nMaxFileTitle = 0;
	file.lpstrInitialDir = currDirectory;
	file.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

	if (GetOpenFileName(&file)) {
		m_cCurrentLevelFilename = szFile;
	}
}
The problem is that if the user presses ok in the file open dialog the trace file won't get saved. In fact I tried the following change in the above code:
if (GetOpenFileName(&file)) {
       m_cCurrentLevelFilename = "Levels\\default.lvl";
}
  
I run the program two times (no changes to the source code). The first time, I selected a level (I know the selected file name is ignored but bear with me) pressed ok and my program could not load the level. Second run, I pressed escape and the "default" level loaded fine. I suppose this is the same reason why the trace file is not saved. So does anyone know why GetOpenFileName messes up with my fstreams? Any help appreciated. edit: This is an example how I open my files:
inFile.open(szLevelName_, ios_base::in | ios_base::binary);
 
[edited by - moucard on June 7, 2004 6:19:09 AM]

Share this post


Link to post
Share on other sites
Advertisement
Finally got the solution. The GetOpenFileName changed the default directory if the call was succesful. No wonder I couldn''t save my file afterwards! The OFN_NOCHANGEDIR flag should be set. Crappy documentation Microsoft! Should you write somewhere in the help files that this functions changes the directory?

Share this post


Link to post
Share on other sites

  • 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!