I'm trying to add line numbers to rows in a RichEdit Control. To do that, I have to know when the scrollbar scrolls up and down, so I can align the line numbers accordingly. I have captured all arrow keys and subclassed the WM_VSCROLL message (which is triggered when you click the scrollbar). Leaves one problem: the mousewheel.
By subclassing the WM_MOUSEWHEEL message I can refill the line numbers when the mouse is scrolled. The problem, however, is that the WM_MOUSEWHEEL message is sent before the actual scrolling has been done. So my code refills the line numbers to the unchanged situation, and only then the contents of the RichEdit box are being scrolled. So my line numbers are always 'one scroll behind'.
Is there any message I can intercept that tells me when the contents have actually been scrolled? When the mousewheel has finished scrolling? And if not, is there a way to turn of smooth scrolling in Rich Edit controls?
Have you tried intercepting the EN_UPDATE message? I assume it would be sent even when the mouse is moved over the control, but you could try using GETFIRSTVISIBLELINE and see if it changes, if it has, then you can redraw them from there.
Thanks for the tip; I looked at the MSDN page you provided, and there also seems to be a message EN_VSCROLL, which triggers when the page is scrolled by any means (be it mousewheel, arrows, scrollbar). That's exactly what I need here, but I can't get it to work. MSDN says you have to call EM_SETEVENTMASK in order to receive that message, but it doesn't seem to do anything. I also tried capturing EN_UPDATE, but got the same problem.
I included a small test program. You can see that WM_VSCROLL is being captured when you click the scrollbar, but EN_VSCROLL is never.