Everyone knows that when writing a Win32 Console Application, when you run this program, you will have a Console window similar to the DOS window by default, but sometimes we just want to run a function code in the program, do not want to display This Console window allows the code to exit after the code is executed.
Let's introduce, how to hide the console window of Win32 Console Application
Because this method is to be implemented by setting the link switch of the compiler, let us take a look at the compiler's link switch option (that is, the Linker option).
First let's take a look at Linker / subsystem options
The syntax form of this option is as follows: / subsystem: {console | EFI_Application | EFI_BOOT_SERVICE_DRIVER | EFI_ROM | EFI_Runtime_Driver | Native | POSIX | Windows | Windowsce} [, Major [.minor]]
This link option tells the operating system how to run executables
Console: Win32 Character Mode Application, this type of application generates a console window similar to a DOS window when running, if the main function of the application is main () or wmain (), in default Application is a console application
The EXTENSIBLE FIRMWARE INTERFACE and CPU specific architecture are not commonly used, here is not described in detail. If you are interested, you can access the Intel Home page to view the content
Native; device driver option, if / driver: WDM option is set, the link option (native) is the default option
POSIX: Application running on the POSIX subsystem in Windows NT
Windows: This type of application does not generate a Console window, which is created by the user yourself, in short, is a standard Win32 Application, its entry address is the address of the WinMain () function or wwinmain () function. If you are using the main function defined by the application to Winmain or Wwinmain, the application is a Win32 Application by default!
Windows Ce: Applications running on Windows CE
Major and minor (optional): The main version number and the secondary version, this option is optional, this option is a decimal integer between 0 ~ 65535
As you can see from above, if we create a Win32 Console Application, Linker's / subsystem option should be console, you can see in the project-> setting-> link-> setting-> link-> setting-> link-> supply-> link-> project option of the VC development environment!
Let's take a look at how the app is running! We know the program written in VC, it is necessary to run the C / C runtime support when we run a C / C program, and then look for applications. The launch function of the program, for example, if you have established a console program, the compiler is the link switch will be the following form / subsystem: "console" / entry: "maincrtstartup" / subsystem: "console" / Entry : "WMAINCRTSTARTUUUUUP" (Unicode)
If you have established a Win32 Application, the compiler has a link switch will be a form / subsystem: "windows" / entry: "winmain" / sbusystem: "windows" / entry: "wwinmain" (Uincode)
The above two forms can be project-> setting-> link-> Project option, see the subsystem and entry do not need to be set, if you only set the / subsystem: "console", then the default Entry switch By default, it should be / entry: "maincrtststup", if you define the main function in the application, by default, your / subsystem switch should be / system: "console" by default / Subsystem and The / Entry switch is matched, that is, console corresponds to MaincrtStartup or WMAINCRTSTARTUPWINDOWS corresponding to WinMain or wwinmain
But we can also make them don't match by manually modifying.
For example, we can change this way
#pragma comment (Linker, "/ subsystem: /" windows / "/ entry: /" maincrtstartup / ") // set the entry address
INT Main (int Argc, char * argv []) {MessageBox (Null, "Hello", "Notice", MB_OK; Return 0;}
When the linker sees / subsystem is the Windows option, it will automatically find WinMain or wwinmain.
But we force to specify the entrance address, so the default console window will hide when running the program!
The above is to set the #pragma instruction in the code, and one is to manually change the project-> setting-> link-> supply-> link-> supply-> link-> Project option in the development environment!
I have written so much, I have a little bit of chaos, there is no way, I haven't worked for it before, so the wording may not be very good, I hope everyone will forgive me.