我正在使用 GetOpenFileName
并设置 lpstrInitialDir
OPENFILENAME
成员(member)struct 到我想要的目录作为初始目录。但是在 Win7 上,我的应用程序似乎记住了用户上次打开的目录,并且忽略了 lpstrInitialDir
设置并转到最后一个目录。
Apparently this is by design
lpstrInitialDir
LPCTSTR
The initial directory. The algorithm for selecting the initial directory varies on different platforms.Windows 7:
1.If lpstrInitialDir has the same value as was passed the first time the application used an Open or Save As dialog box, the path most recently selected by the user is used as the initial directory.
2.Otherwise, if lpstrFile contains a path, that path is the initial directory.
3.Otherwise, if lpstrInitialDir is not NULL, it specifies the initial directory.
有谁知道如何阻止这种情况发生?
我希望我指定的目录是初始目录,而不管用户上次打开的文件是什么,即我希望应用上述条件 3。我做了显而易见的事情,并通过注册表进行了搜索,但找不到与问题相关的任何内容。
最佳答案
如果设置 lpstrFile
会发生什么到所需的初始目录路径(即 lpstrInitialDir
)。如果您正在使用 lpstrFile
要指定文件名,那么您可能需要在文件名之前添加初始目录路径。
关于windows-7 - 在 Win7 上 GetOpenFileName 函数忽略 lpstr InitialDir 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4117222/