delphi - RichEdit and WM_VSCROLL message -
when number of lines not large no problem wm_vscroll message. when richedit has large number of lines (in case ~130k lines average 150 chars) not works. richedit1.perform(wm_vscroll, makewparam(sb_thumbposition, n), 0); scroll top (n > 5) or more should (n <= 5). can vertical scroll in other way ?
p.s. testing can used this code written sertac akyuz.
i can't think of way adapt code linked in question able work rich edit version 2.0 reason mentioned in comment question. luckily might not necessary..
for windows xp sp1 , later rich edit version 3.0 included os. see 'about rich edit controls' on msdn. don't have use version 3.0, class names of version 2.0 , 3.0 same. if version 3.0 'riched20.dll' deployed on system, vcl gets use it.
interestingly there no problem wm_vscroll. message still use word sized scroll position, rich edit control adapts itself: scroll range of @ 65535.
about problem em_posfromchar, version 3.0 rich edit control, if pass pointer pointl in wparam, control detects , instead of returning coordinates, fills in parameter.
so, here sample having modified version of same code (please add error/special case handling appropriate) (works wordwrap set false):
const line = 'the scrollinfo structure contains scroll bar parameters...'#13#10; procedure tform1.formcreate(sender: tobject); var i: integer; s: string; begin s := ''; := 1 130000 s := s + inttostr(i) + ' - ' + line; sendmessage(richedit1.handle, wm_settext, 0, lparam(pchar(s))); end; procedure vertcenterline(richedit: trichedit; linenum: integer); var lineindex, maxlineindex: lresult; linepos, maxpos: tpoint; scrollinfo: tscrollinfo; scrollpos: extended; begin sendmessage(richedit.handle, em_setsel, 0, 0); sendmessage(richedit.handle, winapi.messages.em_scrollcaret, 0, 0); richedit.setfocus; lineindex := sendmessage(richedit.handle, em_lineindex, linenum, 0); maxlineindex := sendmessage(richedit.handle, em_lineindex, richedit.lines.count, 0); // account possible line feed @ end if maxlineindex = -1 maxlineindex := sendmessage(richedit.handle, em_lineindex, richedit.lines.count - 1, 0); sendmessage(richedit.handle, em_posfromchar, wparam(@linepos), lineindex); sendmessage(richedit.handle, em_posfromchar, wparam(@maxpos), maxlineindex); scrollinfo.cbsize := sizeof(scrollinfo); scrollinfo.fmask := sif_range; getscrollinfo(richedit.handle, sb_vert, scrollinfo); scrollpos := (linepos.y - richedit.clientheight / 2) / maxpos.y; scrollpos := scrollpos * (scrollinfo.nmax - scrollinfo.nmin); sendmessage(richedit.handle, wm_vscroll, makewparam(sb_thumbposition, round(scrollpos)), 0); end; procedure tform1.button1click(sender: tobject); begin vertcenterline(richedit1, 110000); end;
Comments
Post a Comment