请高手帮帮忙,有关透明的Edit控件!(50分)

  • 主题发起人 主题发起人 cherrylin
  • 开始时间 开始时间
C

cherrylin

Unregistered / Unconfirmed
GUEST, unregistred user!
制作了一个透明的Edit控件,里面主要用了一些API函数来完成的,一些网站上都是用这样的方法,但是很奇怪,我在WIN98和WIN2000下都可以透明,但是在WIN XP下却不可以完全透明,有文字出现地方是不透明的!不知道这是为什么? 真纳闷啊?
不知哪位大哥能帮帮我,或者有别的更好的方法!真的非常感谢!

unit EditPro;

interface

uses
Windows, Messages, SysUtils, Classes, Controls, StdCtrls, Graphics,Dialogs;

const
TWM_Invalidate = WM_USER+1;

type
TEditPro = class(TEdit)
private
FAlignment: TAlignment; //水平对齐
FTransparent: Boolean; //透明
procedure SetAlignment(Value: TAlignment);
procedure TInvalidate(var Message: TMessage); message TWM_Invalidate;
procedure CNCTLCOLOREDIT(var Message: TWMCTLCOLOREDIT); message CN_CTLCOLOREDIT;
procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
procedure WMMove(var Message: TMessage); message WM_MOVE;
{ Private declarations }
protected
procedure CreateWnd; override;
procedure CreateParams(var Params: TCreateParams); override;
procedure DoExit; override;
procedure DoEnter; override;
{ Protected declarations }
public
constructor Create(AOwner: TComponent); override;
procedure Invalidate; override;
{ Public declarations }
published
property Alignment: TAlignment Read FAlignment Write SetAlignment Default taLeftJustify; //水平对齐属性
{ Published declarations }
end;

procedure Register;

implementation

constructor TEditPro.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
Width := 70;
Height := 25;
FTransparent := True;
end;

procedure TEditPro.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 TEditPro.SetAlignment(Value: TAlignment);
begin
if Value <> FAlignment then
begin
FAlignment := Value;
RecreateWnd;
end;
end;

procedure TEditPro.TInvalidate(var Message:TMessage);
var
r: TRect;
begin
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 TEditPro.CNCTLCOLOREDIT(var Message: TWMCTLCOLOREDIT);
begin
if FTransparent then
with Message do
begin
SetBkMode(ChildDC, Windows.TRANSPARENT);
Result := GetStockObject(HOLLOW_BRUSH)
end
else
inherited;
end;

procedure TEditPro.WMEraseBkgnd(var Message: TWMERASEBKGND);
begin
if FTransparent then
PostMessage(Handle, TWM_Invalidate, 0, 0)
else
inherited;
end;

procedure TEditPro.WMMove(var message: TMessage);
begin
inherited;
if FTransparent then
SendMessage(Handle, TWM_Invalidate, 0, 0)
else
Invalidate;
end;

procedure TEditPro.CreateParams(var Params: TCreateParams);
const
Alignments: array[TAlignment] of word = (DT_LEFT, DT_RIGHT, DT_CENTER);
begin
inherited CreateParams(Params);
with Params do
begin
Style := Style or Alignments[FAlignment];
ExStyle := ExStyle or WS_EX_TRANSPARENT;
end;
end;

procedure TEditPro.DoExit;
begin
inherited;
FTransparent := True;
SetCursor(0);
RecreateWnd;
end;

procedure TEditPro.DoEnter;
var
exstyle, stdstyle: LongInt;
begin
inherited;
FTransparent := False;
StdStyle:= Windows.GetWindowLong(Parent.handle, GWL_EXSTYLE);
exStyle:= StdStyle and not WS_EX_TRANSPARENT;
Windows.SetWindowLong(Parent.handle, GWL_EXSTYLE, exStyle);
invalidate;
end;

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

procedure Register;
begin
RegisterComponents('Standard', [TEditPro]);
end;

end.


 
请版主帮忙解决一下啊!
很急啊!
 
为什么没人帮忙呢?难道这没有人知道吗?
 

Similar threads

I
回复
0
查看
570
import
I
I
回复
0
查看
548
import
I
I
回复
0
查看
646
import
I
后退
顶部