当前位置:编程学习 > C#/ASP.NET >>

Window Hiding with C#(ZT)

答案:

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
{
    /// <summary>
    /// Object used to control a Windows Form.
    /// </summary>
    public class Window
    {
        /// <summary>
        /// Win32 API Imports
        /// </summary>
        [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);
 
        /// <summary>
        /// Win32 API Constants for ShowWindowAsync()
        /// </summary>
        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;
 
        /// <summary>
        /// Private Fields
        /// </summary>
        private IntPtr m_hWnd;
        private string m_Title;
        private bool m_Visible = true;
        private string m_Process;
        private bool m_WasMax = false;
 
        /// <summary>
        /// Window Object's Public Properties
        /// </summary>
        public IntPtr hWnd
        {
            get{return m_hWnd;}
        }
      &nbs

上一个:穿针引线:一个不完全的对代码加亮的代码,大家可以对其进行扩展!(原创)
下一个:调试使用 Visual Basic .NET 或 Visual C# .NET 创建的Windows窗体控件 (zt)

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,