Its a little strange. Ok so I am working with OGRE game engine which has a "SceneManager" class which keeps some files streams open in background. If i use those streams just BEFORE using GetOpenFileName() those streams work fine, but if I try to use those streams AFTER GetOpenFileName() those strams are found to be closed. Can someone throw some light why GetOpenFileName() is killing my background streams?
String Submerge::showFileDialog(char* filters, bool savedialog, char* title)
// need to tweak flags for open/save
{
OPENFILENAME ofn ;
char szFile[255] ;
HWND hwnd = NULL;
//getOgre()->getAutoCreatedWindow()->getCustomAttribute("WINDOW", &hwnd);
ZeroMemory( &ofn , sizeof(ofn) );
ofn.hwndOwner = hwnd;
ofn.lStructSize = sizeof ( ofn );
ofn.lpstrFile = szFile;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof( szFile );
ofn.lpstrFilter = filters ? filters : "All files\0*.*\0";
ofn.nFilterIndex =1;
ofn.lpstrFileTitle = NULL ;
ofn.nMaxFileTitle = 0 ;
ofn.lpstrInitialDir=NULL ;
if(title!=NULL)
ofn.lpstrTitle=title;
//ofn.Flags = OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST ;
MeshLoadTest(); // this is where i use background file streams
bool success = false;
if(savedialog)
success = GetSaveFileName( &ofn );
else
success = GetOpenFileName( &ofn );
MeshLoadTest(); // this is where i use background file streams
if(!success)
return "";
String str;
str.append(ofn.lpstrFile);
return str;
return "";
}
Note that GetOpenFileName()
can and will change the current directory of your whole process. This might be interfering with whatever else you have going on.
There is an option called OFN_NOCHANGEDIR
, but according to the documentation, it's ineffective:
Restores the current directory to its original value if the user changed the directory while searching for files. Windows NT 4.0/2000/XP: This flag is ineffective for GetOpenFileName.
You should check the current directory before and after making this call; if it changes then this may be your problem. In that case, add code to save and restore the current directory around the call to GetOpenFileName()
.