?
Solved

RX Richedit(2) Component

Posted on 2002-05-03
6
Medium Priority
?
522 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 34

Accepted Solution

by:
Slick812 earned 400 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month10 days, 18 hours left to enroll

770 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