asd0023 发表于 2026-9-26 12:20:43

控件半透明工具

本帖最后由 asd0023 于 2026-9-26 12:47 编辑

<火山程序 类型 = "通常" 版本 = 1 />

类 控件透明工具 <公开 @全局类 = 真>
{
    方法 设置控件透明度 <公开 静态 类型 = 逻辑型 注释 = "透明度:0=全透255=不透明">
    参数 控件句柄 <类型 = 变整数>
    参数 透明度 <类型 = 整数>
    {
      变量 表头句柄 <类型 = 变整数>

      分层并设置 (控件句柄, 透明度)

      // LVM_GETHEADER = 4127:表头是表格内部的子窗口,需一起设置
      表头句柄 = SendMessageW (控件句柄, 4127, 0, 0)
      如果 (表头句柄 != 0)
      {
            分层并设置 (表头句柄, 透明度)
      }
      返回 (真)
    }

    # 加分层样式 → 刷帧 → 立即设置透明度

    方法 分层并设置 <公开 静态>
    参数 控件句柄 <类型 = 变整数>
    参数 透明度 <类型 = 整数>
    {
      // GWL_EXSTYLE=-20WS_EX_LAYERED=524288
      SetWindowLongW (控件句柄, -20, 位或 (GetWindowLongW (控件句柄, -20), 524288))
      // SWP_NOSIZE|NOMOVE|NOZORDER|NOACTIVATE|FRAMECHANGED = 55
      SetWindowPos (控件句柄, 0, 0, 0, 0, 0, 55)
      // LWA_ALPHA = 2
      SetLayeredWindowAttributes (控件句柄, 0, (字节)透明度, 2)
    }

    # ===== DLL 命令声明 =====

    方法 GetWindowLongW <公开 静态 类型 = 整数 @视窗.输入 = "user32.dll?GetWindowLongW">
    参数 hWnd <类型 = 变整数>
    参数 nIndex <类型 = 整数>

    方法 SetWindowLongW <公开 静态 类型 = 整数 @视窗.输入 = "user32.dll?SetWindowLongW">
    参数 hWnd <类型 = 变整数>
    参数 nIndex <类型 = 整数>
    参数 dwNewLong <类型 = 整数>

    方法 SetWindowPos <公开 静态 类型 = 逻辑型 @视窗.输入 = "user32.dll?SetWindowPos">
    参数 hWnd <类型 = 变整数>
    参数 hWndInsertAfter <类型 = 变整数>
    参数 X <类型 = 整数>
    参数 Y <类型 = 整数>
    参数 cx <类型 = 整数>
    参数 cy <类型 = 整数>
    参数 uFlags <类型 = 整数>

    方法 SendMessageW <公开 静态 类型 = 变整数 @视窗.输入 = "user32.dll?SendMessageW">
    参数 hWnd <类型 = 变整数>
    参数 Msg <类型 = 整数>
    参数 wParam <类型 = 变整数>
    参数 lParam <类型 = 变整数>

    方法 SetLayeredWindowAttributes <公开 静态 类型 = 逻辑型 @视窗.输入 = "user32.dll?SetLayeredWindowAttributes">
    参数 hWnd <类型 = 变整数>
    参数 crKey <类型 = 整数>
    参数 bAlpha <类型 = 字节>
    参数 dwFlags <类型 = 整数>
}

#


清单文件

li327065266kun 发表于 2026-9-26 15:44:37

所有控件都有用??

asd0023 发表于 2026-9-26 15:55:23




我测试 好像 都可以

兵三进一 发表于 2026-9-26 21:37:29

谢谢大神分享:)

asd0023 发表于 2026-9-26 22:36:22



把组件布局器 设置成透明,它里面的控件都会随着它一起透明。

兵三进一 发表于 2026-9-26 22:41:36

windows7 好像无效:)

asd0023 发表于 2026-9-26 22:58:26

本帖最后由 asd0023 于 2026-9-26 23:19 编辑

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity type="win32" name="MyVolApp" version="1.0.0.0" processorArchitecture="*"/>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
      <!-- Windows 10 / 11 -->
      <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
      <!-- Windows 8.1 -->
      <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
      <!-- Windows 8 -->
      <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
    </application>
</compatibility>
<dependency>
    <dependentAssembly>
      <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
    </dependentAssembly>
</dependency>
</assembly>

用记事本打开app.manifest 清单文件,在里面添加win7的<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>

该标签是 Windows 应用清单中的兼容性声明,用于告知系统此应用支持 Windows 7 行为;若目标是 Win7,GUID 应改为 {35138b9a-5d96-4fbd-8e2d-a2440225f93a}。 Microsoft +1 各 Windows 版本 GUID 对照 Windows Vista:{e2011457-1546-43c5-a5fe-008deee3d3f0} Windows 7:{35138b9a-5d96-4fbd-8e2d-a2440225f93a} Windows 8:{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38} Microsoft



兵三进一 发表于 2026-9-27 06:49:19

asd0023 发表于 2026-9-26 22:58
用记事本打开 ...

大侠威武:)

秋天的童话 发表于 2026-9-27 07:14:28

支持所有控件透明
页: [1]
查看完整版本: 控件半透明工具