您的位置:首页 > 其它

RichEdit控件加载背景图片

2009-10-06 16:28 302 查看
unit   Unit1;

interface

uses
Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,
Dialogs,   StdCtrls,   Buttons,   ComCtrls,   ExtCtrls,   jpeg;

type
TForm1   =   class(TForm)
Image1: TImage;
RichEdit1: TRichEdit;

procedure   ClassWndProc(var Msg: TMessage);
procedure FormCreate(Sender: TObject);
private
{   Private   declarations   }
public
{   Public   declarations   }
end;

var
Form1: TForm1;
wproc: pointer;
oldproc: TWndMethod;
bb: hBrush;

implementation

{$R   *.dfm}

procedure Tform1.ClassWndProc(var Msg: TMessage);
begin
if msg.Msg = WM_ERASEBKGND then
msg.result:=1
else if (msg.Msg=CN_CTLCOLORMSGBOX) or (msg.Msg=CN_CTLCOLORSTATIC) then
begin
bb:=null;
msg.result := bb
end
else
oldproc(msg)
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
oldproc:=RichEdit1.WindowProc;
RichEdit1.WindowProc := form1.ClassWndProc;
SetWindowLong(RichEdit1.Handle,   GWL_EXSTYLE,   GetWindowLong(RichEdit1.Handle,GWL_EXSTYLE)   or   WS_EX_TRANSPARENT);
end;

end.


1. 使RichEdit的窗口透明. SetWindowLong(RichEdit.Handle, GWL_EXSTYLE, GetWindowLong(RichEdit.Handle,GWL_EXSTYLE) or WS_EX_TRANSPARENT);

2. 截获RichEdit的Wndproc, 处理以下消息:
CN_CTLCOLORMSGBOX..CN_CTLCOLORSTATIC: 返回一个NullBrush的handle
(防止编辑状态时清除背景).
WM_ERASEBKGND: 什么都不做就返回1(防止窗口在刷新时清除背景)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: