标题: [工具合集] 设置windows下窗口程序半透明工具 [打印本页]
作者: whiter 时间: 2019-4-7 12:54 标题: 设置windows下窗口程序半透明工具
windows下自带的编译工具
%windir%/Microsoft.NET/Framework/v4.0.30319/csc.exe /nologo trans.cs
用法trans.exe [进程名] [透明度]
进程名 看任务管理器或者tasklist
透明度 0~255- using System;
- using System.Runtime.InteropServices;
- namespace App
- {
- class Program
- {
- [DllImport("user32.dll", SetLastError = true)]
- static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);
- [DllImport("user32.dll", SetLastError = true)]
- static extern int SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);
- [DllImport("user32.dll", SetLastError = true)]
- static extern int GetWindowLong(IntPtr hWnd, int nIndex);
- static void Main(string[] args)
- {
- byte trans = 168;
- var processName = "chrome";
- if(args.Length == 1){
- processName = args[0];
- }
- if(args.Length == 2){
- processName = args[0];
- trans = Convert.ToByte(args[1]);
- }
- Console.WriteLine("processName:"+processName);
- Console.WriteLine("透明度0~255:"+trans);
- Program program = new Program();
- System.Diagnostics.Process[] ps = System.Diagnostics.Process.GetProcessesByName(processName);
- System.Console.WriteLine("当前打开进程个数:"+ps.Length);
- if(ps.Length < 1) {
- Console.WriteLine(processName+" 没有在执行");
- return;
- };
- foreach(System.Diagnostics.Process p in ps){
- bool isTransed = program.MakeWindowTransparent(p.MainWindowHandle, trans);
- if(isTransed){
- Console.WriteLine("修改成功");
- return;
- }
- }
- Console.WriteLine("修改失败");
- }
- bool MakeWindowTransparent(IntPtr hWnd, byte factor)
- {
- const int GWL_EXSTYLE = (-20);
- const uint WS_EX_LAYERED = 0x00080000;
- int Cur_STYLE = GetWindowLong(hWnd, GWL_EXSTYLE);
- SetWindowLong(hWnd, GWL_EXSTYLE, (uint)(Cur_STYLE | WS_EX_LAYERED));
- const uint LWA_COLORKEY = 1;
- const uint LWA_ALPHA = 2;
- const uint WHITE = 0xffffff;
- return SetLayeredWindowAttributes(hWnd, WHITE, factor, LWA_COLORKEY | LWA_ALPHA);
- }
- }
- }
复制代码
作者: 老刘1号 时间: 2019-4-7 13:07
支持,不过这个happy好像写过
作者: whiter 时间: 2019-4-7 13:26
回复 2# 老刘1号
我记得之前的应该是c++写的,这个是c#的
作者: lockxxx 时间: 2023-11-22 11:12
成功,感谢分享
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |