Click here to Skip to main content
15,905,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Posted
Updated 18-Mar-10 8:43am
v2

1 solution

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;
          }
     }
}
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900