Window Hiding with C#(ZT)

作者:袖梨 2022-07-02
Introduction
Ever wanted to completely hide all the crap on your machine that you're not supposed to be looking at when your boss walks by? Try this handy Window Hider utility and all you will have to do is press a customizable hotkey.    
This source project will demonstrate the implementation of hot keys, enumerable collections, enums, binary serialization, DllImports of Win32 API, Window Enumeration, CallBacks/Delegates, Custom Events and Event Handlers, and more. It's quite a bit of code to look through but some of you may find it interesting.
The guts of the application is based in the Window and Windows classes that enumerate and hide the open windows your choose: using System;using System.Text;using System.Collections;using System.Runtime.InteropServices; namespace WindowHider{    ///     /// Object used to control a Windows Form.    ///     public class Window    {        ///         /// Win32 API Imports        ///         [DllImport("user32.dll")] private static extern       bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);        [DllImport("user32.dll")] private static extern       bool SetForegroundWindow(IntPtr hWnd);        [DllImport("user32.dll")] private static extern       bool IsIconic(IntPtr hWnd);        [DllImport("user32.dll")] private static extern       bool IsZoomed(IntPtr hWnd);        [DllImport("user32.dll")] private static extern       IntPtr GetForegroundWindow();        [DllImport("user32.dll")] private static extern       IntPtr GetWindowThreadProcessId(IntPtr hWnd, IntPtr ProcessId);        [DllImport("user32.dll")] private static extern       IntPtr AttachThreadInput(IntPtr idAttach, IntPtr idAttachTo, int fAttach);     ///         /// Win32 API Constants for ShowWindowAsync()        ///         private const int SW_HIDE = 0;        private const int SW_SHOWNORMAL = 1;        private const int SW_SHOWMINIMIZED = 2;        private const int SW_SHOWMAXIMIZED = 3;        private const int SW_SHOWNOACTIVATE = 4;        private const int SW_RESTORE = 9;        private const int SW_SHOWDEFAULT = 10;     ///         /// Private Fields        ///         private IntPtr m_hWnd;        private string m_Title;        private bool m_Visible = true;        private string m_Process;        private bool m_WasMax = false;     ///         /// Window Object's Public Properties        ///         public IntPtr hWnd        {       get{return m_hWnd;}        }    &nbs

相关文章

精彩推荐