Hide Console Window C#

C# language provides extensive function which helps in programming variety of tools. Following is the snippet for Hiding console window which is recommended for programming spy or background tools.. 





Image source from internet

namespace hidedemo
{
class Program
{


[DllImport("user32.dll")]

public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport("user32.dll")]

static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);


public static void hide()
{
Console.Title = "Hide window demo - C# program under .NET platform"; // Give an unique title to identify the console window
IntPtr hWnd = FindWindow(null, "Hide window demo - C# program under .NET platform"); //put your console window caption here

if (hWnd != IntPtr.Zero)
{

// Hide the console window

ShowWindow(hWnd, 0); // 0 = SW_HIDE

}
}
public static void show()
{
Console.Title = "Hide window demo - C# program under .NET platform"; //Give an unique title to identify the console window
IntPtr hWnd = FindWindow(null, "Hide window demo - C# program under .NET platform"); //put your console window caption here

if (hWnd != IntPtr.Zero)
{

// Show the console window

ShowWindow(hWnd, 1);

}
}
static void Main(string[] args)
{

/*---------------------

Customize the code according to your need

-----------------------*/
hide();

show();

}
}

Comments

Popular Posts