如何创建子分层 alpha 透明窗口?
我正在尝试创建透明的子窗口。
procedure TForm1.BtnGoClick(Sender: TObject);
var
bmp:TBitmap;
BitmapPos: TPoint;
BitmapSize: TSIZE;
BlendFunction: _BLENDFUNCTION;
exStyle: Cardinal;
begin
bmp := TBitmap.Create;
bmp.LoadFromFile('my32bitbitmap.bmp');
exStyle := GetWindowLongA(Form2.Handle, GWL_EXSTYLE);
if (exStyle and WS_EX_LAYERED = 0) then
SetWindowLong(Form2.Handle, GWL_EXSTYLE, exStyle or WS_EX_LAYERED);
BitmapPos := Point(0, 0);
BitmapSize.cx := bmp.Width;
BitmapSize.cy := bmp.Height;
BlendFunction.BlendOp := AC_SRC_OVER;
BlendFunction.BlendFlags := 0;
BlendFunction.SourceConstantAlpha := 200;
BlendFunction.AlphaFormat := AC_SRC_ALPHA;
UpdateLayeredWindow(Form2.Handle, 0, nil, @BitmapSize, bmp.Canvas.Handle, @BitmapPos, 0, @BlendFunction, ULW_ALPHA);
Windows.SetParent(Form2.Handle, Form1.Handle);
bmp.Free;
end;
它几乎可以工作:Form2 成为 Form1 内漂亮的透明窗口。但看起来 Form2 不随 Form1 移动。当我移动 Form1 时,Form2-Window 也会移动,但在屏幕上我看到了它。当 Form1 移动时,我无法单击 Form2,单击会通过,所以我知道窗口已移动。
那么问题是如何使子透明窗口没有这些功能? (只是随父窗口移动的普通窗口)
I am trying to create transparent child window.
procedure TForm1.BtnGoClick(Sender: TObject);
var
bmp:TBitmap;
BitmapPos: TPoint;
BitmapSize: TSIZE;
BlendFunction: _BLENDFUNCTION;
exStyle: Cardinal;
begin
bmp := TBitmap.Create;
bmp.LoadFromFile('my32bitbitmap.bmp');
exStyle := GetWindowLongA(Form2.Handle, GWL_EXSTYLE);
if (exStyle and WS_EX_LAYERED = 0) then
SetWindowLong(Form2.Handle, GWL_EXSTYLE, exStyle or WS_EX_LAYERED);
BitmapPos := Point(0, 0);
BitmapSize.cx := bmp.Width;
BitmapSize.cy := bmp.Height;
BlendFunction.BlendOp := AC_SRC_OVER;
BlendFunction.BlendFlags := 0;
BlendFunction.SourceConstantAlpha := 200;
BlendFunction.AlphaFormat := AC_SRC_ALPHA;
UpdateLayeredWindow(Form2.Handle, 0, nil, @BitmapSize, bmp.Canvas.Handle, @BitmapPos, 0, @BlendFunction, ULW_ALPHA);
Windows.SetParent(Form2.Handle, Form1.Handle);
bmp.Free;
end;
It almost works: Form2 become nice transparent window inside Form1. But it looks like Form2 does not move with Form1. When i move Form1, Form2-Window moves, but on screen i see it when it was. When Form1 is moved i cant click on Form2, clicks goes through, so i know window was moved.
So question is how to make child transparent window without these features? (just normal window that moves with it's parrent)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每次移动或调整 Form2 大小后,您都需要调用 UpdateLayeredWindow。或者您可以将其替换为 TCustomTransparentControl 后代。
You need to call UpdateLayeredWindow after each move or resize of your Form2. Or you can replace it with TCustomTransparentControl descendant.