Okay so I figure it out.
My solution was to read the scrollbar position and calculate the line number from it. Then calculate the delta number of lines to scroll from the current line position.
I captured the WM_MOUSEWHEEL
and WM_VSCROLL
and translated them into EM_LINESCROLL
messages instead.
// Translate Mouswheel
case WM_MOUSEWHEEL:
Message.Msg = EM_LINESCROLL;
Message.LParam = (long)Message.WParamHi == 120 ? -3 : 3;
Message.WParam = 0;
PrevWndProc(Message);
break;
// Handle thumbscroll
case WM_VSCROLL: {
if (Message.WParamLo == SB_THUMBTRACK || Message.WParamLo == SB_THUMBPOSITION) {
SCROLLINFO scrInfo = { sizeof(SCROLLINFO), SIF_ALL };
int ratio,delta;
// Get scrollbar position
GetScrollInfo(Script_Edit->Handle,SB_VERT,&scrInfo);
// Calculate line number
ratio = (scrInfo.nMax/Script_Edit->Lines->Count);
delta = (Message.WParamHi/ratio)-GetlineNumber();
// Don't update if delta is 0
if (delta == 0)
break;
// Change to EM_LINESCROLL message
Message.Msg = EM_LINESCROLL;
Message.WParam = 0;
Message.LParam = delta;
}
PrevWndProc(Message);
} break;
PrevWndProc()
is the original WindowProc()
function and GetLineNumber()
returns the top line index of the RichEdit control (EM_GETFIRSTVISIBLELINE
).
I hope this is helpful if someone else has the same problem.