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);
- }
- }
- }
复制代码
|