Advertisement Jump to content
Sign in to follow this  

Win32 File Open/Save Dialog Weirdness

This topic is 4937 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 All! Im getting some weird issues with open/save file dialogs in Win32. I create/load my resources from my base path. For example to create a log file when running I would call fopen( "event.log", "w");. As you can see I dont include the full path. Now I need to save/open files in my program. The problem is not opening but saving. If I call GetOpenFileName() all works fine. If I call GetSaveFileName() its like my entire 'program base path' changes to the path where I save my files. For example the log I just created above gets moved to this new path as soon as I click ok. I ZeroMemory() OPENFILENAME structures before use. I checked the following: HINSTANCE's, HWND's, FILE NAME STRING BUFFERS, BUFFER SIZES, etc... I declare these structures in C++ method scope, they arn't being passed as arguments.

wchar_t world_name[ MAX_PATH ] = "";

/* Before we can create the world we need to save it's file for the first time */
/* Setup open file structure */
ZeroMemory( &sfn, sizeof(sfn) );
sfn.hInstance = GetModuleHandle(0);
sfn.lStructSize = sizeof(sfn);
sfn.hwndOwner = window_get_handle();
sfn.lpstrFile = world_name;
sfn.nMaxFile = sizeof(world_name) / sizeof(wchar_t);
sfn.lpstrFilter = L"World\0*.wsf\0";
sfn.lpstrFileTitle = 0;
sfn.nMaxFileTitle = 0;
sfn.lpstrTitle = L"Save Created World As...";

/* Create and show the 'save file' dialog */
if ( ! GetSaveFileName( &sfn ) )
/* World creation aborted because user did not click ok when saving the file */
    return false;

I dont know why its doing this! Please help!

Share this post

Link to post
Share on other sites
There could be an implicit call to SetCurrentDirectory in the GetSaveFilename function.... It's not documented but the MSDN does have one or two omissions here and there [grin]

Try calling GetCurrentDirectory before and after the call... if it changes then you know this is the problem... and you should be able to remedy it fairly easily.

Share this post

Link to post
Share on other sites

Sandman, thank you very much! You are right!

I checked it before and after the call. Afterwards it was set to the save file path and no longer the path the program resides in.

Thanks Alot for the help!

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!