繁体   English   中英

如何创建子分层alpha透明窗口?

[英]How to create child layered alpha-transparent 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;

它几乎可以工作:Form2在Form1中变成了漂亮的透明窗口。 但看起来Form2不会随Form1移动。 当我移动Form1时,Form2-Window会移动,但是在屏幕上我会看到它。 移动Form1时,我无法点击Form2,点击进入,所以我知道窗口被移动了。

那么问题是如何制作没有这些功能的儿童透明窗口? (只是正常的窗口,随着它的移动而移动)

每次移动或调整Form2的大小后,您需要调用UpdateLayeredWindow。 或者您可以用TCustomTransparentControl后代替换它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM