GetOpenFileName 更改目录
问题:
有谁知道如何更改已运行的打开文件对话框的当前目录?
详细信息:
我有一个自定义的打开文件对话框(使用自定义模板添加额外的控件),该对话框还关闭了所有验证、现有检查和创建测试(通过 OpenFileName 标志)。
关闭这些功能会禁用对话框的内置行为,如果用户在“文件名”组合框中键入文件夹名称并按 Enter 键,则会导致对话框更改当前显示的文件夹。
我想重新添加该行为。 我可以通过钩子过程检测到这种情况何时发生。 我隐藏了“确定”按钮,关闭了它的加速器,并将我自己的“选择”按钮放在控件上。 这意味着我收到 CDN_FILEOK 消息的唯一时间是用户在输入后在文本框中按 Enter 键时。
但是,我无法弄清楚如何以编程方式告诉对话框更改当前目录。
我想我也许可以通过向窗口中的 SHELLDLL_DefView 控件发送某种消息来完成此操作,但我尚未找到任何相关文档。
Question:
Does anyone know how to change the current directory of an already running open file dialog?
Details:
I have a customized open file dialog (using a custom template to add extra controls) that also has all the validation, existing checks, and creation tests turned off (via the OpenFileName flags).
Turning those things off disables the built-in behavior of the dialog that will cause it to change the currently displayed folder if the user types a folder name into the "file name" combo box and hits the enter key.
I would like to add that behavior back. I can detect when this happens via the hook procedure. I've hidden the OK button, turned off it's accelerator, and put my own "select" button on the control. This means that the only time I get a CDN_FILEOK message is when the user hits enter in the text box after typing.
I can't, however, figure out how to programatically tell the dialog to change the current directory.
I was thinking that I might be able to accomplish this by sending some sort of a message to the SHELLDLL_DefView control in the window, but I haven't been able to find any documentation on it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定直接的答案,但如果您有 SPY++ 或任何其他消息窥探程序,请尝试检查更改普通 OpenFileName 对话框目录时经过的消息。 您可能会在那里找到答案(尽管这是一条艰难的出路)。
不过,其他人可能立刻就知道答案; 希望他们能做到。
I'm not sure of the direct answer, but if you have SPY++ or any other message snooping program, try checking the messages that go by when you change a normal OpenFileName dialog's directory. You might uncover the answer there (although it's the hard way out).
Someone else might know the answer off-hand though; let's hope they do.
我找到了解决方法。
事实证明,当验证关闭时,输入以“\”结尾的目录名仍然会更改正在显示的文件夹,但输入不以“\”结尾的目录名则不会。
使用spy++我可以看到,当按下回车键时,一条WM_COMMAND消息将被发送到带有wParam参数的公共对话框控件,该参数的高位字是BN_CLICKED,其低位字是ID_OK。
如果我对公共对话框进行子类化,我可以拦截该消息,更改文件名组合框中的文本,将消息转发到原始子类过程,然后将文本更改回来。
这有点麻烦,但它使我能够从对话框中获得我想要的行为。
I was able to figure out a work around.
It turns out that when validation is turned off, typing in a directory name that ends in a "\" will still change the folder being displayed, but typing in a directory name that does not end in a "\" will not.
Using spy++ I was able to see that when enter is hit a WM_COMMAND message will be sent to the common dialog control with a wParam argument whose hi-order word is BN_CLICKED and whose low order word is ID_OK.
If I subclass the common dialog I can intercept the message, change the text in the file name combo box, forward the message through to original subclass procedure, and then change the text back afterwards.
It's a little bit of hack, but it enables me to get the behavior I want from the dialog.