I want to know how to hide a console window when it starts.
It's for a keylogger program, but it's not my intention to hack someone. It's for a little school project that I want to make to show the dangers about hackers.
Here's my code so far:
#include <cstdlib> #include <iostream> #include <Windows.h> using namespace std; int main() { cout << "Note. This program is only created to show the risk of being unaware of hackers." << endl; cout << "This program should never be used to actually hack someone." << endl; cout << "Therefore this program will never be avaiable to anyone, except me." << endl; FreeConsole(); system("PAUSE"); return 0; }
I see the window appear and immediately disappear at startup. It seems to open a new console right after that, which is just blank. (By blank I mean "Press any key to continue.." I'm wondering if it has anything to do with system("PAUSE")
)
So I want to know why it opens a new console, instead of only creating and hiding the first one.
Thanks. :)
"SW_HIDE" hides the window, while "SW_SHOW" shows the window.
If you do not know what I am talking about: press Win+R, type “help” and press ENTER. A black console window will open, execute the HELP command and close again. Often, this is not desired. Instead, the command should execute without any visible window.
To literally hide/show the console window on demand, you could use the following functions: It's possible to hide/show the console by using ShowWindow. GetConsoleWindow retrieves the window handle used by the console. IsWindowVisible can be used to checked if a window (in that case the console) is visible or not.
#include <Windows.h> void HideConsole() { ::ShowWindow(::GetConsoleWindow(), SW_HIDE); } void ShowConsole() { ::ShowWindow(::GetConsoleWindow(), SW_SHOW); } bool IsConsoleVisible() { return ::IsWindowVisible(::GetConsoleWindow()) != FALSE; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With