The following describes how to hide the console window of the win32 console application.
This method is implemented by setting the compiler's link switch, so let's take a look at the compilation
(That is, the linker option ).
First, let's take a look at the/subsystem options of linker.
The syntax 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 shows the operating system how to run executable files.
Console:
Win32 character mode application. This type of application will generate a dos-like
The console window of the window. If the main function of the application is main () or wmain (),
This application is a console application.
Extensible firmware interface
A parameter option related to the cpu architecture is not commonly used. It is not described here.
If you are interested, visit the intel homepage to view the relevant content.
Native;
Device drive option. If the/driver: wdm option is set, the link option (native) is the default option.
Posix:
Applications running on the posix Subsystem in windows nt
Windows:
This type of application does not generate a console window. The window of this type of application is created by the user. In short
Is a standard win32 application. Its Entry address is the address of the winmain () function or the wwinmain () function.
If you define the main function as winmain or wwinmain In the application, the application is
Win32 application!
Windowsce:
Applications running on windows ce
Major and minor (optional ):
The primary version number and minor version number. This option is optional. The value ranges from 0 ~ Decimal integer between 65535
We can see from the above that if we create a win32 console application, the/subsystem option of linker should be
Console, which can be viewed in project> setting> link> project option in the vc development environment!
Next, let's take a look at how the application runs!
We know that the c/c program is supported by the cc Runtime Library.
The linker first looks for the startup function of the application, for example:
If you create a console program, the compiler's link switch will be in the following form:
/Subsystem: console/entry: maincrtstartup (ansi)
/Subsystem: console/entry: wmaincrtstartuup (unicode)
If you create a win32 application, the compiler uses the link switch as follows:
/Subsystem: windows/entry: winmain (ansi)
/Sbusystem: windows/entry: wwinmain (uincode)
The preceding two formats can be viewed in project> setting> link> project option.
The above subsystem and entry do not need to be set. If you only set/subsystem: console
The default entry switch should be/entry: maincrtstartup by default.
Otherwise, if you define the main function in the application, your/subsystem switch is used by default.
It should be/system: console
By default, the/subsystem and/entry switches match, that is
Console corresponds to maincrtstartup or wmaincrtstartup
Windows corresponds to winmain or wwinmain
However, we can also manually change them to make them not match.
For example, we can change it like this.
Copy codeCode: # 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 the windows option in/subsystem by default, it will automatically find winmain or wwinmain
However, you must specify the entry address to hide the default console window when running the program!
The above is set using the # pragma command in the code, and one is directly in the development environment
Manually changed project-> setting-> link-> project option!
After writing so many articles, I feel a little confused. There is no way. I have not written any articles before, so the wording may be poor. I hope you will forgive me.
1: If the console program has been written, you cannot change it. Write an API program, do not draw a window, then call the prepared console program with CreateProcess, and set the property to SW_HIDE.
2: you cannot use the console to write (CONSLOE). You can use WINMAIN as the portal. If you do not draw a window, no one else can see it. you only need to figure out how to hide your process in the taskbar.
3: If it is a console program, use the API function GetStdHandle () to obtain the window handle of the console program, and then hide the window
4: // hide the Console
# Pragma comment (linker, "/subsystem: \" windows \ "/entry: \" mainCRTStartup \"")
You need to write the console program to use this
Hide the console window in the console program!