我继承TCustomRichEdit,编写一个透明的RichEdit控件!(50分)

  • 主题发起人 主题发起人 pandy
  • 开始时间 开始时间
P

pandy

Unregistered / Unconfirmed
GUEST, unregistred user!
大家能不能帮我看看到底是什么问题?
我的RichEdit是要放在图片之上的!
我查了一些资料,说是RichEdit2.0支持WS_EX_TRANSPARENT
但是我这里怎么好像不起作用?我的系统是WIN2K!
大虾们,谢谢帮忙咯!
unit TranspCustomRichEdit;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls;
const
TWM_TransInvalidate=WM_USER+1;
type
TTranspCustomRichEdit = class(TCustomRichEdit)

private

FTransparent:Boolean;
procedure TransInvalidate(var Message:TMessage); message TWM_TransInvalidate;
procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
procedure CNCTLCOLOREDIT(var Message:TWMCTLCOLOREDIT);message CN_CTLCOLOREDIT;
protected
procedure CreateWnd; override;
procedure CreateParams(var Params: TCreateParams); override;
public
procedure SetTransparent(value:Boolean);
constructor Create(AOwner:TComponent);override;
procedure Invalidate; override;
published
property Align;
property Alignment;
property Anchors;
property BiDiMode;
property BorderStyle;
property BorderWidth;
property Color;
property Ctl3D;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property HideSelection;
property HideScrollBars;
property ImeMode;
property ImeName;
property Constraints;
property Lines;
property MaxLength;
property ParentBiDiMode;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PlainText;
property PopupMenu;
property ReadOnly;
property ScrollBars;
property ShowHint;
property TabOrder;
property TabStop default True;
property Visible;
property WantTabs;
property WantReturns;
property WordWrap;
property OnChange;
property OnContextPopup;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnMouseWheel;
property OnMouseWheelDown;
property OnMouseWheelUp;
property OnProtectChange;
property OnResizeRequest;
property OnSaveClipboard;
property OnSelectionChange;
property OnStartDock;
property OnStartDrag;
property TransParent:Boolean read FTransparent write SetTransparent default True ;
end;

procedure Register;

implementation

constructor TTranspCustomRichEdit.Create(AOwner:TComponent);
begin
inherited create(AOwner);
ftransparent:=true;
end;

procedure TTranspCustomRichEdit.CreateWnd;
begin
inherited CreateWnd;
if fTransparent then
begin
SetWindowLong(Parent.Handle, GWL_STYLE,
GetWindowLong(Parent.Handle, GWL_STYLE) and not WS_CLIPCHILDREN);
end;
end;


procedure TTranspCustomRichEdit.SetTransparent(value:Boolean);
begin
FTransparent:=value;
end;

procedure TTranspCustomRichEdit.TransInvalidate(var Message:TMessage);
var r:TRect;
begin
Message.Result:=1;
if (Parent<>nil) and FTransparent then
begin
r:=ClientRect;
r.TopLeft:=Parent.ScreenToClient(ClientToScreen(r.TopLeft));
r.BottomRight:=Parent.ScreenToClient(ClientToScreen(r.BottomRight));
RedrawWindow(Handle,nil,0,RDW_FRAME+RDW_INVALIDATE);
end;

end;


procedure TTranspCustomRichEdit.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
if (CsDesigning in ComponentState) then exit;
with Params do
begin
ExStyle:=ExStyle or WS_EX_TRANSPARENT;
end;

end;


procedure TTranspCustomRichEdit.WMEraseBkgnd(var Message: TWMEraseBkgnd);
begin
if FTransparent and not (csDesigning in ComponentState) then
PostMessage(Handle,TWM_TransInvalidate,0,0)
else inherited;
Message.Result:=1;
end;

procedure TTranspCustomRichEdit.Invalidate;
begin
if FTransparent then
SendMessage(Handle,TWM_TransInvalidate,0,0)
else
inherited;
end;

procedure TTranspCustomRichEdit.CNCTLCOLOREDIT(var Message:TWMCTLCOLOREDIT);
begin
message.Result:=1;
if FTransparent then
with Message do
begin
SetBkMode(ChildDC,Windows.TRANSPARENT);
Result:=GetStockObject(HOLLOW_BRUSH)
end
else inherited;
end;



procedure Register;
begin
RegisterComponents('Samples', [TTranspCustomRichEdit]);
end;

end.
 
网上这末多透明edit的控件,download一个不就可以了,何必自己写一个
 
兄弟:

我没有找到RichEdit的透明控件呀!普通的Edit到是有不少透明控件!

我要控制字体和字体的颜色的!


 
接受答案了.
 
后退
顶部