Solved

RX Richedit(2) Component

Posted on 2002-05-03
6
517 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 34

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 34

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

726 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