关于透明容器,再一次提问!

huijunzi 2003-11-28 11:37:39
关于透明容器,再一次提问!这可能是一个老问题,提问之前我也仔细翻了一下以前的贴子,但是没有一个能够完全解决问题,我现在需要实现如下效果:
1.是一个容器,比如Panel
2.是透明的,是说容器本身是透明的,只能看到该容器下的控件,而不是包括窗体一起是透明的。
3.该透明的容器支持当其下面的对象发生变化时依然透明,并能看到最新的变化(如:将该容器放在一个视频窗口上,能够透过该容器看到视频的播放。)
...全文
155 4 打赏 收藏 举报
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
jiezhi 2003-11-29
http://expert.csdn.net/Expert/topic/2471/2471680.xml?temp=.8781244
  • 打赏
  • 举报
回复
saien 2003-11-28
关注...
  • 打赏
  • 举报
回复
huijunzi 2003-11-28
以上的TGlass根本不是容器啊
  • 打赏
  • 举报
回复
hongqi162 2003-11-28
Panel透明
unit Glass;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;

type
TGlassStyle = (
gsBlackness, gsDstInvert, gsMergeCopy, gsMergePaint, gsNotSrcCopy,
gsNotSrcErase, gsPatCopy, gsPatInvert, gsPatPaint, gsSrcAnd,
gsSrcCopy, gsSrcErase, gsSrcInvert, gsSrcPaint, gsWhiteness);

TGlass = class(TCustomControl)
private
FColor: TColor;
FStyle: TGlassStyle;
FOnPaint: TNotifyEvent;

procedure SetColor(Value: TColor);
procedure SetStyle(Value: TGlassStyle);
procedure CMCtl3DChanged(var Message: TMessage); message CM_CTL3DCHANGED;
procedure WMEraseBkgnd(var Message: TMessage); message WM_ERASEBKGND;
procedure WMWindowPosChanging(var Message: TWMWindowPosChanging); message WM_WINDOWPOSCHANGING;
protected
Buffer: TBitmap;

procedure CreateParams(var Params: TCreateParams); override;
procedure Paint; override;
procedure Resize; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property Canvas;
published
property Align;
property Anchors;
property AutoSize;
property BiDiMode;
property BorderWidth;
property Color: TColor read FColor write SetColor;
property Ctl3D;
property Enabled;
property Style: TGlassStyle read FStyle write SetStyle default gsSrcAnd;
property Visible;

property OnClick;
property OnDblClick;
property OnEnter;
property OnExit;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnPaint: TNotifyEvent read FOnPaint write FOnPaint;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Croco', [TGlass]);
end;

function GlassStyleToInt(gs: TGlassStyle): LongInt;
begin
case gs of
gsBlackness : Result := cmBlackness;
gsDstInvert : Result := cmDstInvert;
gsMergeCopy : Result := cmMergeCopy;
gsMergePaint : Result := cmMergePaint;
gsNotSrcCopy : Result := cmNotSrcCopy;
gsNotSrcErase: Result := cmNotSrcErase;
gsPatCopy : Result := cmPatCopy;
gsPatInvert : Result := cmPatInvert;
gsPatPaint : Result := cmPatPaint;
gsSrcAnd : Result := cmSrcAnd;
gsSrcCopy : Result := cmSrcCopy;
gsSrcErase : Result := cmSrcErase;
gsSrcInvert : Result := cmSrcInvert;
gsSrcPaint : Result := cmSrcPaint;
gsWhiteness : Result := cmWhiteness;
else Assert(True, 'Error parameter in function GlassStyleToInt');
end;
end;

constructor TGlass.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Buffer := TBitmap.Create;

ControlStyle := [csAcceptsControls, csCaptureMouse, csClickEvents,
csDoubleClicks, csReplicatable];
Width := 100;
Height := 100;
FStyle := gsSrcAnd;
ParentCtl3d := False;
Ctl3D := False;
ParentColor := False;
FColor := clWhite;
end;

destructor TGlass.Destroy;
begin
Buffer.Free;
inherited Destroy;
end;

procedure TGlass.Paint;
var
R: TRect;
rop: LongInt;
begin
R := Rect(0, 0, Width, Height);
Buffer.Width := Width;
Buffer.Height := Height;
Buffer.Canvas.Brush.Style := bsSolid;
Buffer.Canvas.Brush.Color := FColor;
Buffer.Canvas.FillRect(Rect(0, 0, Width, Height));
rop := GlassStyleToInt(FStyle);
StretchBlt(Buffer.Canvas.Handle, 0, 0, Width, Height,
Canvas.Handle, 0, 0, Width, Height, rop);
if Ctl3D then DrawEdge(Buffer.Canvas.Handle, R, BDR_RAISEDINNER, BF_RECT);
Buffer.Canvas.Pen.Mode := pmCopy;
Buffer.Canvas.Pen.Style := psSolid;
Canvas.Draw(0, 0, Buffer);
if Assigned(FOnPaint) then FOnPaint(Self);
end;


procedure TGlass.SetColor(Value: TColor);
begin
if Value <> FColor then
begin
FColor := Value;
RecreateWnd;
end;
end;

procedure TGlass.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);

Params.ExStyle := Params.ExStyle + WS_EX_TRANSPARENT;
end;

procedure TGlass.WMWindowPosChanging(var Message: TWMWindowPosChanging);
begin
Invalidate;

inherited;
end;

procedure TGlass.WMEraseBkgnd(var Message: TMessage);
begin
Message.Result := 0;
end;

procedure TGlass.Resize;
begin
Invalidate;

inherited;
end;

procedure TGlass.CMCtl3DChanged(var Message: TMessage);
begin
inherited;

RecreateWnd;
end;

procedure TGlass.SetStyle(Value: TGlassStyle);
begin
if Value <> FStyle then
begin
FStyle := Value;
RecreateWnd;
end;
end;

end.
  • 打赏
  • 举报
回复
相关推荐
发帖
Delphi
加入

5096

社区成员

Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
申请成为版主
帖子事件
创建了帖子
2003-11-28 11:37
社区公告
暂无公告