The position of the cursor in the console window reflects the insertion position of the current text input, and the Windows API function allows us to change the position of the cursor at will, and here is a description of the API for this control cursor position.
BOOL setconsolecursorposition ( //Set cursor position
HANDLE hconsoleoutput, //Handle
COORD dwcursorposition // coordinates
); Returns a value other than 0 if the function call succeeds
Not only the position of the cursor, the cursor information we can also use some API functions to set, the following describes the cursor information structure has been obtained and set the cursor information API functions, as follows:
typedef struct _CONSOLE_CURSOR_INFO //cursor information structure
{
DWORD dwsize; Cursor size, range is 1~100
BOOL bvisible; Indicates whether the cursor is visible, and true indicates that Console_cursor_info is visible
}, *pconsole_cursor_info;
BOOL Getconsolecursorinfo ( //Get cursor information
HANDLE hconsoleoutput, //Handle
Pconsole_cursor_info Lpconsolecursorinfo //cursor information, note that this is a pointer type
);
BOOL Setconsolecursorinfo ( //Set CURSOR information
HANDLE hconsoleoutput, //handle
const CONSOLE_CURSOR_INFO * Lpconsolecursorinfo //cursor information
);
This column more highlights: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/C/
The following example program demonstrates the use of the above function
#include <stdio.h>
#include <Windows.h>
#include <conio.h>
#include <stdlib.h>
int main ()
{
HANDLE handle_out = GetStdHandle (std_output_handle); Obtain the standard output device handle
console_cursor_info CCI; Defines the cursor information structure body
getconsolecursorinfo (handle_out, &cci); Obtains the current cursor information
_getch ();
Cci.dwsize = 1; Set the cursor size to 1
setconsolecursorinfo (handle_out, &cci);
_getch ();
Cci.dwsize = m; Set the cursor size to
setconsolecursorinfo (Handle_out, &cci);
_getch ();
Cci.dwsize = m; Set the cursor size to
setconsolecursorinfo (Handle_out, &cci);
_getch ();
Cci.bvisible = false; Sets the cursor to be invisible
setconsolecursorinfo (handle_out, &cci);
_getch ();
return 0;
}