Default filename appears truncated in Windows IFileDialog

[亡魂溺海] 提交于 2020-06-17 09:11:43

问题


When using the Windows IFileDialog interface to launch File browser dialog, I face an issue if the default filename provided exceeds certain number of characters.

The filename appears truncated, although it is simply wrapped around so that we can only see last few characters. It seems the issue lies with the Windows file browser dialog. Whenever the default filename provided exceeds 12-13 characters, it gets wrapped around.

Has anyone encountered such an issue? Is there any workaround?

OS detail:
Windows 10, Version 1709 (OS Build 16299.1625)

Dialog snapshot:

Code snippet shared below:
This is the function that gets called from an MFC application when a button - "BrowseFile" is clicked.

void CCustomFileBrowserNewDlg::OnBnClickedBrowseFile()
{
    IFileDialog* pfd = nullptr;
    IID id = CLSID_FileSaveDialog;

    const COMDLG_FILTERSPEC c_rgSaveTypes[] =
    {
        {L"Word Document (*.doc)",       L"*.doc"},
        {L"Web Page (*.htm; *.html)",    L"*.htm;*.html"},
        {L"Text Document (*.txt)",       L"*.txt"},
    };


    HRESULT hr = CoCreateInstance(id, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pfd));
    if (SUCCEEDED(hr))
    {
        hr = pfd->SetFileTypes(ARRAYSIZE(c_rgSaveTypes), c_rgSaveTypes);
        if (SUCCEEDED(hr))
        {
            hr = pfd->SetFileTypeIndex(1);
            if (SUCCEEDED(hr))
            {
                //pfd->SetFileName(L"Filename.txt");       // This is okay
                pfd->SetFileName(L"SomeLongFilename.txt"); // This name gets wrapped around
                pfd->Show(::GetActiveWindow());
            }
        }

        pfd->Release();
    }
}

回答1:


Few errors in your example. An example that you provided is of save dialog and screenshot is open dialog.

The issue that you are talking about will never reproducible on save dialog because filter combo box and save button are on the next line of default text edit control.

Now your problem is specific to open dialog and default text is not truncating its hiding towards left due to less space availability in the same line. i.e. since file name static text, default text edit control and filter combo box are on the same line, windows interpret this as less availability of space for default text and wrap the text towards left. If you scroll text cursor towards file name static control then you will get complete text. You may raise this concern to MSDN.

Now, a workaround to your problem is to show open file dialog in maximize mode. One way to do this is once a dialog is open then maximize it. Next onwards dialog will open in maximize mode.



来源:https://stackoverflow.com/questions/60182612/default-filename-appears-truncated-in-windows-ifiledialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!