CWnd文本框自动滚动建议 [英] CWnd textbox autoscroll advice

查看:80
本文介绍了CWnd文本框自动滚动建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建CWnd派生的文本框,并希望用户
以便能够继续在窗口范围之外输入内容,并使文本同步滚动-与具有自动滚动功能的CEdit控件相同.

由于窗口(编辑控件)的大小似乎没有变化,所以我想知道这是如何实现的.

我唯一能想到的是,您在
上键入 右侧边缘,字符从左侧删除,因此您
保持两个缓冲区.一个缓冲区就是整个文本,
另一个缓冲区是显示的值.只是一个猜测.

任何帮助我朝这个方向发展的建议将不胜感激.

再多考虑一下之后,我想在OnPaint()中,我只会根据光标/编辑位置的位置来选择要打印的某些字符.我会变暖吗?

I''m creating a CWnd derived textbox and want the user
to be able to continue typing beyond the limits of the window and have the text scroll in sync - the same as a CEdit control with autoscroll.

Since the size of the window (edit control) does not appear to change, I''m wondering how this is accomplished.

The only thing I can think of is that as you type at the
right edge, characters are removed from the left so you
are keeping two buffers. One buffer is the entire text,
the other buffer is the displayed values. Just a guess.

Any suggestion to help me move in that direction would be appreciated.

After thinking about it a little more, I''m thinking that in OnPaint() I would only select the certain characters to print depending upon the location of the cursor/edit position. Am I getting warm?

推荐答案

这似乎行得通,我需要做更多的测试,但是
我认为它可以满足我的要求.

This seems to work, I have more testing to do, but
I think it does what I want.

CSize sz = dc.GetTextExtent(m_strBuffer);
if (rc.Width() < sz.cx){
     //not enough room to display all the characters
     CString strSub, strDisplay;
     strSub = "";
     for (int i=m_strBuffer.GetLength()-1; i >= 0; i--){
          strSub = m_strBuffer[i] + strSub;
          sz = dc.GetTextExtent(strSub);
          if (sz.cx < rc.Width()){
               strDisplay = strSub;  //building a display string
          }
          else {
              sz = dc.GetTextExtent(strDisplay);
	      SetCaretPos(CPoint(sz.cx + nCellMargin, nTopMargin));
              dc.DrawText(strDisplay, rc, unFormat);
              break;
          }
     }
}


这篇关于CWnd文本框自动滚动建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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