如何创建子分层的alpha透明窗口? [英] How to create child layered alpha-transparent window?

查看:127
本文介绍了如何创建子分层的alpha透明窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建透明的子窗口。

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;

几乎可以正常工作:Form2成为Form1内部漂亮的透明窗口。但是看起来Form2不会随Form1一起移动。当我移动Form1时,Form2-Window会移动,但是在屏幕上我看到的是它。当移动Form1时,我无法单击Form2,因此单击会通过,因此我知道窗口已移动。

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)

推荐答案

每次Form2移动或调整大小后,您都需要调用UpdateLayeredWindow。或者,您也可以将其替换为TCustomTransparentControl后代。

You need to call UpdateLayeredWindow after each move or resize of your Form2. Or you can replace it with TCustomTransparentControl descendant.

这篇关于如何创建子分层的alpha透明窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆