Console dual-buffering technology, console Buffering
Introduction
The dual-buffer technology is mainly used in plotting. However, leveraging the principles of the dual-buffer technology, you can experience the advantages of your console programs better, such as the console game you have compiled, you often need to constantly refresh the screen, which may cause very serious problems-screen flashing! This greatly reduces the user experience (although there are no users, it does not prevent us from pursuing perfection ~), Double Buffering can eliminate this flicker.
Technical Principle of Double Buffering on the console:
Background: what you see on the black interface is displayed in the "screen buffer". The buffer we can see is called "Current (active) screen buffer ", we can create other buffers or operate on them, but they are invisible.
Principles:
Create a screen buffer (invisible at this time)
Write the content you want to display once in the newly created screen buffer.
Set the buffer to the current buffer (visible)
----> Why is the problem solved?
Explanation: Suppose you print a series of 11111111111111111111111111111111111111111111111111111 messages on the screen. If you use loop printf ("1"), the actual situation is that the output is 1, 11, and then 111 first on the screen ,, and so on, we can see the write process. In this process, we will feel flashes. If so many 1 s are displayed, there will be no flashes, the write process of the dual buffer bar is placed in the invisible screen buffer. The flash problem is solved when it is displayed at one time.
Specific implementation:
--------------------------------- Create a screen buffer --------------------------------------
------------------------------------ Option: Hide the cursor ---------------------------------------
------------------------------- Write what you want to display ---------------------------------------
WriteConsole (hNewConsole, "Here is the string", strlen (p), NULL, NULL );
------------------------------------------ Activate --------------------------------------------------