Give a windows handle (Native), how to close the windows using C#?
问题 Given a handle of a window, how can I close the window by using the window handle? 回答1: The easiest way is to use PInvoke and do a SendMessage with WM_CLOSE . [DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam); private const UInt32 WM_CLOSE = 0x0010; void CloseWindow(IntPtr hwnd) { SendMessage(hwnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero); } 回答2: Not sure if there is another way but you could PInvoke