Sorry, you don't have access to the chatbox yet, VIPs and people with more than 2 posts get access to the chatbox :)


Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[C#] Window Hider
18-08-2010, 10:02 PM, (This post was last modified: 18-08-2010, 11:03 PM by MMOhax.)
Post: #1
[C#] Window Hider
Simple application to hide a selected window by the press of a button.

Useful at work Wink

[Image: WindowHider.png]

Program minimizes to tray icon, just click it to open it again.

Download EXE
Download Source (Visual Studio 2010)

Source code:
PHP Code:
using System;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;

namespace 
WindowHider
{
    public 
partial class Main Form
    
{
        public 
Main()
        {
            
InitializeComponent();
        }

        [
DllImport("user32.dll"CharSet CharSet.AutoSetLastError true)]
        static 
extern int GetWindowText(IntPtr hWndStringBuilder lpStringint nMaxCount);
        [
DllImport("user32.dll"SetLastError trueCharSet CharSet.Auto)]
        static 
extern int GetWindowTextLength(IntPtr hWnd);

        [
DllImport("user32.dll")]
        static 
extern bool ShowWindowAsync(IntPtr hWndint nCmdShow);
        private const 
int SW_HIDE 0;
        private const 
int SW_SHOWNORMAL 1;
        private const 
int SW_SHOWMAXIMIZED 3;

        [
DllImport("user32.dll")]
        [return: 
MarshalAs(UnmanagedType.Bool)]
        static 
extern bool IsWindowVisible(IntPtr hWnd);

        [
DllImport("user32.dll")]
        static 
extern bool IsZoomed(IntPtr hWnd);

        [
DllImport("user32.dll")]
        static 
extern ushort GetAsyncKeyState(int vKey);
        public static 
bool IsKeyPushedDown(System.Windows.Forms.Keys vKey)
        {
            return 
!= (GetAsyncKeyState((int)vKey) & 0x8000);
        }

        [
DllImport("user32.dll")]
        private static 
extern int EnumWindows(CallbackPtr callPtrIntPtr lParam);
        public 
delegate bool CallbackPtr(IntPtr hwndIntPtr lParam);
        private 
CallbackPtr ptrCallback;

        private 
bool Report(IntPtr hwndIntPtr lParam)
        {
            if (!
IsWindowVisible(hwnd)) { return true; }

            
int length GetWindowTextLength(hwnd);
            
StringBuilder sb = new StringBuilder(length 1);
            
GetWindowText(hwndsbsb.Capacity);

            if (
sb.ToString().Length 0) {
                list.
Items.Add(sb.ToString() + " " hwnd);
            }

            return 
true;
        }

        private 
bool visible true;
        private 
bool wasmax false;
        private 
bool wasdown false;

        private 
void Visibility(bool show)
        {
            
string[] split = list.SelectedItem.ToString().Split(' ');
            
IntPtr hwnd = (IntPtr)Convert.ToInt32(split[split.Length 1]);

            if (
show) {
                if (
wasmax) {
                    
ShowWindowAsync(hwndSW_SHOWMAXIMIZED);
                }
                else {
                    
ShowWindowAsync(hwndSW_SHOWNORMAL);
                }
            }
            else {
                
wasmax IsZoomed(hwnd);
                
ShowWindowAsync(hwndSW_HIDE);
            }
        }

        private 
void list_DropDown(object senderEventArgs e)
        {
            list.
Items.Clear();

            
ptrCallback = new CallbackPtr(Report);
            
EnumWindows(ptrCallbackIntPtr.Zero);
        }

        private 
void Main_Load(object senderEventArgs e)
        {
            
hotkey.SelectedIndex 0;
        }

        private 
void Main_Resize(object senderEventArgs e)
        {
            if (
this.WindowState == FormWindowState.Minimized) {
                
notifyIcon.Visible true;
                
this.Hide();
            }
            else {
                
notifyIcon.Visible false;
            }
        }

        private 
void notifyIcon_Click(object senderEventArgs e)
        {
            
this.Show();
            
this.WindowState FormWindowState.Normal;
            
this.Focus();
            
notifyIcon.Visible false;
        }

        private 
void timer_Tick(object senderEventArgs e)
        {
            
timer.Enabled false;

            
Keys key Keys.F7;
            if (
hotkey.SelectedItem.ToString() == "F8") { key Keys.F8; }
            else if (
hotkey.SelectedItem.ToString() == "F9") { key Keys.F9; }
            else if (
hotkey.SelectedItem.ToString() == "F10") { key Keys.F10; }
            else if (
hotkey.SelectedItem.ToString() == "F11") { key Keys.F11; }
            else if (
hotkey.SelectedItem.ToString() == "F12") { key Keys.F12; }

            if (
IsKeyPushedDown(key))
            {
                if (!
wasdown && list.SelectedIndex >= 0)
                {
                    
visible = !visible;
                    
Visibility(visible);
                }
                
wasdown true;
            }
            else
            {
                
wasdown false;
            }

            
timer.Enabled true;
        }
    }

[Image: sitelogo.png]
Reply
10-04-2011, 02:46 PM,
Post: #2
RE: [C#] Window Hider
Thats awsome man. ^^
Reply
26-05-2011, 02:53 PM,
Post: #3
RE: [C#] Window Hider
So will this work for BFH?
~Volcom~
Reply
26-05-2011, 09:25 PM,
Post: #4
RE: [C#] Window Hider
no...
Reply
27-05-2011, 04:41 AM,
Post: #5
RE: [C#] Window Hider
what is that????
Reply
27-05-2011, 10:03 PM,
Post: #6
RE: [C#] Window Hider
stupid question should get stupid answer:
HAAAAAAAAAAAXOR
Reply
27-05-2011, 11:30 PM,
Post: #7
RE: [C#] Window Hider
hides a spesific window with a press of a button but not BFH it just hides the frame.
~Volcom~
Reply
28-05-2011, 12:20 AM,
Post: #8
RE: [C#] Window Hider
doest work in any game :-(
Reply




Users browsing this thread: 1 Guest(s)