Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CRichEditCtrl problem

CRichEditCtrl problem

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestionlounge
11 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xtexistenz
    wrote on last edited by
    #1

    hey im having a rich edit problem.. lets say the control has some text.. more than its height size.. and you resize the rich edit in the dialog's WM_SIZE event from the bottom of the dialog to down youll see that the text in the rich edit remains at the same location and down there will be some empty space but the scrollbar position is down and when you click the scrollbar the text will go down at the bottom of the rich edit control where it should be when i resize it as well i tried so many methods of forcing the control to scroll down there but no one was really efficient and right for example i have this method [code] void CDDlg::OnSize(UINT nType, int cx, int cy) { CDialog::OnSize(nType, cx, cy); m_richedit.MoveWindow(200, 200, cx - 200, cy - 200, FALSE); m_richedit.PostMessage(WM_VSCROLL, SB_BOTTOM, 0); m_richedit.Invalidate(); } [/code] when i resize the dialog everything seems to work right but i can see the rich edit flicker the text up and then down which is pretty annoying.. i tried finding the message which tells the richedit that i resized it and make it not send the message.. but i couldnt really find it then i thought using LineScroll but i never figured it out how it works.. it doesnt really work right for me please think about both methods and tell me how i could do it right.. LineScroll seems ok.. but i kind of dislike the idea of a line scroll.. i use the rich edit as a chat window and it seems better if it has smooth scrolling instead of line scrolling anyway i cant really understand microsoft.. they released many versions of this control and never noticed their bug ??? i mean look at word pad which uses a rich edit control and do what i said above and resize it down after you add a lot of text.. youll see what happens which is very stupid IMO please help me.. im trying to fix this bug for many months ( im not joking ) and i cant continue my project.. im sure this will help many other people.. thanks

    X 1 Reply Last reply
    0
    • X xtexistenz

      hey im having a rich edit problem.. lets say the control has some text.. more than its height size.. and you resize the rich edit in the dialog's WM_SIZE event from the bottom of the dialog to down youll see that the text in the rich edit remains at the same location and down there will be some empty space but the scrollbar position is down and when you click the scrollbar the text will go down at the bottom of the rich edit control where it should be when i resize it as well i tried so many methods of forcing the control to scroll down there but no one was really efficient and right for example i have this method [code] void CDDlg::OnSize(UINT nType, int cx, int cy) { CDialog::OnSize(nType, cx, cy); m_richedit.MoveWindow(200, 200, cx - 200, cy - 200, FALSE); m_richedit.PostMessage(WM_VSCROLL, SB_BOTTOM, 0); m_richedit.Invalidate(); } [/code] when i resize the dialog everything seems to work right but i can see the rich edit flicker the text up and then down which is pretty annoying.. i tried finding the message which tells the richedit that i resized it and make it not send the message.. but i couldnt really find it then i thought using LineScroll but i never figured it out how it works.. it doesnt really work right for me please think about both methods and tell me how i could do it right.. LineScroll seems ok.. but i kind of dislike the idea of a line scroll.. i use the rich edit as a chat window and it seems better if it has smooth scrolling instead of line scrolling anyway i cant really understand microsoft.. they released many versions of this control and never noticed their bug ??? i mean look at word pad which uses a rich edit control and do what i said above and resize it down after you add a lot of text.. youll see what happens which is very stupid IMO please help me.. im trying to fix this bug for many months ( im not joking ) and i cant continue my project.. im sure this will help many other people.. thanks

      X Offline
      X Offline
      x87Bliss
      wrote on last edited by
      #2

      I never experienced this problem myself, but I did just dabble with it in Wordpad as you said, and I see what you're talking about. As you resize down it adjusts the scroll-bars range in respect to the size of the data, but it ignores the current scroll location being below the end of the data. I don't know what you have already tried. I would try to get a handle to the scroll-bar and use "SetScrollPos" and see if that forces an update. To prevent it from changing, you may try "SetScrollPos(GetScrollPos())" or similar, I don't know the return types or parameters of these functions off the top of my head, but that would in essence tell it the user has scrolled, although the position won't really change, but it may force it to redraw the text in the right spot. Another thing you can try is RedrawWindow() maybe. Again, these are just little workarounds that may work, but I'm sure it's not the "right" way to do it. But maybe it'll get the job done. I've never tried them myself either, just what I would try if I was doing it. Good Luck

      X 1 Reply Last reply
      0
      • X x87Bliss

        I never experienced this problem myself, but I did just dabble with it in Wordpad as you said, and I see what you're talking about. As you resize down it adjusts the scroll-bars range in respect to the size of the data, but it ignores the current scroll location being below the end of the data. I don't know what you have already tried. I would try to get a handle to the scroll-bar and use "SetScrollPos" and see if that forces an update. To prevent it from changing, you may try "SetScrollPos(GetScrollPos())" or similar, I don't know the return types or parameters of these functions off the top of my head, but that would in essence tell it the user has scrolled, although the position won't really change, but it may force it to redraw the text in the right spot. Another thing you can try is RedrawWindow() maybe. Again, these are just little workarounds that may work, but I'm sure it's not the "right" way to do it. But maybe it'll get the job done. I've never tried them myself either, just what I would try if I was doing it. Good Luck

        X Offline
        X Offline
        xtexistenz
        wrote on last edited by
        #3

        hey, thanks for the reply i have tried those before.. and no luck m_richedit.SetScrollPos(SB_VERT, m_richedit.GetScrollPos(SB_VERT)); m_richedit.RedrawWindow(); they don't do anything if you have any more ideas please post them here thanks :) btw you never experienced it because you never used the control ? or you never noticed it ? (just curious) -- modified at 19:01 Monday 19th March, 2007

        X 1 Reply Last reply
        0
        • X xtexistenz

          hey, thanks for the reply i have tried those before.. and no luck m_richedit.SetScrollPos(SB_VERT, m_richedit.GetScrollPos(SB_VERT)); m_richedit.RedrawWindow(); they don't do anything if you have any more ideas please post them here thanks :) btw you never experienced it because you never used the control ? or you never noticed it ? (just curious) -- modified at 19:01 Monday 19th March, 2007

          X Offline
          X Offline
          x87Bliss
          wrote on last edited by
          #4

          I've used the control, but not extensively enough to notice the problem. I've used it to write a paragraph worth of info basically, never had to use the scrolls. I was just saying that I don't have experience with the problem, but I was trying to offer things I would try as a solution if I did have that problem, but I see you're ahead of me, lol. I notice in Wordpad, when the problem occurs if I hit the down arrow on the scroll bar, it'll fix it. Have you tried using SendMessage to send messages to emulate the user doing that? I don't know what those messages are tho. The other thing you can do which may be "wrong" is int oldScrollPos = GetScrollPos(SV_VERT); SetScrollPos(SB_VERT, 0); SetScrollPos(SB_VERT, oldScrollPos); so it scrolls to the beginning then back to the end. I don't like it myself, it's sloppy, but if you want you can try it.

          X 1 Reply Last reply
          0
          • X x87Bliss

            I've used the control, but not extensively enough to notice the problem. I've used it to write a paragraph worth of info basically, never had to use the scrolls. I was just saying that I don't have experience with the problem, but I was trying to offer things I would try as a solution if I did have that problem, but I see you're ahead of me, lol. I notice in Wordpad, when the problem occurs if I hit the down arrow on the scroll bar, it'll fix it. Have you tried using SendMessage to send messages to emulate the user doing that? I don't know what those messages are tho. The other thing you can do which may be "wrong" is int oldScrollPos = GetScrollPos(SV_VERT); SetScrollPos(SB_VERT, 0); SetScrollPos(SB_VERT, oldScrollPos); so it scrolls to the beginning then back to the end. I don't like it myself, it's sloppy, but if you want you can try it.

            X Offline
            X Offline
            xtexistenz
            wrote on last edited by
            #5

            ah ok :P yes i tried PostMessage(WM_VSCROLL, SB_BOTTOM, 0); and SendMessage(WM_VSCROLL, SB_BOTTOM, 0); they do not work right if i dont add an Invalidate() after that but even after i do.. they cause the annoying flicker problem which i said at my first post your last solution doesnt work.. funny i can see the scrollbar flickering up and down but no change to the text area. lol. thanks again :)

            X 1 Reply Last reply
            0
            • X xtexistenz

              ah ok :P yes i tried PostMessage(WM_VSCROLL, SB_BOTTOM, 0); and SendMessage(WM_VSCROLL, SB_BOTTOM, 0); they do not work right if i dont add an Invalidate() after that but even after i do.. they cause the annoying flicker problem which i said at my first post your last solution doesnt work.. funny i can see the scrollbar flickering up and down but no change to the text area. lol. thanks again :)

              X Offline
              X Offline
              x87Bliss
              wrote on last edited by
              #6

              I recreated the problem in Wordpad, as you mentioned before, and created a program to send window messages to it to fix it. And this is what worked for me. You can send these messages from within your own program where necessary. I only made a seperate app, because I couldn't just rewrite wordpad :-P

              ::SendMessage(HandleOfRichEditControl, WM_VSCROLL, SB_LINEDOWN, 0);
              ::SendMessage(HandleOfRichEditControl, WM_VSCROLL, SB_ENDSCROLL, 0);

              The one with ENDSCROLL may not be needed, but it is sent after LINEDOWN when I press the down arrow on the scroll bar. So it may be needed for more accurate emulation of the user pressing it. Who knows.

              X 1 Reply Last reply
              0
              • X x87Bliss

                I recreated the problem in Wordpad, as you mentioned before, and created a program to send window messages to it to fix it. And this is what worked for me. You can send these messages from within your own program where necessary. I only made a seperate app, because I couldn't just rewrite wordpad :-P

                ::SendMessage(HandleOfRichEditControl, WM_VSCROLL, SB_LINEDOWN, 0);
                ::SendMessage(HandleOfRichEditControl, WM_VSCROLL, SB_ENDSCROLL, 0);

                The one with ENDSCROLL may not be needed, but it is sent after LINEDOWN when I press the down arrow on the scroll bar. So it may be needed for more accurate emulation of the user pressing it. Who knows.

                X Offline
                X Offline
                xtexistenz
                wrote on last edited by
                #7

                ah sorry for the late reply.. yeah it works.. same goes for SB_BOTTOM but the problem is it creates some flicker.. you could see the lines going up and then down very fast.. i just need to find a way to scroll it down and not have that flicker.. thats all and i have no idea.. thanks

                X 1 Reply Last reply
                0
                • X xtexistenz

                  ah sorry for the late reply.. yeah it works.. same goes for SB_BOTTOM but the problem is it creates some flicker.. you could see the lines going up and then down very fast.. i just need to find a way to scroll it down and not have that flicker.. thats all and i have no idea.. thanks

                  X Offline
                  X Offline
                  x87Bliss
                  wrote on last edited by
                  #8

                  It should only flicker as you're resizing, which shouldn't be that big of a deal? If it's flickering all time you probably have the scrolling code in the wrong place. A lot of controls flicker during resize AFAIK. You should be able to search up ways around that. I think it involves drawing the dialog off-screen and then repainting it on-screen, like a double buffer. I'm sure there are other ways too. I just know that you'll be able to find something.

                  X 1 Reply Last reply
                  0
                  • X x87Bliss

                    It should only flicker as you're resizing, which shouldn't be that big of a deal? If it's flickering all time you probably have the scrolling code in the wrong place. A lot of controls flicker during resize AFAIK. You should be able to search up ways around that. I think it involves drawing the dialog off-screen and then repainting it on-screen, like a double buffer. I'm sure there are other ways too. I just know that you'll be able to find something.

                    X Offline
                    X Offline
                    xtexistenz
                    wrote on last edited by
                    #9

                    that flicker is because the rich edit always scrolls the caret into view.. which is a scroll by line.. to get rid of that flickering i would have to disable that rich edit "feature" i dont think you understood what i meant by flickering.. its not the standard light flickering.. its a very bad flicker which can be very annoying on slower pc's, it moves the whole text up one line then down.. this is very noticeable.. i tried many ways.. like ignoring WM_PAINT while resizing but didnt make any change.. i got no idea

                    X 1 Reply Last reply
                    0
                    • X xtexistenz

                      that flicker is because the rich edit always scrolls the caret into view.. which is a scroll by line.. to get rid of that flickering i would have to disable that rich edit "feature" i dont think you understood what i meant by flickering.. its not the standard light flickering.. its a very bad flicker which can be very annoying on slower pc's, it moves the whole text up one line then down.. this is very noticeable.. i tried many ways.. like ignoring WM_PAINT while resizing but didnt make any change.. i got no idea

                      X Offline
                      X Offline
                      x87Bliss
                      wrote on last edited by
                      #10

                      Have you tried SetSel to move the caret to the end of the text, so this way it doesn't have to scroll it into position. SetSel, I think that's the name, should take 2 parameters, the first selected character and the last selected character. If they are the same, then it just moves the caret to that position. Should be something like... int Length = GetLength(); SetSel(Length, Length); SetSel may even have a third bool parameter too that tells it whether to scroll to the newly selected text. Using SetSel and telling it to scroll to the newly selected text may even fix the other scrolling problem. Good Luck.

                      X 1 Reply Last reply
                      0
                      • X x87Bliss

                        Have you tried SetSel to move the caret to the end of the text, so this way it doesn't have to scroll it into position. SetSel, I think that's the name, should take 2 parameters, the first selected character and the last selected character. If they are the same, then it just moves the caret to that position. Should be something like... int Length = GetLength(); SetSel(Length, Length); SetSel may even have a third bool parameter too that tells it whether to scroll to the newly selected text. Using SetSel and telling it to scroll to the newly selected text may even fix the other scrolling problem. Good Luck.

                        X Offline
                        X Offline
                        xtexistenz
                        wrote on last edited by
                        #11

                        thanks, SetSel only has 2 parameters.. anyway i meant even if the selection was at the end of the text it still tries to scroll it in its way (like line by line) which causes the flicker, when i try to force it stay down it first goes up one line and then down i hope this made sense.. if not please tell me and ill explain again :P if there was a way to slow down the PC a lot or just the application you could see it very clearly whats happening lol btw i dont think i have said this before.. but if you look at MSN Messenger you will see that it doesnt have any flickering problem and im pretty sure it uses the rich edit control.. but yea its made by microsoft so they know the rich edit's secret lol but theres also GameSpy Arcade.. which works without a problem i dunno how they do it.. all i see is that they put in a custom scrollbar.. but i dont see how that helped this is because of auto vscroll, actually really check this out.. remove the auto vscroll property and it will never flicker.. you have to remove vertical scroll as well..

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups