Shield the console application window # pragma comment (linker, "/subsystem: Windows/entry: maincrtstartup ")

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.