有点奇怪。好的,所以我正在使用OGRE游戏引擎,该引擎具有“SceneManager”类,该类可使某些文件流在后台保持打开状态。如果我只是在使用GetOpenFileName()之前使用这些流,则这些流可以正常工作,但是如果我尝试在GetOpenFileName()之后使用这些流,则将发现这些层已关闭。有人可以解释为什么GetOpenFileName()杀死我的背景流吗?

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 "";
}

最佳答案

请注意,GetOpenFileName()可以并且将更改整个过程的当前目录。这可能会干扰您正在进行的其他操作。

有一个名为OFN_NOCHANGEDIR的选项,但是根据documentation,它是无效的:



在进行此调用之前和之后,您应该检查当前目录;如果它改变了,那么这可能是您的问题。在这种情况下,添加代码以保存和恢复对GetOpenFileName()的调用周围的当前目录。

关于c++ - GetOpenFileName()杀死了我的后台开放流:(,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1945584/

10-11 00:57