首页 > 其他分享 >SetLayeredWindowAttributes - 设置窗口的透明

SetLayeredWindowAttributes - 设置窗口的透明

时间:2023-05-13 15:37:12浏览次数:36  
标签:FormStyle 透明 窗口 SetLayeredWindowAttributes TObject EXSTYLE GWL LWA

//声明:
SetLayeredWindowAttributes(
  Hwnd: THandle;   {窗口句柄}
  crKey: COLORREF; {透明色}
  bAlpha: Byte;    {Alpha 值}
  dwFlags: DWORD   {LWA_COLORKEY(=1)表示使用透明色; LWA_ALPHA(=2)表示使用 Alpha 值}
): Boolean;        {是否成功设置}

//举例(控制外部程序的透明度, 用计算器举了个例子):
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{设定计算器的 Alpha 透明}
procedure TForm1.Button1Click(Sender: TObject);
var
  h: HWND;
  FormStyle: Integer;
begin
  h := FindWindow('SciCalc', nil);
  FormStyle := GetWindowLong(h, GWL_EXSTYLE);
  SetWindowLong(h, GWL_EXSTYLE, FormStyle or WS_EX_LAYERED);
  SetLayeredWindowAttributes(h, 0, 128, LWA_ALPHA);
end;

{设定计算器中的白色透明}
procedure TForm1.Button2Click(Sender: TObject);
var
  h: HWND;
  FormStyle: Integer;
begin
  h := FindWindow('SciCalc', nil);
  FormStyle := GetWindowLong(h, GWL_EXSTYLE);
  SetWindowLong(h, GWL_EXSTYLE, FormStyle or WS_EX_LAYERED);
  SetLayeredWindowAttributes(h, clWhite, 255, LWA_COLORKEY);
end;

end.

标签:FormStyle,透明,窗口,SetLayeredWindowAttributes,TObject,EXSTYLE,GWL,LWA
From: https://www.cnblogs.com/lucken2000/p/17397451.html

相关文章

  • 根据窗口句柄获取所在程序路径
    本例效果图:代码文件:unitUnit1;interfaceuses Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms, Dialogs,StdCtrls;type TForm1=class(TForm)  Button1:TButton;  Button2:TButton;  procedureButton1Click(S......
  • 滑动窗口的最大值
    classSolution{public:vector<int>res;deque<int>q;vector<int>maxInWindows(vector<int>&nums,intk){for(inti=0;i<nums.size();i++){//先弹出左端点,保证队列里所有元素都是有效的......
  • 创建异形窗口1
    unitUnit1;interfaceuses Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms, Dialogs,StdCtrls;type TForm1=class(TForm)  Button1:TButton;  procedureButton1Click(Sender:TObject);  procedureFormDblClick......
  • 用鼠标获取任意窗口的句柄, 并把它当作子窗体
    unitUnit1;interfaceuses Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms, Dialogs,StdCtrls,ExtCtrls;type TForm1=class(TForm)  Panel1:TPanel;  Edit1:TEdit;  Button1:TButton;  Button2:TButton;......
  • 解决Tomcat服务器开启时DOS窗口的乱码问题(控制台乱码)
    从tomcat的目录中找:conf->logging.properties,用记事本打开,找到如下信息: 将UTF-8改为GBK(WIndows的命令窗口采用GBK的编码方式)......
  • 在PhpStorm项目工具窗口中显示.idea文件夹
    转自:https://www.codenong.com/33010238/ 对于.idea,它也有专用的注册表设置(默认情况下,我至少在PhpStorm中启用了此设置)Help|FindAction...并查找registry(或在Windows上使用默认键盘映射通过Maintenance Ctrl+Alt+Shift+/)进入内部-查找projectView.hide.dot.idea条......
  • 成品直播源码推荐,js点击让窗口抖动动画效果
    成品直播源码推荐,js点击让窗口抖动动画效果比如说用户的未输入密码就点击登录按钮,则输入框会晃动一下提示用户需要输入,实现这种效果很简单,只需要给元素添加一个类,然后做一个关键帧动画即可css代码 .shake{   animation:shake800msease-in-out; }@keyframesshake{......
  • Electron设置窗口大小setSize遇到的问题
    应用场景登录页跳转主页-窗口放大主页跳转登录页-窗口缩小方法setSize()遇到的问题在主页退出登录时,窗口缩小时setSize()不生效查看官方文档发现设置了窗口最小范围时,会影响setSize()所以,setSzie()调用要放在setMinimumSize()、setMaximumSize()后面functioninitMain......
  • [Scilab] Ubuntu 22.04下scilab绘图窗口空白
    造冰箱的大熊猫,本文适用于Ubuntu22.04@cnblogs2023/05/11 问题:在Ubuntu22.04下启动Scilab,使用surf()绘图,弹出绘图窗口,但窗口空白,没有看到绘制的图像。解决:1、在ShowApplications中找到AdditionalDrivers,安装显卡驱动。2、重启计算机。3、在ShowApplications中找到Sci......
  • 将透明度转换为 RGBA 中的 alpha 值, 将透明度转换为HEX颜色值中2位16进制数字
     1.透明度对比16进制数值透明度对比16进制数值 100%—FF99%—FC98%—FA97%—F796%—F595%—F294%—F093%—ED92%—EB91%—E890%—E689%—E388%—E087%—DE86%—DB85%—D984%—D683%—D482%—D181%—CF80%—......