컴퓨터 개발/닷넷2011. 1. 25. 15:56
using System;
using System.Runtime.InteropServices;

public class TransA
{
	const int GWL_ID = (-12);
	const int GWL_STYLE = (-16);
	const int GWL_EXSTYLE = (-20);

	const int WS_EX_LAYERED = 0x00080000;
	const int LWA_ALPHA = 0x00000002;


	[DllImport("user32.dll")]
	public static extern int SetWindowLong(int hWnd, int nIndex, int dwNewLong);

	[DllImport("user32.dll", SetLastError=true)]
	public static extern int GetWindowLong(int hWnd, int nIndex);

	
	[DllImport("user32.dll")]
	public static extern bool SetLayeredWindowAttributes(int hWnd, uint crKey, byte bAlpha, uint dwFlags);
	
	[DllImport("user32.dll")]
	public  static extern int FindWindow(string  lpClassName, string  lpWindowName);
	
	public static void Main(string[] args)
	{
		if (args.Length >= 2)
		{
			int alpha = int.Parse(args[0]);
			if ( alpha >= 100 && alpha <= 255 )
			{
				for( int i = 1 ; i < args.Length ; i++ )
				{
					string names = args[i].ToString();
					
					int hwnd = FindWindow( null, names );
					if ( hwnd != 0 )
					{
						SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
						SetLayeredWindowAttributes( hwnd, 0, ( byte )alpha, LWA_ALPHA );
						Console.WriteLine( string.Format("{0}을 찾아서 변환 하였습니다.", names ) );
						hwnd = 0;
					}
				}
			}
			else
			{
				Console.WriteLine( "alpha 값은 100 이상 255 미만의 값을 가집니다." );
			}
		}
		else
		{
			Console.WriteLine( "사용법 : app.exe alpha_value Windows_name" );
		}
	}

}	

Posted by yhlee