1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85:
| using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices;
namespace IconKiller { class IconKiller { public delegate bool EnumDelegate(IntPtr hWnd, int lParam);
[DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool IsWindowVisible(IntPtr hWnd);
[DllImport("user32.dll", EntryPoint = "GetWindowText", ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)] public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpWindowText, int nMaxCount);
[DllImport("user32.dll", EntryPoint = "EnumDesktopWindows", ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)] public static extern bool EnumDesktopWindows(IntPtr hDesktop, EnumDelegate lpEnumCallbackFunction, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto)] static extern IntPtr LoadImage(IntPtr hInst, string lpsz, IntPtr uType, IntPtr cxDesired, IntPtr cyDesired, IntPtr fuLoad);
[DllImport("user32.dll", CharSet = CharSet.Auto)] static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
private const string FILE = "blank.ico"; private const UInt32 WM_SETICON = 0x80; private const int IMAGE_ICON = 1; private const int LR_DEFAULTSIZE = 0x40; private const int ICON_SMALL = 0; static void Main(string[] args) { IntPtr icon = LoadImage(new IntPtr(0), FILE, new IntPtr(IMAGE_ICON), new IntPtr(0), new IntPtr(0), new IntPtr(LR_DEFAULTSIZE));
EnumDelegate filter = delegate(IntPtr hWnd, int lParam) { StringBuilder strbTitle = new StringBuilder(255); int nLength = GetWindowText(hWnd, strbTitle, strbTitle.Capacity + 1); string strTitle = strbTitle.ToString();
if (IsWindowVisible(hWnd) && string.IsNullOrEmpty(strTitle) == false && strTitle != "Start" && strTitle != "Program Manager") { Console.WriteLine(strTitle); SendMessage(hWnd, WM_SETICON, new IntPtr(ICON_SMALL), icon); } return true; };
Console.Read(); } } } |