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 中出现截断
- Stroustrup 的 Simple_window.h 2022-01-01
- C++ 协变模板 2021-01-01
- 静态初始化顺序失败 2022-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 从python回调到c++的选项 2022-11-16
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 近似搜索的工作原理 2021-01-01