windows-7 - 在 Win7 上 GetOpenFileName 函数忽略 lpstr InitialDir 参数

标签 windows-7

我正在使用 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/

相关文章:

delphi - COM Elevation Moniker 在 Vista/Windows 7 下无法提升服务器

c# - Windows 手机 xml 解析

java - 为什么我的 Java 应用程序成功关闭 Windows 资源管理器,但无法再次重新启动它?

ssl - Windows 7下的makecert问题

c# - 如何以编程方式创建适用于 XP、Vista 和 Windows 7 的文件关联

vb6 - VB6 IDE 是否可以在 Windows 7/8/10 64 位上运行?

visual-c++ - OpenCV imwrite 2.2 在 Windows 7 上导致异常,消息为 "OpenCV Error: Unspecified error (could not find a writer for the specified extension)"

r - 使用 R 在 Windows 7 中安装 Pandoc

python - 如何在 python 中使用 espeak

cordova - 为 Windows 7 构建 Cordova 应用程序