如何真正实现窗口的透明(100分)

  • 主题发起人 主题发起人 tangyi_001
  • 开始时间 开始时间
T

tangyi_001

Unregistered / Unconfirmed
GUEST, unregistred user!
窗口实现透明后,在拖动窗口时原窗口位置的背景画面被拷贝到窗口新位置的背景上。如何解决这一问题。
 
应该不会如此
你说的有点不太清楚,是用的控件,还是自己写的代码?
 
不如不透明,先复制背景图像,保存一下,
在画到窗体上.
 
把屏幕先抓下来,再显示你的窗口。
当窗口移动时,不断地用抓下来的图形根据窗口的位置BitBlt到你的Form上。
但如果要求即时更新,比较困难。
记得eyes曾讨论过,在窗口移动过程中,Visible:=false;
再迫使屏幕背景重画,再抓重画的部分,Visible:=true;
再画Form.
 
可以用REGION。
 
说明:做了着色处理;用Alt+F4关闭;鼠标拖动。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure WMWinPosChanging(var Message: TWMWindowPosChanging);
message WM_WINDOWPOSCHANGING;
procedure WMEraseBkgnd(var Message: TWMEraseBkgnd);
message WM_ERASEBKGND;
procedure FormPaint(Sender: TObject);
procedure FormMouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
private
ScrBuff: TBitmap;
procedure GetScreen;
public
end;

var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
ScrBuff := TBitmap.Create;
BorderStyle := bsNone;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
ScrBuff.Free;
end;

procedure TForm1.GetScreen;
var
R: TRect;
begin
ScrBuff.Width := Screen.Width;
ScrBuff.Height := Screen.Height;
ScrBuff.Canvas.Brush.Style := bsSolid;
ScrBuff.Canvas.Brush.Color := $00FFFF80;
R := Rect(0, 0, Screen.Width, Screen.Height);
ScrBuff.Canvas.FillRect(R);
BitBlt(ScrBuff.Canvas.Handle, 0, 0, Screen.Width, Screen.Height, GetDC(0), 0, 0, srcAnd);
end;

procedure TForm1.FormShow(Sender: TObject);
begin
GetScreen;
end;

procedure TForm1.WMWinPosChanging(var Message: TWMWindowPosChanging);
begin
Invalidate;
end;

procedure TForm1.WMEraseBkgnd(var Message: TWMEraseBkgnd);
begin
{}
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
Canvas.Draw(- Left, - Top, ScrBuff);
end;

procedure TForm1.FormMouseDown(Sender: TObject;
Button: TMouseButton;
Shift: TShiftState;
X, Y: Integer);
begin
if Button = mbLeft then
begin
ReleaseCapture;
SendMessage(Handle, WM_SYSCOMMAND, SC_MOVE or 2, 0);
end;
end;

end.
 
croco 谢谢!给你加上100分
 
后退
顶部