RT,的确是有点儿烦人,写了个Daemon
修改配置文件中"CalcFrame,计算器",格式:"ClassName,标题",可以那spyxx抓下:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > <section name="PopKiller.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> </sectionGroup> </configSections> <applicationSettings> <PopKiller.Settings> <setting name="ClassWindowName" serializeAs="Xml"> <value> <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <string>CalcFrame,计算器</string> <string>TXGuiFoundation,腾讯网新闻</string> </ArrayOfString> </value> </setting> </PopKiller.Settings> </applicationSettings> </configuration>
代码简单得很,大家参考,[PopKiller.7z]
using System; using System.Runtime.InteropServices; using System.Timers; namespace PopKiller { class Program { [DllImport("user32.dll", CharSet = CharSet.Auto)] static extern IntPtr FindWindow(string className, string windowName); [DllImport("user32.dll", CharSet = CharSet.Auto)] static extern IntPtr SendMessage(IntPtr hWnd, uint msg, int wParam, int lParam); const uint WM_CLOSE = 0x0010; static System.Timers.Timer timer1; static System.Collections.Specialized.StringCollection lstClassWindowName; static void Main(string[] args) { lstClassWindowName = Settings.Default.ClassWindowName; timer1 = new Timer(); timer1.Elapsed += new ElapsedEventHandler(timer1_Elapsed); timer1.Start(); GC.KeepAlive(timer1); while (true) { System.Threading.Thread.Sleep(1000); } } static void timer1_Elapsed(object sender, ElapsedEventArgs e) { foreach (var item in lstClassWindowName) { IntPtr hwnd = FindWindow(item.Split(',')[0], item.Split(',')[1]); if (hwnd != IntPtr.Zero) { SendMessage(hwnd, WM_CLOSE, 0, 0); //System.Diagnostics.Debug.WriteLine("Closed " + item); } } } } }