none
Default filename wrapped around in Windows IFileDialog RRS feed

  • Question

  • 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)

    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();
        }
    }


    Thursday, February 13, 2020 5:28 AM