Default filename appears truncated in Windows IFileDialog(默认文件名在 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 中出现截断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:默认文件名在 Windows IFileDialog 中出现截断
基础教程推荐
- 从 std::cin 读取密码 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- Windows Media Foundation 录制音频 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01