Increase the number of characters in the file name field of the GetOpenFileName file dialog box

Our application allows you to select multiple files in the file selection dialog box, which is displayed through the GetOpenFileName function (this question also applies to people using CFileDialog, etc.)

It seems that the number of characters that can be entered in the file name field (the limit of 259 seems to be a magic number - it is not clear why).

We tried to modify the following elements of the OPENFILENAME structure:

lpstrFile - specify our own 4 kb buffer nMaxFile - set the size of lpstrFile (we compile ANSI, so this is actually 4000

But these values ​​do not increase the input width of the file name field in the dialog box.

I'm going to experiment with sending EM_SETLIMITTEXT messages to the control, but would like to know if anyone has a solution.

EDIT - I decided it myself: a decision I can’t take my own answer, but here it is for posterity. If someone else has a better solution, send it or feel free to modify my solution so that future search engines find it at the top.

+4
source share
3 answers

It turns out that the edit control (at least in my development environment) is a combo box, so EM_SETLIMITTEXT not suitable.

Instead, I highlighted the combo box using GetDlgCtrl in the parent window of the file open dialog (I do this in the OnInitDialog handler), add it to CComboBox* , then call LimitText() to set the limit.

You can also do this by sending a CB_LIMITTEXT message to the control for those of you who are not working with CFileDialog . The corresponding value here is most likely the value OPENFIILENAME.nMaxFile that is being passed.

+4
source

From Naming a file or directory in MSDN :

In the Windows API (with some exceptions described in the following paragraphs), the maximum path length is MAX_PATH , which is defined as 260 characters.

Even if you could push longer lines from the dialog box, you might run into difficulties using the APIs that were encoded using MAX_PATH .

The docs say:

The Windows API has many functions that also have Unicode versions for allowing an extended path for a maximum total path length of 32,767 characters. This type of path consists of components separated by a backslash, each up to the value returned in the lpMaximumComponentLength parameter of the GetVolumeInformation function. to specify the path of extended length, use the prefix "\\?\" . For example, "\\?\D:\<very long path>" . (The characters < > are used here for visual clarity and cannot be part of a valid path string.)

+1
source

I believe that this is a hard limit that cannot be circumvented. The only time this is necessary is when you want to select more than one file, since this limit is enough for the maximum length of the file name.

I added "All Files" to these dialogs to open all the files in the folder; what is the only workaround i found.

0
source

All Articles