VS2008,CEdit控制抖动和眨眼...... [英] VS2008, CEdit control shake and blink badly...

查看:127
本文介绍了VS2008,CEdit控制抖动和眨眼......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,亲爱的大家,当我使用CEdit从波特率为115200bps的串口接收数据时,换行时,我设置CEdit新内容,但问题是EDIT控件抖动和闪烁。请问,我怎样才能正常显示收到的数据?



用于更新CEdit控件的代码如下:



Hi, dear everyone, When I use CEdit to receive data from serial whose baudrate is 115200bps, when newline comes, i set the CEdit new content, BUT the problem is that the EDIT control shakes and bliks. please, How can I make it normally show the received data?

my code which is used to update CEdit control follows:

m_EditSerialRcv.SetRedraw(FALSE);
int nLength = m_EditSerialRcv.SendMessage(WM_GETTEXTLENGTH);
 if (nLength > 10240)
 {
    nLength = 0;
    m_EditSerialRcv.Clear();
}
m_EditSerialRcv.SetSel(nLength, nLength);
m_EditSerialRcv.ReplaceSel(buf);
m_EditSerialRcv.LineScroll(m_EditSerialRcv.GetLineCount());
m_EditSerialRcv.SetRedraw(TRUE);





Aescleal编辑(16/04/2012)



(删除解决方案2,因为这是来自提问者的评论,而非解决方案)



附加信息:该程序非常小,提问者(实际上)不希望实现新控件的痛苦。



Edited by Aescleal (16/04/2012)

(removed solution2 as it was a comment from the questioner, not a solution)

Additional Info: The program is really small, the questioner doesn't (understandably) want the pain of implementing a new control.

推荐答案

它看起来你的问题是你将文本填充到控件中的速度要快于它能够正确显示它。一个高波特串行端口想要每秒填充1000个字符到控件中,这是一个相当数量的应对。它实际上只是用于处理人类打字速度周围的文本输入。



为了证明这种事情会影响其他应用程序,请启动记事本文件,足以填写大约3个窗口值并开始向下滚动。滚动页面底部时,您会看到文本闪烁。如果您仍然不相信选择大量文本并将其重复粘贴到文档中。这也可能会导致闪烁。



无论如何,关键在于你是以一个地狱般的速度粘贴大块文本。 />


那么你能做些什么呢?我的第一反应是创建一个显示数据的自定义控件。此控件具有以下特征:



- 没有滚动条

- 实现滚动的函数(定义消息)整个shebang一次上升一行

- 实现另一个在控件底部显示一行文本的函数;实际上是自己画它来调用TextOut或DrawText

- 只画一个固定的音高字体,它可以更容易地计算出一行中的文字数量!



每当你得到足够的文字来填充一行而且只有这样:



- 将你的文字向上滚动

- 在底部绘制新的接收文本行



不要打扰窗口无效,只需滚动并绘制。这意味着你不必费心让你的控件实际记住提供给它的文本以及随之而来的所有内存管理问题。因为你不记得在收到WM_PAINT消息时你写的是什么文本 - 只需忽略它。这意味着当您从应用程序切换时,控件将丢失任何被遮盖的文本(如果应用程序已最小化或覆盖最大化窗口,则会丢失所有文本)。然而,由于您从串行线生成数据的速度,窗口很快就会再次填满。除非你有一个比我更大的显示器,在这种情况下我也想要一个。



加速似乎来自不缓冲文本在控件中,使滚动和新文本显示尽可能小。



我用这种技术来记录对于控制台窗口来说太快的调试信息。我写的控件能够跟上长达128个字符的显示行,并且闪烁非常小。这大约是你需要显示器移动速度的1/8,但它比我使用编辑控件更好,我从未以更高的速率测试过它。



现在......如果您不知道如何编写自定义控件该怎么办?我会抓两本书,两本都可能已绝版:



- 编程Windows(第5版) - Charles Petzold

- 使用MFC编程Windows(第2版) - Jeff Prosise



虽然购买新版本的成本和手臂和腿,你可以选择它们的副本在英国总计约40英镑,
It looks like your problem is that you're stuffing text into the control faster than it can manage to display it properly. A high baud serial port is going to want to stuff 1,000 characters a second into the control which is a fair amount for it to cope with. It's really only meant for coping with text entry at something around a human's typing speed.

To demonstrate that this sort of thing affects other apps start notepad up with a really big file, enough to fill about 3 windows worth and start scrolling down. You'll see the text flickering as you scroll off the bottom of the page. If you're still not convinced select a large chunk of text and paste it repeatedly into the document. That'll probably cause a flicker as well.

Anyway, the point is that you're pasting in large chunks of text at one hell of a rate.

So what can you do about it? My first reaction would be to create a custom control that displays the data. This control would have the following characteristics:

- Don't have scroll bars
- Implement a function (define a message) that scrolls the whole shebang up one line at a time
- Implement another function which displays a line of text at the bottom of the control; actually draw it yourself calling TextOut or DrawText
- Only draw in a fixed pitch font, it makes it easier to calculate how much text can go in a line!

Every time you get enough text to fill a line and only then:

- scroll your text up a line
- draw the new line of received text at the bottom

Don't bother invalidating the window, just scroll and draw. This means you don't need to bother having your control actually remember the text supplied to it and all the memory management headaches that go with it. As you don't remember what text to you've written when you get a WM_PAINT message - just ignore it. This means when you switch away from your app the control will loose any text that gets covered up (or all of it if the app's minimised or covered with a maximised window). However with the speed you're generating data from the serial line the window will soon fill up again anyway. That's unless you've got a far bigger monitor than I've got, in which case I want one too.

The speed ups seem to come from not buffering text in the control and making scrolling and new text display as minimal as possible.

I've used this technique to record debugging information that was going too fast for a console window. The control I wrote was able to keep up with displaying lines of up to 128 characters long and had remarkably little flicker. This is about 1/8 of the speed you'll need the display to move but it's better than I managed with an edit control and I never tested it at higher rates.

Now... what to do if you don't know how to write custom controls? I'd grab two books, both of which are probably out of print:

- Programming Windows (5th Edition) - Charles Petzold
- Programming Windows with MFC (2nd Edition) - Jeff Prosise

While it costs and arm and a leg to buy new copies you can pick used copies of the pair of them for a total of about £40 in the UK,


50美国。对不起,我不知道世界其他地方,但亚马逊通常有交易员鞭打他们的二手。它们是关于如何使用和不使用MFC编程Windows的很好的参考。如果你想成为一个使用C ++和MFC的严肃的Windows UI程序员,我认为它们是必不可少的读物。如果他们没有为你编程文本,那么他们有足够的重量来作为攻击性武器使用。



无论如何,我希望这有助于所涉及的额外工作并不会让你太过沮丧。我也希望有人建议更快的解决方案,因为我很想知道如何在Windows中快速显示大量数据而不会闪烁太多!



干杯,


Ash



编辑母语失败
50 in the US. Sorry I don't know about the rest of the world, but Amazon usually have traders who flog them second hand. They're good references on how to program Windows with and without MFC. If you intend to be a serious windows UI programmer using C++ and MFC they're essential reads in my opinion. And they have the bonus of being heavy enough to use as offensive weapons if they don't do it for you as programming texts.

Anyway, I hope this helps and doesn't depress you too much with the extra work involved. I also hope someone suggests a quicker solution as I'd love to know how to display loads of data quickly in windows without flickering too much!

Cheers,

Ash

Edited for Mother Tongue failiure


Aescleal解决方案1是一个非常好的解释。



如果你不想创建自定义控件,可以减少闪烁。但是使用 CEdit 控件无法完全避免。



现有代码可以调整:



  • 您可以自己计算使用过的编辑尺寸,并避免调用 GetLength()
  • 调用 LineScroll()不是必需的,因为使用 ReplaceSel()将在这里滚动。
Solution 1 by Aescleal is a very good explanation.

If you don't want to create a custom control, it may be possible to reduce the flickering. But it can't be totally avoided using a CEdit control.

You existing code can be tweaked:

  • You may count the used edit size yourself and avoid calling GetLength().
  • Calling LineScroll() is not necessary, because using ReplaceSel() will scroll here.


这篇关于VS2008,CEdit控制抖动和眨眼......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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