[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

RX Richedit(2) Component

Posted on 2002-05-03
6
Medium Priority
?
543 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 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
Independent Software Vendors: 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 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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 Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

872 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