The Realm of Real

..rjproz's blog..

Hide Console Window C++

There are two ways to hide the console window. Depending on the Compiler one of them will work.. Recommended for programming spy or background tools..

/*  Method 1 to hide or show console window */

void stealth()
{
ShowWindow( GetConsoleWindow(), SW_HIDE );
}

void reveal()
{
ShowWindow( GetConsoleWindow(), SW_RESTORE );
}

Image source from internet

/*  Method 2 to hide or show console window */

void stealth()
{
typedef HWND (WINAPI *tGetConsoleWindow)(void);
tGetConsoleWindow pGetConsoleWindow = 0;
HINSTANCE handle = ::LoadLibrary("Kernel32.dll");
if ( handle )
pGetConsoleWindow = (tGetConsoleWindow)::GetProcAddress(handle, "GetConsoleWindow");

HWND hwnd = pGetConsoleWindow();
::ShowWindow(hwnd,SW_HIDE);
}

void reveal()
{
typedef HWND (WINAPI *tGetConsoleWindow)(void);
tGetConsoleWindow pGetConsoleWindow = 0;
HINSTANCE handle = ::LoadLibrary("Kernel32.dll");
if ( handle )
pGetConsoleWindow = (tGetConsoleWindow)::GetProcAddress(handle, "GetConsoleWindow");

HWND hwnd = pGetConsoleWindow();
::ShowWindow(hwnd,SW_SHOW);
}


Leave a Reply

Your email address will not be published. Required fields are marked *