SetLimitText () in CEdit in Vista does not work

This happens in Vista. To test this, I created a new dialog based MFC project. I added a CEdit control to my dialog. I called SetLimitText so that my CEdit gets 100,000 characters. I tried both:

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

and

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

I put these calls in InitDialog.

after I insert 5461 characters into my CEdit, it becomes empty and not responding. Any ideas on what causes this and workarounds to embed long lines of text in CEdit or any other control?

Note: 5461 is 0x1555 or 1010101010101 in binary format, which I find rather strange.

if i insert 5460 characters i have no problem.

+6
visual-c ++ windows-vista mfc
source share
3 answers

I contacted micro-content.

The goal was to have 240,000 characters in a single editable line of text.

I can reproduce the problem of Windows Vista (x64 and x32 both), but not in Windows XP.

this code works fine in XP:

  BOOL ClongeditXPDlg::OnInitDialog() { CDialog::OnInitDialog(); // Set the icon for this dialog. The framework does this automatically // when the application 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 } 

If instead I use CRichEdit when I press the "end" or "right arrow" key after pasting a long line inside, I cannot see all the characters in Rich Edit Control. an attempt to scroll through the last visible character produces a beep. The rest of the characters are there, I know this because if I double-click Rich Change the control and copy the text using ctrl-c, and then paste it into the text editor, I see 240,000 characters. Thus, the control keeps the correct number of characters, but the last characters are inaccessible for viewing except by an external editor, so my original problem remains.

Here are the answers from Microsoft Representatives:

The problem is that the edit control with a lot of characters in it does not draw text.

I tried setting different characters and found that I could fit more 'l than' x than 'm'. The problem is not the direct number of characters, but most 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 32 thousand pixels.

another answer from Microsoft:

I have done extensive research on this issue and would like to inform you about the progress.

The main difference between Change Management in Vista and XP is that the Edit control in Vista pre-compiles its glyphs for better international support (internally, it ends with calling ExtTextOut using ETO_GLYPH_INDEX and an array of glyphs rather than a character string. This results in saving the glyph indices in the metafile and thus 32k pixels. When too many characters are provided, ExtTextOut fails and draws nothing. Edit control over XP does not precede glyphs and therefore does not have this problem, but will not process intern odnye characters.

The XP editing control will be 32k, but since it is off-screen, it is not obvious. When scrolling to correctly, the visible character begins with the first, so the visible part of the control is always earlier than 32 thousand pixels.

The RichEdit control draws starting, but after hitting End, editing happens mostly off-screen. RichEdit 3.0 and 4.1 give similar behavior. This seems to be a 32k pixel RichEdit control limit, as it draws its text on the screen bitmap before displaying the screen.

Given these points, design behavior. You will need to create your own control in order to get the behavior of displaying a large line as 240000 in one line.

And last:

I continued research on this issue to find a light weight workaround to overcome 32k pixels but, unfortunately, it seems that there is no workaround for this.

A couple of alternatives that we tried RichEdit 3.0, RichEdit 4.1, using UniScribe, using different fonts, etc., But none of them seem to be enough of your requirement.

You may need to create your own controls if you want to display an editable single-line line that exceeds the 32k pixel limit in Windows Vista.

+5
source share

FYI - if the text is read-only / dsiplay-only, you can add some CR-LF to the line to correct the text display. It seems that the ExtTextOut function works a bit differently when newlines. Since this is a single-line editing block, the lines of a new line are erased, so the text looks the same - if you do not copy and paste it, the lines will be in the line ...

+1
source share

There should not be any problems with only 6,000 characters - maybe the problem is elsewhere? Do you have handlers for modified events / notifications from a text field? Maybe they hang out?

0
source share

All Articles