?
Solved

Scrolling down a TRichEdit

Posted on 1998-10-21
15
Medium Priority
?
359 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
[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
  • 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
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 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 300 total points
ID: 1343695
10x
0
 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
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…
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

764 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