Solved

RX Richedit(2) Component

Posted on 2002-05-03
6
499 Views
Last Modified: 2013-11-22
Hi there..

A small but annoying problem, in order to make the component scroll you have to give the richedit control focus and it will work perfectly, but very annoying if using it as a chat client so i eventually found some code that makes it scroll like Perform does on Richedit.



procedure ScrollToEnd(display: TRxRichEdit);
Var
  Oldfont: HFont;
  DC: THandle;
  Tm: TTextMetric;
  TheRect: TRect;
  index, lines: Integer;
begin
  DC:=GetDC(display.Handle);
  try
    OldFont:=SelectObject(DC,display.Font.Handle);
    try
      GetTextMetrics(DC,Tm);
      display.Perform(EM_GETRECT,0,longint(@TheRect));
      index:=(TheRect.Bottom-TheRect.Top)div(Tm.tmHeight+Tm.tmExternalLeading);
    finally
      SelectObject(DC,Oldfont);
    end;
  finally
    ReleaseDC(display.Handle,DC);
  end;
  lines:=SendMessage(display.Handle,EM_GETFIRSTVISIBLELINE,0,0);
    SendMessage(display.Handle,EM_LINESCROLL,0,(display.Lines.Count-lines-index+1));
  FaceUsed:=False;
//  SendMessage(Form1.Richedit1.Handle,SB_PAGEDOWN,ticker,0);
end;

The problem is this, if you use Bigger size fonts than 10 or include Graphics, the lines it scrolls is exactly i think 8 or 10 pixels per line, so once the graphics/bigger fonts are in place it no longer scrolls to the bottom and it gets left behind, anyone understand the code above enough to help me to fix this problem?

 Thank You...


Craig C.
0
Comment
Question by:craig_capel
  • 3
  • 2
6 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6990013
did you tried the em_scrollcaret-message after you've set the selstart-property to the of the content?
0
 
LVL 33

Expert Comment

by:Slick812
ID: 6990133
hello craig, you're trying to use line numbers to get to the bottom of the RichEdit text Rect, why not use the WM_VSCROLL message to just go to the bottom of the rect.

procedure TForm1.sbut_BottomClick(Sender: TObject);
var
Wpar: WParam;
ERect: TRect;
begin
RichEdit1.Perform(EM_GETRECT,0,Integer(@ERect));
WPar := 0;
WPar := MAKELONG(SB_THUMBPOSITION, ERect.Bottom);
RichEdit1.Perform(WM_VSCROLL,WPar,0);
end;

hope this works with the TRxRichEdit, let me know.
0
 
LVL 2

Author Comment

by:craig_capel
ID: 6996260
Slik, Well i thought i actually deleted this thread just after making it... about 10 - 15 mins later i tried this...


procedure ScrollToEnd(display: TRxRichEdit);
Var
  Oldfont: HFont;
  DC: THandle;
  Tm: TTextMetric;
  TheRect: TRect;
  index, lines: Integer;
  Wpar: WParam;
  ERect: TRect;
begin
  DC:=GetDC(display.Handle);
  try
    OldFont:=SelectObject(DC,display.Font.Handle);
    try
      GetTextMetrics(DC,Tm);
      display.Perform(EM_GETRECT,0,longint(@TheRect));
      index:=(tm.tmInternalLeading);
    finally
      SelectObject(DC,Oldfont);
    end;
  finally
    ReleaseDC(display.Handle,DC);
  end;
  lines:=SendMessage(display.Handle,EM_GETFIRSTVISIBLELINE,0,0);
    SendMessage(display.Handle,EM_LINESCROLL,0,(index-1));
 FaceUsed:=False;
{ Display.Perform(EM_GETRECT,0,Integer(@ERect));
 WPar := 0;
 WPar := MAKELONG(SB_THUMBPOSITION, ERect.Bottom);
 Display.Perform(WM_VSCROLL,WPar,0);}
end;

IT sometimes jumps up and leaves a few white spaces at the bottom but it fills in the gap as the text comes in, but it's ok...

So since the thread did not Delete, i tried your code, it works find until the font gets > 16 that is Font.Size:=17,18 then it stops scrolling enough to get to the bottom. but it works perfectly if the font stayed constant....
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 33

Accepted Solution

by:
Slick812 earned 100 total points
ID: 6999010
I had used that code a few times before, and it worked, but the RichEdits I used it in used only had a font smaller than 14. Turns out, I was thinking the scroll bar used the same measurement for it's position as the size of the RichEdit Rect, but it uses it's own measurement for the Max, incorperating the Page size (thumb button length) of the scroll bar, something like (MaxScrollPos = MaxRangeValue - (PageSize - 1)). So I should have used GetScrollInfo( ) instead of EM_GETRECT.


procedure TForm1.sbut_REditBottomClick(Sender: TObject);
var
theWparam: Integer;
ScrollInfo1: TScrollInfo;
begin
ScrollInfo1.cbSize := SizeOf(TScrollInfo);
ScrollInfo1.fMask := SIF_RANGE;
GetScrollInfo(RichEdit1.Handle,SB_VERT, ScrollInfo1);
theWparam := MAKELONG(SB_THUMBPOSITION, ScrollInfo1.nMax);
RichEdit1.Perform(WM_VSCROLL,theWparam,0);
end;

Glad you noticed this, so I could get it more better
0
 
LVL 2

Author Comment

by:craig_capel
ID: 7002328
Wow - thank you :) - yes it did do the trick :)
0
 
LVL 2

Author Comment

by:craig_capel
ID: 7002897
Just as a Side note - I tried that code and it works PERFECTLY using Riched20.dll however Richedit2 in Windows 98 is different in that when it attempts to do the scroll, the whole screen goes white - so what i did as a temp solution (as i hope the majority of users will be using XP/ME/2K) is copy the Richedit2.dll from NT to the same directory as the program which works...

But that's there for you to follow up - if it's something simple any suggestions on how to fix it?, if not don't worry as it works in NT and that' s the main thing..

Thanks once again....


- Craig C.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now