[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[工具合集] 设置windows下窗口程序半透明工具

windows下自带的编译工具
%windir%/Microsoft.NET/Framework/v4.0.30319/csc.exe /nologo trans.cs
用法trans.exe [进程名] [透明度]
进程名 看任务管理器或者tasklist
透明度 0~255
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace App
  4. {
  5.     class Program
  6.     {
  7.         [DllImport("user32.dll", SetLastError = true)]
  8.         static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);
  9.         [DllImport("user32.dll", SetLastError = true)]
  10.         static extern int SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);
  11.         [DllImport("user32.dll", SetLastError = true)]
  12.         static extern int GetWindowLong(IntPtr hWnd, int nIndex);
  13.         static void Main(string[] args)
  14.         {
  15.             byte trans = 168;
  16.             var processName = "chrome";
  17.             if(args.Length == 1){
  18.                 processName = args[0];
  19.             }
  20.             if(args.Length == 2){
  21.                 processName = args[0];
  22.                 trans = Convert.ToByte(args[1]);
  23.             }
  24.             Console.WriteLine("processName:"+processName);
  25.             Console.WriteLine("透明度0~255:"+trans);
  26.             Program program = new Program();
  27.             System.Diagnostics.Process[] ps = System.Diagnostics.Process.GetProcessesByName(processName);
  28.             System.Console.WriteLine("当前打开进程个数:"+ps.Length);
  29.             if(ps.Length < 1) {
  30.                 Console.WriteLine(processName+" 没有在执行");
  31.                 return;
  32.             };
  33.             foreach(System.Diagnostics.Process p in ps){
  34.                 bool isTransed = program.MakeWindowTransparent(p.MainWindowHandle, trans);
  35.                 if(isTransed){
  36.                     Console.WriteLine("修改成功");
  37.                     return;
  38.                 }
  39.             }
  40.             Console.WriteLine("修改失败");
  41.         }
  42.         bool MakeWindowTransparent(IntPtr hWnd, byte factor)
  43.         {
  44.             const int GWL_EXSTYLE = (-20);
  45.             const uint WS_EX_LAYERED = 0x00080000;
  46.             int Cur_STYLE = GetWindowLong(hWnd, GWL_EXSTYLE);
  47.             SetWindowLong(hWnd, GWL_EXSTYLE, (uint)(Cur_STYLE | WS_EX_LAYERED));
  48.             const uint LWA_COLORKEY = 1;
  49.             const uint LWA_ALPHA = 2;
  50.             const uint WHITE = 0xffffff;
  51.             return SetLayeredWindowAttributes(hWnd, WHITE, factor, LWA_COLORKEY | LWA_ALPHA);
  52.         }
  53.     }
  54. }
复制代码

支持,不过这个happy好像写过

TOP

回复 2# 老刘1号
我记得之前的应该是c++写的,这个是c#的

TOP

成功,感谢分享

TOP

返回列表