RichEdit控件加载背景图片

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(防止窗口在刷新时清除背景)  
   

你可能感兴趣的:(RichEdit控件加载背景图片)