A new console is created when the system starts a console program, and the entry point of this console program is the main function. For example, the system creates a new console when the command processor (command prompt) is started. Once the command processor starts a new console program, the user can specify whether the system creates a new console for the new program, or inherits the current command processor console.
The program can create a console by the following method:
A GUI program or console program can invoke the CreateProcess function in a new console in a new console in a new console in a new console. (Usually, a console program will inherit its parent console, and its received input may be unexpected.) A graphical interface (GUI) program or console program that is currently not in the console can be called by calling the allocconsole function Create a new console. (GUI is not in the console once created, if the console program is created by delivering Detached_Process to the CreateProcess function, is not in the console.)
Typically, the program has an error and requires allocConsole to create a console using AllocConsole. If the GUI program does not use the graphical interface normally, a console will be created; or the console program cannot interact with the user, it will create a console prompt error generation.
Of course, the program can also assign the CREATE_NEW_CONSOLE flag to create a console when CreateProcess can create a console. The console created by this method can access its subroutines, but cannot access the parent program. The parental console can interact with the user separately without any conflict. If the console program is not specified, the two programs will use a console at the same time, and the input required by a program cannot be guaranteed correctly. Applications can avoid confusion by creating, and do not inherit the processing of the input buffer; or allow the subroutine to inherit the input buffer processing, and prevent the parent program from reading the input until the subroutine ends, can also be avoided The necessary mistakes are generated.
Creating a new console will generate a new console window and use a separate I / O screen buffer. The program is associated with the new console through the getStdHandle function to obtain the handle of the new console input and the screen buffer, and the console can be accessed through these handles.
Using CreateProcess, you can specify a StartupInfo structure that controls the first new console created by the subroutine (if there are many words). If you specify the CREATE_NEW_CONSOLE flag when calling createProcess, the StartupInfo structure will affect the console characteristics, and also affect the console created by the subroutocconsole. The following console characteristics can be specified:
The size of the new console form, according to the location of the character unit new console form, press the screen pixel coordinate the size of the console screen buffer, press the text and background colors of the character cells new console screen buffer Attribute new console form headline display name
If the value of StartupInfo is not specified, the system will use the default value. A subroutine can be used to determine the value of StartupInfo by calling the getStartupInfo function.
The program cannot change its own console window location, but the following functions can be used to set or get other attribute values of the StartupInfo structure.
Function Description getConsolescreenBufferInfo Gets the Size, the screen buffer size, and color properties. SetConsoleWindowInfo Change Console Forms Size SetConsolescreenBuffersize Change Console Screen Buffer Size SetConSoleTextAttribute Sets Color Properties. SetConsoletitle Set the console window title bar. GetConsoletitle gets the console window title bar. A program can be separated by calling the FreeConsole function and separated from a console created by calling AllocConsole.