Method One: (no flash) Add #pragma comment (linker, "/subsystem:\" windows\ "/entry:\" Maincrtstartup\ "") Method two: (This will have flashes)
#include "Windows.h"
void Main ()
{
HWND hwnd;
if (Hwnd=::findwindow ("Consolewindowclass", NULL))//Locate the console handle
{
:: ShowWindow (Hwnd,sw_hide); Hide Console window
}
Add your code. After the program runs, the window is automatically hidden and can only be seen in the process in Task Manager.
}
With the above code, the effect of hiding the current console window can be achieved. However, if the program is loaded automatically when the system is powered on, you will find that the console window is not automatically hidden, and if you close this window, double-click the console program to see that the window is hidden. To resolve this issue, you can use the following code:
#include "Windows.h"
void Main ()
{
Boot Auto Hide window
HWND hwnd;
Hwnd=findwindow ("Consolewindowclass", NULL);//Find the current window handle
if (HWND)
{
Showownedpopups (hwnd,sw_hide);//Show or hide all pop-up windows from the specified window
ShowWindow (hwnd,sw_hide);//control the visibility of the window
winexec function: Control window display Form
If the boot automatically run: C:\\windows\\system32\\keyboardrec.exe
WinExec ("C:\\windows\\system32\\keyboardrec.exe", sw_hide);
}
Your other code
}
Note: Hide the Code of the window, be sure to put it in front of the main function, otherwise the console window may not be hidden.
C + + lets Win32 Console application program run in the background