把以下文本存为html文件。这是一个网页,自己看吧。
<html><TITLE>建立一个透明 Edit 控件</TITLE><table border=0 align=center width='600' class='tblStandard' bgcolor='#666666' cellspacing='1' cellpadding='2'><tr><th bgcolor='#cccc99' colspan='2'>Building a Transparent Edit Control</th></tr><tr><td bgcolor='#ffffff'><b>Undertitle:</b></td><td bgcolor='#ffffff'>Transparency made easy</td></tr><tr><td bgcolor='#ffffff'></td></tr><tr><td bgcolor='#ffffff'><b>Category:</b></td><td bgcolor='#ffffff'>VCL-General</td></tr><tr><td bgcolor='#ffffff'><b>Uploader:</b></td><td bgcolor='#ffffff'>Romeo Lefter</td></tr><tr><td bgcolor='#cccccc' colspan='2'>&nbsp;</td></tr><tr><td bgcolor='#ffffff' valign='top'><b>Question:</b></td><td bgcolor='#ffffff'>如何 build a transparent edit control?</td></tr><tr><td bgcolor='#ffffff' valign='top'><b>Answer:</b></td><td bgcolor='#ffffff'><span style='margin-left:20px;margin-right:20px;'>&nbsp;&nbsp;Building a transparent edit control can be the cool face of your application. Why? Because your entry forms can look like "paper forms". Adding this cool features for your application can be very easy, as you will see bellow.<br><br>&nbsp;&nbsp;First of all I want to specify that is not my original code. I have found a transparent edit, listbox, checkbox and memo controls in FusedControls, but the main goal of this library is the flicker. Is impossible for anyone to distribute a applicatin with this controls because the flicker is in supportable.<br><br>&nbsp;&nbsp;An now, go to work. All we have to do is to overrwide the CreateParams and some common events. In order to resolve the flicker I have decide to let our edit control transparent only when the focus is not on it. So, I have override the DoEnter and DoExit. The entire code is bellow. Just copy, paste in a blank unit and install the component.<br><br><br>unit RbsWiredEdit;<br><br>interface<br><br>uses<br>&nbsp;&nbsp;Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp;&nbsp;StdCtrls;<br><br>const<br>&nbsp;&nbsp;TWM_RbsInvalidate=WM_USER+1;<br><br>type<br>&nbsp;&nbsp;TRbsWiredEdit = class(TEdit)<br>&nbsp;&nbsp;private<br>&nbsp;&nbsp;&nbsp;&nbsp;{ Private declarations }<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure RbsInvalidate(var Message:TMessage); message<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TWM_RbsInvalidate;<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure CNCTLCOLOREDIT(var Message:TWMCTLCOLOREDIT); message<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CN_CTLCOLOREDIT;<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure WMMove(var Message: TMessage); message WM_MOVE;<br><br>&nbsp;&nbsp;protected<br>&nbsp;&nbsp;&nbsp;&nbsp;{ Protected declarations }<br>&nbsp;&nbsp;&nbsp;&nbsp;FTransparent: boolean;<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure CreateWnd; override;<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure CreateParams(var Params: TCreateParams); override;<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure DoExit; override;<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure DoEnter; override;<br>&nbsp;&nbsp;public<br>&nbsp;&nbsp;&nbsp;&nbsp;{ Public declarations }<br>&nbsp;&nbsp;&nbsp;&nbsp;constructor Create(AOwner: TComponent); override;<br>&nbsp;&nbsp;&nbsp;&nbsp;procedure Invalidate; override;<br><br>&nbsp;&nbsp;published<br>&nbsp;&nbsp;&nbsp;&nbsp;{ Published declarations }<br>&nbsp;&nbsp;end;<br><br>procedure Register;<br><br>implementation<br><br>constructor TRbsWiredEdit.Create(AOwner:TComponent);<br>begin<br>inherited create(AOwner);<br>&nbsp;&nbsp; ftransparent:=true;<br>end;<br><br>procedure TRbsWiredEdit.CreateWnd;<br>begin<br>inherited CreateWnd;<br>&nbsp;&nbsp; if fTransparent then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SetWindowLong(Parent.Handle, GWL_STYLE,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GetWindowLong(Parent.Handle, GWL_STYLE) and not WS_CLIPCHILDREN);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end;<br>end;<br><br>procedure TRbsWiredEdit.RbsInvalidate(var Message:TMessage);<br>var r:TRect;<br>begin<br>&nbsp;&nbsp;if (Parent&lt;&gt;nil) and FTransparent then<br>&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;r:=ClientRect;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;r.TopLeft:=Parent.ScreenToClient(ClientToScreen(r.TopLeft));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;r.BottomRight:=Parent.ScreenToClient(ClientToScreen(r.BottomRight));<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RedrawWindow(Handle,nil,0,RDW_FRAME+RDW_INVALIDATE);<br>&nbsp;&nbsp;&nbsp;&nbsp;end;<br>end;<br><br>procedure TRbsWiredEdit.CNCTLCOLOREDIT(var Message:TWMCTLCOLOREDIT);<br>begin<br>&nbsp;&nbsp;if FTransparent then<br>&nbsp;&nbsp; with Message do<br>&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SetBkMode(ChildDC,Windows.TRANSPARENT);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Result:=GetStockObject(HOLLOW_BRUSH)<br>&nbsp;&nbsp;&nbsp;&nbsp;end<br>&nbsp;&nbsp; else inherited;<br>end;<br><br><br><br>procedure TRbsWiredEdit.WMEraseBkgnd(var Message:TWMERASEBKGND);<br>begin<br>&nbsp;&nbsp;if FTransparent and not (csDesigning in ComponentState) then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PostMessage(Handle,TWM_RbsInvalidate,0,0)<br>&nbsp;&nbsp;else inherited;<br>end;<br><br>procedure TRbsWiredEdit.WMMove(var message:TMessage);<br>begin<br>inherited;<br> if FTransparent then SendMessage(Handle,TWM_RbsInvalidate,0,0)<br>&nbsp;&nbsp;else Invalidate;<br>end;<br><br>procedure TRbsWiredEdit.CreateParams(var Params:TCreateParams);<br>begin<br>inherited CreateParams(Params);<br>if (CsDesigning in ComponentState) then exit;<br>&nbsp;&nbsp;&nbsp;&nbsp;with Params do<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;begin<br>&nbsp;&nbsp; ExStyle:=ExStyle or WS_EX_TRANSPARENT;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end;<br>end;<br><br>procedure TRbsWiredEdit.DoExit;<br>begin<br> inherited;<br>&nbsp;&nbsp; FTransparent:=true;<br>&nbsp;&nbsp; SetCursor(0);<br>&nbsp;&nbsp; RecreateWnd;<br>end;<br><br>procedure TRbsWiredEdit.DoEnter;<br>var exstyle,stdstyle:longint;<br>begin<br>inherited;<br>Ftransparent:=false;<br>StdStyle:= Windows.GetWindowLong(handle, GWL_EXSTYLE);<br>exStyle:= StdStyle and not WS_EX_TRANSPARENT;<br>Windows.SetWindowLong(handle, GWL_EXSTYLE, exStyle);<br>invalidate;<br>end;<br><br>procedure TRbsWiredEdit.Invalidate;<br>begin<br>if FTransparent then SendMessage(Handle,TWM_RbsInvalidate,0,0)<br>&nbsp;&nbsp;else inherited;<br>end;<br><br>procedure Register;<br>begin<br>&nbsp;&nbsp;RegisterComponents('Rombest', [TRbsWiredEdit]);<br>end;</html>