Solved

Scrolling down a TRichEdit

Posted on 1998-10-21
15
352 Views
Last Modified: 2010-04-06
I have this terminal program for telnet that reads in text from the net and displays it in a TRichEdit.  I want the incoming text to be visible when it comes in.  Right now, I have it set up to the SelStart to the end of the text and then I set the focus to the TRichEdit.  This works fine, except that on occasion, if I'm working in another application, focus will jump to my terminal program.  Is there a way do this without setting the focus to the RichEdit at all?
0
Comment
Question by:Gms300
  • 7
  • 6
  • 2
15 Comments
 
LVL 10

Expert Comment

by:viktornet
ID: 1343689
SendMessage(RichEdit1.Handle, WM_VSCROLL, 10, 0); //Scroll down by 10
SendMessage(RichEdit1.Handle, WM_VSCROLL, -10, 0); //Scroll up by 10

Regards,
Viktor Ivanov
0
 

Author Comment

by:Gms300
ID: 1343690
I couldn't get that to work.  I don't know if I was doing something wrong or what.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1343691
Hi Gms300,

this should work :

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    RichEdit1: TRichEdit;
    bFill: TButton;
    bUp: TButton;
    bDown: TButton;
    Edit1: TEdit;
    procedure bFillClick(Sender: TObject);
    procedure bUpClick(Sender: TObject);
    procedure bDownClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.bFillClick(Sender: TObject);
var i: integer;
begin
 for i:= 1 to 20 do begin
  richedit1.Lines.Add('This is line : '+intToStr(i));
 end;
end;

procedure TForm1.bUpClick(Sender: TObject);
var i : integer;
begin
for i:= 1 to StrToInt(Edit1.text) do
 SendMessage(RichEdit1.Handle, WM_VSCROLL, SB_LINEUP, 0);
end;

procedure TForm1.bDownClick(Sender: TObject);
var i : integer;
begin
for i:= 1 to StrToInt(Edit1.text) do
 sendmessage(richedit1.Handle, WM_VSCroll, SB_LINEDOWN,0);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 Edit1.Text := '1';
end;

end.

Regards, Zif.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1343692
The problem is I guess that you didn't have more that 10 lines in your RichEdit component .... Simply try replacing the 10 with a 1 or 2 and try again.. I've been using that a few times and it always works....

btw- Zif, No offence but I think that your code is no different than mine...As a matter of fact if he uses your code it will take a while to scroll down 10 units... If he uses the way I told 'im to then the RichEdit will scroll right at the current plus ten, and yours it will just jump rfom line to line until it gets to the number in edit.text

Cheers,
Viktor
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1343693
Viktornet,

 I must say that the answer you gave is partially correct, so by all means, you may have the points, but let me say this :

SendMessage(richedit1.handle, VM_VScroll,-10, 0) will not work, even if you would 've added more then 10 lines. Normally if you browse further then you have, it should stop at the last item.

SendMessage(richedit1.handle,VM_VScroll,-1,0) doesn't work either.

I tried these myself several times, even now again, because you gave them as an answer. I just can't get this scroll down to work.

What does work for scrolling down is this (this I found by trial and error):

SendMessage(richedit1.handle,VM_VScroll,0,1) does work for browsing down.

But, it is much better, to use windows constants itself!

So to scroll up, use parameter SB_LINEUP, do scroll down us SB_LINEDOWN.

To scroll to a given amount, use SB_THUMBPOSITION. (Scrolls to the absolute position. The current position is specified by the nPos parameter.)      

I agree about calling these 10 times isn't a great way of programming, but do you have a better one? (also for scrolling down?). Yes, perhaps, SB_THUMBPOSITION is better for moving fast. ps. there are other constants available too.

Regards, Zif.

0
 

Author Comment

by:Gms300
ID: 1343694
Thanks for the help.  viktornet, you were right.  Sorry about rejecting you answer the first time.  The points are yours, just answer again, please.  :)
0
 
LVL 10

Accepted Solution

by:
viktornet earned 100 total points
ID: 1343695
10x
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 8

Expert Comment

by:ZifNab
ID: 1343696
Strange, does this rely works on your pc's?

SendMessage(richedit1.handle, VM_VScroll,-10, 0)

I can't get this at work.

Which versions of Delphi are you using and which OS.

Zif.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1343697
D4 / Win95

Vik
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1343698
and you gms300. I've D3 and Win98 on this PC.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1343699
Win98 is f****** buggy, so is Delphi4...

Vik
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1343700
well, I don't understand that it actually works.

Look at this :

WM_VSCROLL

nScrollCode = (int) LOWORD(wParam); // scroll bar value
nPos = (short int) HIWORD(wParam);  // scroll box position
hwndScrollBar = (HWND) lParam;      // handle of scroll bar

then

Parameters

nScrollCode

Value of the low-order word of wParam. Specifies a scroll bar value that indicates the user's scrolling request. This parameter can be one of the following values:

Value      Meaning
SB_BOTTOM      Scrolls to the lower right.
SB_ENDSCROLL      Ends scroll.
SB_LINEDOWN      Scrolls one line down.
SB_LINEUP      Scrolls one line up.
SB_PAGEDOWN      Scrolls one page down.
SB_PAGEUP      Scrolls one page up.
SB_THUMBPOSITION      Scrolls to the absolute position. The current position is specified by the nPos parameter.
SB_THUMBTRACK      Drags scroll box to the specified position. The current position is specified by the nPos parameter.
SB_TOP      Scrolls to the upper left.
nPos

Value of the high-order word of wParam. Specifies the current position of the scroll box if the nScrollCode parameter is SB_THUMBPOSITION or SB_THUMBTRACK; otherwise, nPos is not used.

hwndScrollBar

Value of lParam. Identifies the control if WM_VSCROLL is sent by a scroll bar control. If WM_VSCROLL is sent by a window's standard scroll bar, hwndScrollBar is not used.

Return Value

If an application processes this message, it should return zero.

so nbScrollbar can't be higher or equal to 10

(SendMessage(richedit1.handle, VM_VScroll,-10, 0))

thus I don't understand above code works.

What can work, like scrolling a X position up or down, should be :


SendMessage(Handle,EM_LINESCROLL,X,Y);

for scrolling down :

SendMessage(richedit1.Handle,EM_LINESCROLL,0,10);

Sorry for all this, but I just wants to know why your code works too.



0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1343701
the above should be nbScrollcode instead of nbScrollBar
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1343702
f*** nScrollCode
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1343703
I have no idea why it works :-|
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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

13 Experts available now in Live!

Get 1:1 Help Now