C Language Console window graphics interface programming six cursor operations

Source: Internet
Author: User

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

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.