-
Notifications
You must be signed in to change notification settings - Fork 6
/
JR_Cursor.c
72 lines (64 loc) · 1.96 KB
/
JR_Cursor.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* JR_Cursor.c (1.0)
* Console光标的操作
*
* By Eric-JR Chen
* diamont1001@163.com
* 2011-2-16
*/
#include "JR_Cursor.h"
#include <windows.h>
/* 将光标移到指定位置 */
void JR_SetCursor(int x, int y){
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos = {x, y};
SetConsoleCursorPosition(hOut, pos);
}
/* 将光标移到左上角 */
void JR_SetCursorStart(){
JR_SetCursor(0, 0);
}
/* 将光标向右移动N列 */
void JR_SetCursorRight(int n){
COORD pos= {0, 0};
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
PCONSOLE_SCREEN_BUFFER_INFO cinfo = malloc(sizeof(PCONSOLE_SCREEN_BUFFER_INFO));
GetConsoleScreenBufferInfo(hOut, cinfo);
pos.X = cinfo->dwCursorPosition.X + n;
pos.Y = cinfo->dwCursorPosition.Y;
SetConsoleCursorPosition(hOut, pos);
free(cinfo);
}
/* 将光标向左移动N列 */
void JR_SetCursorLeft(int n){
COORD pos= {0, 0};
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
PCONSOLE_SCREEN_BUFFER_INFO cinfo = malloc(sizeof(PCONSOLE_SCREEN_BUFFER_INFO));
GetConsoleScreenBufferInfo(hOut, cinfo);
pos.X = cinfo->dwCursorPosition.X - n;
pos.Y = cinfo->dwCursorPosition.Y;
SetConsoleCursorPosition(hOut, pos);
free(cinfo);
}
/* 将光标向上移动N行 */
void JR_SetCursorUp(int n){
COORD pos= {0, 0};
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
PCONSOLE_SCREEN_BUFFER_INFO cinfo = malloc(sizeof(PCONSOLE_SCREEN_BUFFER_INFO));
GetConsoleScreenBufferInfo(hOut, cinfo);
pos.X = cinfo->dwCursorPosition.X;
pos.Y = cinfo->dwCursorPosition.Y - n;
SetConsoleCursorPosition(hOut, pos);
free(cinfo);
}
/* 将光标向下移动N行 */
void JR_SetCursorDown(int n){
COORD pos= {0, 0};
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
PCONSOLE_SCREEN_BUFFER_INFO cinfo = malloc(sizeof(PCONSOLE_SCREEN_BUFFER_INFO));
GetConsoleScreenBufferInfo(hOut, cinfo);
pos.X = cinfo->dwCursorPosition.X;
pos.Y = cinfo->dwCursorPosition.Y + n;
SetConsoleCursorPosition(hOut, pos);
free(cinfo);
}