Advertisement
Guest User

visor

a guest
Jun 21st, 2011
1,722
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.55 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Diagnostics;
  10. using System.Runtime.InteropServices;
  11. using Utilities;
  12.  
  13. namespace Visor
  14. {
  15.     public partial class Form1 : Form
  16.     {
  17.         #region Constants
  18.         private const int SW_HIDE = 0;
  19.         private const int SW_SHOWNORMAL = 1;
  20.         private const int SW_SHOW = 5;
  21.         #endregion Constants
  22.         #region APIs
  23.         [System.Runtime.InteropServices.DllImport("user32.dll", CharSet=System.Runtime.InteropServices.CharSet.Auto)]
  24.         private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
  25.         [System.Runtime.InteropServices.DllImport("user32.dll", CharSet=System.Runtime.InteropServices.CharSet.Auto)]
  26.         private static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
  27.         [System.Runtime.InteropServices.DllImport("user32.dll")]
  28.         private static extern bool SetForegroundWindow(IntPtr hwnd);
  29.         [System.Runtime.InteropServices.DllImport("user32.dll")]
  30.         private static extern IntPtr SetFocus(IntPtr hwnd);
  31.         [System.Runtime.InteropServices.DllImport("user32.dll")]
  32.         internal static extern int AttachThreadInput(int idAttach, int idAttachTo, bool fAttach);
  33.         [System.Runtime.InteropServices.DllImport("user32.dll")]
  34.         private static extern IntPtr GetFocus();
  35.         #endregion APIs
  36.         // Declare global key hook object
  37.         private globalKeyboardHook ghk = new globalKeyboardHook();
  38.         // bool to track if console is hidden or visible
  39.         private bool isHidden = false;
  40.         public void ShowApp()
  41.         {
  42.         IntPtr h = FindWindow(null, "C:\\Windows\\system32\\cmd.exe");
  43.         ShowWindow(h, SW_SHOW);
  44.         //EnableWindow(h, true);
  45.         isHidden = false;
  46.             // set focus to console window
  47.  
  48.         SetForegroundWindow(h);
  49.         System.Diagnostics.Debug.WriteLine(h);
  50.         }
  51.         public void HideApp()
  52.         {
  53.         IntPtr h = FindWindow(null, "C:\\Windows\\system32\\cmd.exe");
  54.         ShowWindow(h, SW_HIDE);
  55.         isHidden = true;
  56.     }
  57.         public Form1()
  58.         {
  59.             // add hooks for tilde
  60.             ghk.HookedKeys.Add(Keys.Oemtilde);
  61.             ghk.KeyDown += new KeyEventHandler(ghk_KeyDown);
  62.             ghk.KeyUp += new KeyEventHandler(ghk_KeyUp);
  63.             InitializeComponent();
  64.         }
  65.         void ghk_KeyDown(object sender, KeyEventArgs e)
  66.         {
  67.             System.Diagnostics.Debug.WriteLine("Down\t" + e.KeyCode.ToString());
  68.             e.Handled = true;
  69.         }
  70.         void ghk_KeyUp(object sender, KeyEventArgs e)
  71.         {
  72.             System.Diagnostics.Debug.WriteLine("Up\t" + e.KeyCode.ToString());
  73.             e.Handled = true;
  74.             if (isHidden == false)
  75.                 HideApp();
  76.             else
  77.                 ShowApp();
  78.         }
  79.         private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
  80.         {
  81.             ShowApp();
  82.         }
  83.         private void Form1_Resize(object sender, System.EventArgs e)
  84.         {
  85.             if (FormWindowState.Minimized == WindowState)
  86.                 Hide();
  87.         }
  88.         private void Form1_Load(object sender, EventArgs e)
  89.         {
  90.             Visible = false;
  91.             ShowInTaskbar = false;
  92.  
  93.             Process runExe = new Process();
  94.             runExe.StartInfo.FileName = "cmd.exe";
  95.             Process.Start("cmd.exe");
  96.         }
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement