unit MoveMemo;
interface
Uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, ExtCtrls,RxRichEd;
type
TMoveMemo = class(TCustomControl)
private
fActive: Boolean;
fTimerTag: Boolean;
fstayTimer: TTimer;
fTimer: TTimer;
fStep : Integer;
fWait : Integer;
fstay : LongInt;
fBgColor: TColor;
Drawing: Boolean;
OffScreen: TBitMap;
fControl :TControl;
fOnComplete: TNotifyEvent;
procedure SetStep(V :Integer);
procedure SetActive(V: Boolean);
procedure SetTimer;
procedure ResetTimer;
procedure SetStay(V: LongInt);
procedure SetWait(V:Integer);
procedure OnTimer(Sender: TObject);
procedure OnStayTimer(Sender: TObject);
procedure SetBgColor(V:TColor);
procedure PaintFrame(ACanvas:TCanvas);
{ Private declarations }
public
Memo:TRxRichEdit;
constructor Create(AOwner:TComponent);override;
destructor Destroy;override;
{ Public declarations }
protected
procedure Paint ; override;
{ protected declarations }
published
property Stay : LongInt Read fStay Write Setstay default 3000;
property Step : Integer Read fStep Write SetStep default 50;
property Wait : Integer Read fWait Write SetWait default 5000;
property Active : Boolean Read fActive Write SetActive default False;
property BgColor: TColor Read fBgColor Write SetBgColor ;
property OnComplete : TNotifyEvent Read fOnComplete Write fOnComplete;
property Visible;
Property OnMouseDown;
property OnMouseUp;
property OnMouseMove;
{ published declarations }
end;
procedure Register ;
implementation
constructor TMoveMemo.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
fStep:=50;
fStay:=3000;
fWait:=5000;
fBgColor:=clBlack;
fStayTimer:=Nil;
fTimer:=Nil;
fActive:=False;
fTimerTag:=False;
Drawing:=False;
OffScreen:=TBitMap.Create;
Width:=200;
Height:=200;
//////////////////////////////
Memo:=TRxRichEdit.Create(Self);
Memo.Parent:=Self;
Memo.BorderStyle:=bsNone;
Memo.ScrollBars:=ssNone;
Memo.Color:=fBgColor;
Memo.Visible:=False;
Memo.Align:=alClient;
end;
destructor TMoveMemo.Destroy;
begin
ResetTimer;
Memo.Clear;
Memo.Free;
OffScreen.Assign(Nil);
OffScreen.Free;
inherited Destroy;
end;
procedure TMoveMemo.PaintFrame(ACanvas:TCanvas);
var
dc:HDC;
MemoCanvas:TCanvas;
MemoRect:TRect;
begin
OffScreen.Width:=ClientWidth;
OffScreen.Height:=ClientHeight;
OffScreen.PixelFormat:=pf4Bit;
MemoCanvas:=TCanvas.Create;
dc:=GetDc(Memo.Handle);
try
MemoCanvas.Handle:=dc;
MemoRect:=Rect(0,0,Memo.Width,Memo.Height);
OffScreen.Canvas.CopyRect(MemoRect,MemoCanvas,MemoRect);
finally
ReleaseDc(Memo.Handle,dc);
MemoCanvas.Free;
end;
ACanvas.Lock;
try
ACanvas.Draw(0,0,OffScreen);
finally
ACanvas.Unlock;
end;
end;
procedure TMoveMemo.Paint;
begin
if not Drawing then begin
Drawing := True;
try
PaintFrame(Canvas);
finally
Drawing := False;
end;
end;
end;
procedure TMoveMemo.SetBgColor(V:TColor);
begin
if fBgColor<>V then begin
fBgColor:=V;
Memo.Color:=fBgColor;
Invalidate;
end;
end;
procedure TMoveMemo.SetStay(V:LongInt);
begin
fStay:=V;
Invalidate;
end;
procedure TMoveMemo.SetWait(V:Integer);
begin
fWait:=V;
Invalidate;
end;
procedure TMoveMem
nTimer(Sender: TObject);
var
m:Integer;
begin
fTimer.Tag:=fTimer.Tag+1;
SendMessage(Memo.Handle,WM_VSCROLL,MakeLong(SB_THUMBTRACK,fTimer.Tag),0);
m:=Memo.Perform(EM_POSFROMCHAR,0,0 );
if m=fstayTimer.Tag then begin
fTimerTag:=True;
fTimer.Enabled:=False;
fstayTimer.Interval:=fWait;
fstayTimer.Enabled:=True;
end;
fstayTimer.Tag:=m;
Paint;
end;
procedure TMoveMem
nStayTimer(Sender:TObject);
begin
fstayTimer.Enabled:=False;
if fTimerTag then begin
Memo.Clear;
if (Assigned(OnComplete)) then fOnComplete(Self);
end else begin
fTimer.Enabled:=True;
fTimer.Tag:=0;
end;
end;
procedure TMoveMemo.SetTimer;
begin
if (csDesigning in ComponentState) then Exit;
fTimer:=TTimer.Create(Self);
fTimer.Interval:=fStep;
fTimer.Enabled:=False;
fTimer.Tag:=0;
fTimer.OnTimer:=OnTimer;
fstayTimer:=TTimer.Create(Self);
fstayTimer.Interval:=fStay;
fstayTimer.OnTimer:=OnStayTimer;
fstayTimer.Enabled:=True;
fstayTimer.Tag:=0;
fTimerTag:=False;
end;
procedure TMoveMemo.ReSetTimer;
begin
if (Assigned(fstayTimer)) then begin
fstayTimer.Enabled:=False;
fStayTimer:=Nil;
end;
if (Assigned(fTimer)) then begin
fTimer.Enabled:=False;
fTimer:=Nil;
end;
Invalidate;
end;
procedure TMoveMemo.SetActive(V: Boolean);
begin
if fActive<>V then fActive :=V;
if fActive then begin
SetTimer;
end else begin
ResetTimer;
end;
Invalidate;
end;
procedure TMoveMemo.SetStep(V:Integer);
begin
fStep:=V;
Invalidate;
end;
procedure Register ;
begin
RegisterComponents('ActiveX', [TMoveMemo]) ;
end ;
end.