Hide the implementation code of the console program window in VC

  • 2020-04-01 21:36:03
  • OfStack

Here's how to hide the console window for win32 console application
Since this method is implemented by setting the link switch of the compiler, let's take a look at compilation
The link switch option (that is, the linker option) for the.
First we look at the/subsystem option would
The syntax for this option is as follows:

/ subsystem: {the 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 the executable
The console:
Win32 character mode applications, this type of application when run will produce a similar to DOS
Window of the console window, if the main function in the application is main() or wmain(), by default
The application is a console application

Extensible firmware interface

A parameter option related to a cpu-specific architecture that is not commonly used and will not be covered in detail here.

If you are interested, please visit the Intel home page
Native;
Device driver option, this link option (native) is the default if the /driver: WDM option is set
Posix:
Applications running on the posix subsystem in Windows nt
Windows:
This type of application does not produce a console window, the Windows for this type of application are created by the user himself, in short
Is a standard win32 application, its entry address is the winmain() function or the address of the wwinmain() function
If the main function you define in your application is winmain or wwinmain, the application is one by default

Win32 application!
Windowsce:

Applications running on Windows ce

Major and minor (optional) :

Major and minor version Numbers, which are optional, are decimal integers between 0 and 65535
Can be seen from the above if we create a win32 console application, would/subsystem option should be
Console, can be in the vc development environment of the project-> Setting - > The link - > In project option!
Now let's see how the application works!
We know that programs written with vc need to be supported by cc runtime. When we run a c/c program
The linker first looks for the application's startup function, for example:
If you build a console program, the compiler will link switches in the following form
/ subsystem: the console/entry: maincrtstartup (ANSI)
/ subsystem: the console/entry: wmaincrtstartuup (unicode)
If you create a win32 application, the compiler's link switch will look like this
/ subsystem: Windows/entry: winmain (ANSI)
/ sbusystem: Windows/entry: wwinmain (uincode)
The above two forms can be re-project -> Setting - > The link - > In project option
The upper subsystem and entry does not need to set, if you only set the/subsystem: the console
By default, the default entry switch should be /entry:maincrtstartup
On the other hand, if you define the main function in the application, by default, you the/subsystem switch
Should be/system: the console
By default/subsystem and/entry switch is matching, that is
The console corresponds to maincrtstartup or wmaincrtstartup
Windows corresponds to winmain or wwinmain
But we can also manually alter them to make them not match
For example, we can change it like this


#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;
}

By default, the linker see Windows/subsystem is option, it will automatically search for winmain or wwinmain
But we force you to specify the entry address so that the default console window is hidden when you run the program!
This is set using the #pragma directive in the code, and this is set directly in the development environment

The project - > Setting - > The link - > Manual modification in project option!

After writing so much, I feel a little bit confused, there is no way, I have not written any article before, so the wording may not be very good, I hope you forgive me.

1: if the console program is already written and cannot be changed, it can be. Write an API without drawing a window, then call the written console program with CreateProcess and set the property to SW_HIDE.
2: you can't use the console to write (CONSLOE), use WINMAIN as the entry, do not draw the window, others can not see.
3: if you are a console application, use the API function GetStdHandle() to get the window handle for the console application, and then hide the window
4:// this sentence hides the console
# pragma comment (would, "/ subsystem: \ Windows \" mainCRTStartup "/ entry: \" \ "")
That's what you're going to use to write a console program
Hide the console window in the console program!


Related articles: