Problems scrolling in an edit box
-
Hi, Has anyone any ideas why LineScroll() does not work in a subclassed edit box? When inserting text and trying to scroll to the end, a carriage return is added to the top of the text and the caret goes to the second line. It looks pretty much like this: CString Container(""); int nLines; GetWindowText(Container); Container += "\r\n" + strText; SetWindowText(Container); nLines = GetLineCount(); LineScroll(nLines); Cheers, /Fredrik Do you Sonork? I do! 100.11430 PhatBoy
-
Hi, Has anyone any ideas why LineScroll() does not work in a subclassed edit box? When inserting text and trying to scroll to the end, a carriage return is added to the top of the text and the caret goes to the second line. It looks pretty much like this: CString Container(""); int nLines; GetWindowText(Container); Container += "\r\n" + strText; SetWindowText(Container); nLines = GetLineCount(); LineScroll(nLines); Cheers, /Fredrik Do you Sonork? I do! 100.11430 PhatBoy
Hmmm... Will LineScroll(...) work of you do not have a scrollbar visible? If you are trying to "get to the end" of the text, why not use SetSel(...) to move the caret to the end of the text? Or am I just missing what you are trying to do? BTW: try not to use "" to represent an empty string with dealing with CStrings, use afxEmptyString instead. And, you do not need to initialize a CString with an empty string. It constructs to an empty string by default. (Initializing it with an empty string just wastes time.) -=- James.
-
Hmmm... Will LineScroll(...) work of you do not have a scrollbar visible? If you are trying to "get to the end" of the text, why not use SetSel(...) to move the caret to the end of the text? Or am I just missing what you are trying to do? BTW: try not to use "" to represent an empty string with dealing with CStrings, use afxEmptyString instead. And, you do not need to initialize a CString with an empty string. It constructs to an empty string by default. (Initializing it with an empty string just wastes time.) -=- James.
Well, the scrollbar is visible, and I am indeed trying to scroll to the last line of the box. I tried to use SetSel(), but then the text disappears... Using LineScroll() works with a non-subclassed edit box. I have written handlers for OnChar(), OnKeyDown() and OnRButtonDown() in the subclassed version. Could that cause any trouble? Cheers, /Fredrik Do you Sonork? I do! 100.11430 PhatBoy
-
Well, the scrollbar is visible, and I am indeed trying to scroll to the last line of the box. I tried to use SetSel(), but then the text disappears... Using LineScroll() works with a non-subclassed edit box. I have written handlers for OnChar(), OnKeyDown() and OnRButtonDown() in the subclassed version. Could that cause any trouble? Cheers, /Fredrik Do you Sonork? I do! 100.11430 PhatBoy
> I have written handlers for OnChar(), OnKeyDown() and > OnRButtonDown() in the subclassed version. Could that > cause any trouble? I would not think so. And what do you mean by "the text dissa[ears" when you use SetSel(...)? -=- James.
-
> I have written handlers for OnChar(), OnKeyDown() and > OnRButtonDown() in the subclassed version. Could that > cause any trouble? I would not think so. And what do you mean by "the text dissa[ears" when you use SetSel(...)? -=- James.
****James R. Twine wrote: I would not think so. And what do you mean by "the text disappears" when you use SetSel(...)? The text that is entered in the edit box disappears. It is not visible, and it can't be retrieved with GetWindowText(). :confused: Cheers, /Fredrik Do you Sonork? I do! 100.11430 PhatBoy
-
****James R. Twine wrote: I would not think so. And what do you mean by "the text disappears" when you use SetSel(...)? The text that is entered in the edit box disappears. It is not visible, and it can't be retrieved with GetWindowText(). :confused: Cheers, /Fredrik Do you Sonork? I do! 100.11430 PhatBoy
I realized if have been a bit unclear :-O ; what I am doing is that I have subclassed an edit box and added an OnChar handler. The OnChar handler adds text and scrolls to the bottom. Looks something like this: void CMySubclassedEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { CString strText("Text\r\n>"); CString Container; int nLines; if (nChar == 0x0D) { GetWindowText(Container); Container += "\r\n" + strText; SetWindowText(Container); nLines = GetLineCount(); LineScroll(nLines); } CEdit::OnChar(nChar, nRepCnt, nFlags); } Cheers, /Fredrik Do you Sonork? I do! 100.11430 PhatBoy
-
I realized if have been a bit unclear :-O ; what I am doing is that I have subclassed an edit box and added an OnChar handler. The OnChar handler adds text and scrolls to the bottom. Looks something like this: void CMySubclassedEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { CString strText("Text\r\n>"); CString Container; int nLines; if (nChar == 0x0D) { GetWindowText(Container); Container += "\r\n" + strText; SetWindowText(Container); nLines = GetLineCount(); LineScroll(nLines); } CEdit::OnChar(nChar, nRepCnt, nFlags); } Cheers, /Fredrik Do you Sonork? I do! 100.11430 PhatBoy
>> The text that is entered in the edit box disappears. >> It is not visible, and it can't be retrieved with GetWindowText(). If you are using the above code, and the text dissapears when you use SetSel(...), it might be due to the fact that your call to SetSel is incorrect, and is selecting the entire control. Then, the base CEdit::OnChar(...) gets called, which will replace the selection with whatever character was entered (a CR or LF); the result: no text in the control. Also, in the above code, "nLines" is not initialized. That might result in some strange scrolling effects. Lastly, if all you want to do is add a CRLF and some text to an edit control, the easiest (and faster than the code you posted) is to do a CEdit::SetSel(...) to get to the end of the control, and then call CEdit::ReplaceSel(...) with the text you want to add to the control. And since pasting normally moves the caret to the end of the pastes text, you will still be at the end of the edit control's text. Peace! -=- James.
-
>> The text that is entered in the edit box disappears. >> It is not visible, and it can't be retrieved with GetWindowText(). If you are using the above code, and the text dissapears when you use SetSel(...), it might be due to the fact that your call to SetSel is incorrect, and is selecting the entire control. Then, the base CEdit::OnChar(...) gets called, which will replace the selection with whatever character was entered (a CR or LF); the result: no text in the control. Also, in the above code, "nLines" is not initialized. That might result in some strange scrolling effects. Lastly, if all you want to do is add a CRLF and some text to an edit control, the easiest (and faster than the code you posted) is to do a CEdit::SetSel(...) to get to the end of the control, and then call CEdit::ReplaceSel(...) with the text you want to add to the control. And since pasting normally moves the caret to the end of the pastes text, you will still be at the end of the edit control's text. Peace! -=- James.
****James R. Twine wrote: >If you are using the above code, and the text dissapears when you use SetSel(...),
>it might be due to the fact that your call to SetSel is incorrect, and is selecting the entire control.
>Then, the base CEdit::OnChar(...) gets called,
>which will replace the selection with whatever character was entered (a CR or LF);
>the result: no text in the control.
Ah, right you are. It works if I remove the selection afterwards, naturally. Thank you for the help, much appreciated! Cheers,
/FredrikDo you Sonork? I do! 100.11430:PhatBoy