visual-c++ - Vista 中 CEdit 中的 SetLimitText() 不起作用

标签 visual-c++ mfc windows-vista

这发生在 Vista 上。
我创建了一个新的基于对话框的 MFC 项目来测试这个。我在对话框中添加了一个 CEdit 控件。我调用 SetLimitText 让我的 CEdit 接收 100000 个字符。我都试过:

this->m_cedit1.SetLimitText(100000);
UpdateData(FALSE);


static_cast<CEdit*>(GetDlgItem(IDC_EDIT1))->LimitText(100000);

我将这些调用放在 InitDialog 上。

在我将 5461 个字符粘贴到我的 CEdit 中后,它变成空的并且没有响应。关于是什么导致这种情况和解决方法能够在 CEdit 或任何其他控件中粘贴长文本字符串的任何想法?

注意:5461 是二进制的 0x1555 或 1010101010101,我觉得这很奇怪。

如果我粘贴 5460 个字符,我没有问题。

最佳答案

我联系了微软支持。

目标是让大约
单曲 240000 个字符
可编辑的文本行。

我能够在
Windows Vista(x64 和 x32)但
不是在 Windows XP 上。

这段代码在 XP 中工作正常:

 BOOL ClongeditXPDlg::OnInitDialog()
 {
     CDialog::OnInitDialog();

     // Set the icon for this dialog.  The framework does this automatically
     //  when the application's main window is not a dialog
     SetIcon(m_hIcon, TRUE);            // Set big icon
     SetIcon(m_hIcon, FALSE);        // Set small icon

     // TODO: Add extra initialization here
     UINT limit = m_longEdit.GetLimitText();
     m_longEdit.SetLimitText(240000);
     UINT limit2 = m_longEdit.GetLimitText();

     CString str;
     str = _T("");
     for(int i = 0; i < 250000; i++)
         str += _T("a");

     m_longEdit.SetWindowText(str);

     return TRUE;  // return TRUE  unless you set the focus to a control
 }

如果我改用 CRichEdit 控件,
当我按下“结束”键或“右”
粘贴长字符串后的箭头”键
在里面,我看不到所有
Rich Edit Control 中的字符。
试图滚过最后一个可见的
字符产生蜂鸣声。其余的
人物就在那里,我知道这一点
因为如果我双击 Rich
编辑控件并使用复制文本
ctrl-c 然后将其粘贴到文本上
编辑,我可以看到240000
人物。所以控制保持
正确数量的字符,但是
最后一个字符不可见
除了在外部编辑器中,所以我的
原来的问题依然存在。

这是微软的答案
代表:

Problem here is that an edit control with a large number of characters in it does not paint its text.

I tried setting different characters, and discovered that I could fit more 'l's than 'x's than 'm's. The issue isn't directly the number of characters, but is likely the number of pixels. Multiplying the number of visible characters by the pixel width of the characters in the selected font shows that the limit is about 32k pixels.



微软的另一个回答:

I did extensive research on this issue and would like to update you about the case progress.

The primary difference between the Edit control on Vista and on XP is that the Edit control on Vista pre-composes its glyphs for better international support (internally, it ends up calling ExtTextOut with ETO_GLYPH_INDEX and an array of glyphs rather than a string of characters. This ends up saving the glyph indices into a metafile and so runs into the 32k pixel limit. When too many characters are provided, ExtTextOut fails and draws nothing. The Edit control on XP doesn't precompose the glyphs and so doesn't have this problem, but won't handle international characters as well.

The edit control on XP will clip at 32k, but since that is offscreen it isn't obvious. When scrolling to the right, it starts with the first visible character so the visible part of the control is always earlier than 32k pixels.

The RichEdit control draws the beginning, but after hitting End, edits occur mostly offscreen. RichEdit 3.0 and 4.1 gives similar behavior. This appears to be the 32k pixel limit of RichEdit control, as the it draws its text on an offscreen bitmap before displaying it to the screen.

Considering these points, the behavior is by design. You would need to create your own control to get the behavior of displaying as big string as 240000 in a single line.



最后一个:

I did further research on this issue for finding any light weight workaround for overcoming 32k pixels limit, but unfortunately it seems that there is no workaround for this.

Couple of alternatives that we tried are RichEdit 3.0, RichEdit 4.1, using UniScribe, using different fonts etc., but none of them seems to suffice your requirement.

Possibly, you would need to create your own custom control if you wish to display an editable single-line string which exceeds 32k pixel limit in Windows Vista.

关于visual-c++ - Vista 中 CEdit 中的 SetLimitText() 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/206600/

相关文章:

c++ - 如何让 Visual C++ 警告将 int 静默转换为字符串?

c++ - 拥有 std::map 的最佳方法,如果没有 key ,我可以在其中定义返回的内容?

windows-vista - 为什么 Vista Sidebar Gadget 不会出现在 Gadget Gallery 中?

c++ - 在 Visual C++ Express 2010 中创建静态库

c++ - 有没有办法检查一个字符串是否包含 C++ 中的 unicode 字符

c++ - MFC/Sql 相同情况下的不同异常

c++ - GetFieldValue 时间变量错误

c++ - 需要帮助以使用MFC C++创建图形

c++ - DLL 导出 4 个 COM 函数但不导出 COM 对象?!我就是不明白!

c# - ClickOnce 无法在 Windows Vista SP2 上安装 LocalDB 2012