Solved

RX Richedit(2) Component

Posted on 2002-05-03
6
515 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
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 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

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!

Question has a verified solution.

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

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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