using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; namespace PluginListener { public class WindowIntPtrUtil { [DllImport("user32.dll", SetLastError = true)] public static extern IntPtr FindWindow(string className, string windowName); [DllImport("user32.dll")] public static extern IntPtr FindWindowByProcessId(int processId, int threadId); [DllImport("user32.dll", SetLastError = true)] public static extern uint GetWindowThreadProcessId(IntPtr ptr, out uint processId); /// /// 操作窗口 1是激活 6是最小化 /// /// /// 1是激活 6是最小化 /// [DllImport("user32.dll", SetLastError = true)] public static extern bool ShowWindow(IntPtr ptr, int command); [DllImport("user32.dll", SetLastError = true)] public static extern bool SendMessage(IntPtr ptr, UInt32 Msg, IntPtr wParam, IntPtr lParam); [DllImport("user32.dll", SetLastError = true)] public static extern bool PostMessage(IntPtr ptr, UInt32 Msg, IntPtr wParam, IntPtr lParam); public static void KillProcessByIntPtr(IntPtr ptr) { //GetWindowThreadProcessId(ptr, out uint processId); //if (processId == 0) return; //Process process = Process.GetProcessById((int)processId); //process.Kill(); //process.WaitForExit(); CloseWindow(ptr); } public static void CloseWindow(IntPtr ptr) { SendMessage(ptr, (UInt32)0x0010, IntPtr.Zero, IntPtr.Zero); } } }