OpenCV learning notes (2) Hide the Console window

Source: Internet
Author: User

When using OpenCV in VC ++, A win32 console application project is generally created. When such a program is run, a console window similar to a DOS window is created by default, for interaction between programs and users.

However, sometimes we only want to run a piece of functional code in the program. Instead of displaying this console window, the program automatically exits after the code is executed. You can hide the console window of the win32 console application in either of the following ways:

1. Run the # pragma command to modify the code. Add the following line of code before the main function:

# Pragma comment (linker, "/subsystem:/" windows/"/entry:/" mainCRTStartup /"")

2. Set Project Properties to modify the Console (/Subsystem: CONSOLE). In the SUBSYSTEM item of Project> Properties> Configuration Properties> Linker> System, set Console (/Subsystem: CONSOLE) change to Console (/SUBSYSTEM: WINDOWS), so that the Console program window is hidden.

The above method is implemented by setting the compiler's link switch, so let's take a look at the compiler's link switch option (that is, the linker option ).

1. linker/subsystem options:

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 console window similar to the DOS window when running. If the main function of an application is main () or wmain (), the application is a console application by default.

-- Extensible Firmware Interface (EFI _***):
These four EFI _ **** are Parameter options related to the CPU architecture and are not commonly used. If you are interested, you can visit the intel homepage to view 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 program window is created by the user. In short, it is a standard Win32 application. Its Entry address is the WinMain () function or wWinMain () function () the address of the function. If the main function you define in the Application is WinMain or wWinMain, the Application is a Win32 Application by default!

-- 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 ~ A decimal integer between 65535.

As shown above, if we create a win32 console application, the/subsystem option of linker should be CONSOLE, you can see it in project> setting> link> project option of VC6 development environment or Project> Properties> Configuration Properties> Linker> System of VS2005/2008 development environment.!

2. How is an application running!

We know that C/C ++ runtime libraries are required for programs written in VC. When we run a C/C ++ program, 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's link switch will be in the following form:

/Subsystem: "windows"/entry: "WinMain" (ANSI)
/Sbusystem: "windows"/entry: "wWinMain" (UINCODE)

The preceding two formats can be found in Project> Properties> Configuration Properties> Linker> System (VS2005/08). The subsystem and entry do not need to be set, if you only set/subsystem: "console", the default entry switch should be/entry: "mainCRTStartup". Otherwise, if you define the main function in the application, by default, your/subsystem switch should be/system: "console ".

By default, the/subsystem and/entry switches match, that is, the console corresponds to mainCRTStartup or wmainCRTStartup; windows corresponds to WinMain or wWinMain.

However, we can also manually change the settings so that they do not match. For example, we can change the settings as follows:

# 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, when the linker sees the windows option in/subsystem, 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 Project-> Properties-> Configuration Properties-> Linker-> System (VS2005/08) manual modification in!

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.