增加 GetOpenFileName 文件选择对话框的文件名字段中的字符数
我们的应用程序允许在文件选择对话框中选择多个文件,该对话框通过 GetOpenFileName 函数显示(这个问题也适用于使用 CFileDialog 等的人...)
可以输入的字符数似乎有限制进入文件名字段(259 似乎是一个神奇的数字 - 不知道为什么)。
我们已尝试更改 OPENFILENAME 结构:
lpstrFile - 指向我们自己的缓冲区,大小为 4K 字节 nMaxFile - 设置为 lpstrFile 的大小(我们正在编译 ANSI,因此这实际上是 4000
但这些值似乎不会增加对话框中文件名字段的输入宽度。
我将尝试向控件发送 EM_SETLIMITTEXT 消息,但想知道其他人是否有解决方案 -
我自己解决了这个问题: 解决方案 我无法接受我自己的答案,但这是为了后代。如果其他人有更好的解决方案,请发布 - 或随意修改我的解决方案,以便未来的搜索者会在顶部找到它。
Our app allows multiple files to be selected in a file selection dialog which is shown via the GetOpenFileName function (this question also applies to folks using CFileDialog, etc...)
There appears to be a limit to the number of characters that can be typed into the filename field (259 seems to be the magic number - not sure why).
We have tried changing the following members of the OPENFILENAME structure:
lpstrFile - point to our own buffer, sized at 4K bytes
nMaxFile - set to the size of lpstrFile (we are compiling ANSI, so this is effectively 4000
But these values appear to not increase the input width of the filename field in the dialog.
I am going to experiment with sending a EM_SETLIMITTEXT message to the control, but wanted to know if anyone else has a solution.
EDIT - solved this myself: solution I can't accept out my own answer, but here it is for posterity. If anyone else has a better solution, please post it - or feel free to mod up my solution so future searchers will find it at the top.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
事实证明,编辑控件(至少在我的开发环境中)是一个组合框,因此
EM_SETLIMITTEXT
不合适。相反,我在文件打开对话框的父级上使用
GetDlgCtrl
追踪组合框(我在OnInitDialog
处理程序中执行此操作),将其转换为CComboBox*
,然后调用LimitText()
来设置限制。对于不使用
CFileDialog
的用户,也可以通过向控件发送CB_LIMITTEXT
消息来完成此操作。 这里合适的值很可能是传入的OPENFIILENAME.nMaxFile
值。Turns out that the edit control (At least in my development environment) is a combo box, so
EM_SETLIMITTEXT
isn't appropriate.Instead, I tracked down the combo box using
GetDlgCtrl
on the parent of the file open dialog (I do this in theOnInitDialog
handler), cast it toCComboBox*
, then callLimitText()
to set the limit.This could also be done by sending a
CB_LIMITTEXT
message to the control for those of you who are not working withCFileDialog
. The appropriate value here is most likely theOPENFIILENAME.nMaxFile
value that is passed in.来自在 MSDN 上命名文件或目录:
即使您可以将更长的字符串强制从对话框中取出,但在使用针对
MAX_PATH
编码的 API 时,您也可能会遇到麻烦。文档继续说:
From Naming a File or Directory on MSDN:
Even if you could coerce longer strings out of the dialog, you may run into trouble down the line when using APIs that have been coded against
MAX_PATH
.The docs go on to say:
我相信这是一个无法绕过的硬性限制。 唯一重要的是当您想要选择多个文件时,因为该限制足以满足最大文件名长度。
我在这些对话框中添加了一个“所有文件”按钮,用于打开文件夹中的所有文件; 这是我找到的唯一解决方法。
I believe this is a hard limit that cannot be bypassed. The only time it should matter is when you want to select more than one file, since the limit is enough for the maximum file name length.
I have added an "All Files" button to these dialogs for opening all of the files in a folder; that's the only workaround I have found.