默认文件名在 Windows IFileDialog 中出现截断 [英] Default filename appears truncated in Windows IFileDialog

查看:16
本文介绍了默认文件名在 Windows IFileDialog 中出现截断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用 Windows IFileDialog 界面启动文件浏览器对话框时,如果提供的默认文件名超过一定数量的字符,我会遇到问题.

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.

文件名似乎被截断了,尽管它被简单地包裹起来,所以我们只能看到最后几个字符.似乎问题在于 Windows 文件浏览器对话框.每当提供的默认文件名超过 12-13 个字符时,它就会被环绕.

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?

操作系统详情:
Windows 10,版本 1709(操作系统内部版本 16299.1625)

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

对话快照:

下面分享的代码片段:
这是在单击BrowseFile"按钮时从 MFC 应用程序调用的函数.

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

推荐答案

我找到了解决此问题的方法,方法是将焦点设置到另一个控件并返回到文件名编辑框.

I found a workaround for this issue by setting the focus to another control and back to the filename edit box.

STDMETHODIMP MyFileDialogEventsImplementation::OnSelectionChange(IFileDialog* pfd)
{   
    if (!m_bInitialized)
    {
        m_bInitialized = true;

        IOleWindow* pOleWindow;
        if (SUCCEEDED(pfd->QueryInterface(IID_PPV_ARGS(&pOleWindow))))
        {
            HWND hwnd;
            if (SUCCEEDED(pOleWindow->GetWindow(&hwnd)))
            {
                CWnd* pDialog = CWnd::FromHandle(hwnd);
                
                if (pDialog != nullptr)
                {
                    CWnd* pCtrlWithFocus = pDialog->GetFocus();
                    
                    if (pCtrlWithFocus != nullptr)
                    {
                        CWnd* pNextDlgTabItem = pDialog->GetNextDlgTabItem(pCtrlWithFocus);

                        if (pNextDlgTabItem != nullptr)
                        {
                            pNextDlgTabItem->SetFocus();
                            pCtrlWithFocus->SetFocus();
                        }
                    }
                }

            }
            pOleWindow->Release();
        }
    }

    return S_OK;
}

这篇关于默认文件名在 Windows IFileDialog 中出现截断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆