How to prevent CRichEditCtrl to jump to the bottom of the text when a new line is inserted - Programmer

This is a discussion on How to prevent CRichEditCtrl to jump to the bottom of the text when a new line is inserted - Programmer ; Question::Question() { I developped a control derived from CRichEditCtrl which - at any time get some lines added at the end, lines come from external events (avg: a line each 2 seconds) - those lines are formatted (font, color, ....) ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: How to prevent CRichEditCtrl to jump to the bottom of the text when a new line is inserted

  1. How to prevent CRichEditCtrl to jump to the bottom of the text when a new line is inserted

    Question::Question() {

    I developped a control derived from CRichEditCtrl which
    - at any time get some lines added at the end, lines come from
    external events (avg: a line each 2 seconds)
    - those lines are formatted (font, color, ....)
    - the user can scroll H or V, select text ... }
    - this is a ReadOnly (for the user) control

    Question::Problem() {

    The lines are added using
    SetSel (-1, -1);
    ReplaceSel(new_lines); // actually I saved and restore the
    previous selected area, but it does not matter

    This is all working fine but one annoying problem:
    When the user scrolls up to view or select text above the visible
    lines, a new line event may interrupt his action, and the

    control goes back to the bottom, showing the new inserted lines. For
    instance the user scrolls up to view some previous lines,

    and unfortunately before he could read them, a new line is being
    inserted, consequently the control displays this new line (at

    the bottom) and the user has to scroll up again... }

    Question::ArleadyTried() {

    I already tried the following:
    - play with scroll events after overriding WindowProc : but this
    events are not used when inserting
    (spy++ confirmed this, only non interesting ones are emitted)
    - play with SetEventMask but nothing relevant there
    - manage myself the V scrolling : but there is - seemingly - no way
    to request a given line to be displayed at top of window (

    there is a GetFirstVisibleLine() but no Set... one !)

    Well, there are some other ways maybe, like buffering the input when
    the LButton is clicked but ... when the user release the

    button from Vscroll to select something for instance.... it does not
    work }

    Question::~Question() {

    Is CRichEditCtrl that closed to any convenient customization ?
    I thought this would be easy to do but it finally seems quite hard!

    So, how to prevent CRichEditCtrl to jump to the bottom of the text
    when a new line is inserted (at the end) ?

    Any idea is welcome,

    thank you
    }

  2. Re: How to prevent CRichEditCtrl to jump to the bottom of the text when a new line is inserted

    Believe it or not I couldn't recreate your problem, when I did what you are
    doing, it added the text to the bottom without scrolling to the end. I have
    a feeling there is some code after the ReplaceSel that scrolls the edit
    control to the bottom.

    Ali R.

    "Alex Deden" wrote in message
    news:ed80af7c.0402021338.775b961a@posting.google.c om...
    > Question::Question() {
    >
    > I developped a control derived from CRichEditCtrl which
    > - at any time get some lines added at the end, lines come from
    > external events (avg: a line each 2 seconds)
    > - those lines are formatted (font, color, ....)
    > - the user can scroll H or V, select text ... }
    > - this is a ReadOnly (for the user) control
    >
    > Question::Problem() {
    >
    > The lines are added using
    > SetSel (-1, -1);
    > ReplaceSel(new_lines); // actually I saved and restore the
    > previous selected area, but it does not matter
    >
    > This is all working fine but one annoying problem:
    > When the user scrolls up to view or select text above the visible
    > lines, a new line event may interrupt his action, and the
    >
    > control goes back to the bottom, showing the new inserted lines. For
    > instance the user scrolls up to view some previous lines,
    >
    > and unfortunately before he could read them, a new line is being
    > inserted, consequently the control displays this new line (at
    >
    > the bottom) and the user has to scroll up again... }
    >
    > Question::ArleadyTried() {
    >
    > I already tried the following:
    > - play with scroll events after overriding WindowProc : but this
    > events are not used when inserting
    > (spy++ confirmed this, only non interesting ones are emitted)
    > - play with SetEventMask but nothing relevant there
    > - manage myself the V scrolling : but there is - seemingly - no way
    > to request a given line to be displayed at top of window (
    >
    > there is a GetFirstVisibleLine() but no Set... one !)
    >
    > Well, there are some other ways maybe, like buffering the input when
    > the LButton is clicked but ... when the user release the
    >
    > button from Vscroll to select something for instance.... it does not
    > work }
    >
    > Question::~Question() {
    >
    > Is CRichEditCtrl that closed to any convenient customization ?
    > I thought this would be easy to do but it finally seems quite hard!
    >
    > So, how to prevent CRichEditCtrl to jump to the bottom of the text
    > when a new line is inserted (at the end) ?
    >
    > Any idea is welcome,
    >
    > thank you
    > }




+ Reply to Thread