As we all know, console applications Program Generally, a console window (Virtual DOS window) is displayed. However, in many cases, the execution logic of the console program does not need to interact with the user at all. Therefore, it is redundant to display this ugly window, so how can we block it? Next, I will introduce a method.
After the operating system loads the application, after initialization, it is transferred to the entry point of the Program for execution. The default entry point of the program is actually set by the Connection Program, and the entry functions selected by different connectors are also different.
. In VC, the connector sets maincrtstartup for the console program, and then calls the main
Function. The entry function set for the graphic user interface (GUI) program is winmaincrtstartup, and winmaincrtstartup calls your own
Winmain function.
The entry point for specific settings is determined by the "/subsystem:" option parameter of the connector, which tells the operating system how to run the compiled. EXE file. Four methods can be specified
Type: "console | Windows | native | POSIX". If the value of this option is "Windows", the console is not required when the application is running.
For more information about off the connector Parameter options, see the msdn library.
The following describes how to set the compiler and connector through pre-compiled commands: Code After running, play the Windows System Startup Sound three times, and then exit. After running, the console window is not displayed.
# Include <windows. h>
# Include <mmsystem. h>
# Pragma comment (Lib, "winmm. lib") // tell the connector to connect to this library because we want to play multimedia sound
# Pragma comment (linker, "/subsystem: Windows/entry: maincrtstartup ")// Set connector options
Int main (void)
{
Playsound ("systemstart", null, snd_alias | snd_sync );
Sleep (50 );
Playsound ("systemstart", null, snd_alias | snd_sync );
Sleep (50 );
Playsound ("systemstart", null, snd_alias | snd_sync );
Sleep (50 );
Return 0;
}
Create an empty console program in the IDE environment, add the above Code to the project, and compile and run it.