console window hiding

Here is my code.But first of all i dont understand anything about what the stealth function is doing and second it doesn't work.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  #include<iostream>
#include<stdlib.h>
using namespace std;
void Stealth()
{
HWND Stealth;
AllocConsole();
Stealth = FindWindowA(“ConsoleWindowClass”, NULL);
ShowWindow(Stealth,0);
}
int main()
{
        stealth();
   system("start /I www.google.com");
}
Since this program uses the Windows API, you need to include Windows.h with the appropriate definition of _WIN32_WINNT.

I'm very rusty with the Windows API, but (if I remember correctly) you can do something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// required for use of newer APIs (e.g., GetConsoleWindow())
# define _WIN32_WINNT 0x0500
// required for use of the Win32 API
# include <Windows.h>

int main() { 
  HWND console_handle = GetConsoleWindow(); 
  if (! console_handle) { /* no console associated with the calling process */
    return 1; 
  }

  ShowWindow(console_handle, SW_HIDE); 

  // The console should be hidden - your code follows.
}


MSDN is your friend:
https://docs.microsoft.com/en-us/windows/console/getconsolewindow
https://msdn.microsoft.com/en-us/library/6sehtctf.aspx
https://msdn.microsoft.com/en-us/library/windows/desktop/ms633548(v=vs.85).aspx

A quick search of this forum yields a relevant post by @Duthomhas
http://www.cplusplus.com/forum/beginner/12001/#msg57208
Last edited on
do you have any simple cross platform option? Cause i would avoid using long complicated codes i dont understand.
Registered users can post here. Sign in or register to post.