Created
November 3, 2011 11:03
-
-
Save CrBoy/1336265 to your computer and use it in GitHub Desktop.
Cutility - Command-line drawing utility
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "cutility.h" | |
void gotoxy(int x, int y) | |
{ | |
static HANDLE hConsole = GetStdHandle( STD_OUTPUT_HANDLE ); | |
COORD coord={x, y}; | |
SetConsoleCursorPosition(hConsole, coord); | |
} | |
void setcolor(const char *fg, const char *bg) | |
{ | |
WORD type=0; | |
while(*fg!='\0'){ | |
switch(*fg++){ | |
case 'r': case 'R': | |
type |= FOREGROUND_RED; | |
break; | |
case 'g': case 'G': | |
type |= FOREGROUND_GREEN; | |
break; | |
case 'b': case 'B': | |
type |= FOREGROUND_BLUE; | |
break; | |
case '+': | |
type |= FOREGROUND_INTENSITY; | |
break; | |
} | |
} | |
while(*bg!='\0'){ | |
switch(*bg++){ | |
case 'r': case 'R': | |
type |= BACKGROUND_RED; | |
break; | |
case 'g': case 'G': | |
type |= BACKGROUND_GREEN; | |
break; | |
case 'b': case 'B': | |
type |= BACKGROUND_BLUE; | |
break; | |
case '+': | |
type |= BACKGROUND_INTENSITY; | |
break; | |
} | |
} | |
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),type); | |
} | |
void msgbox(const char *msg) | |
{ | |
int temp; | |
gotoxy(21,8); | |
printf("╭────────────────╮"); | |
gotoxy(21,9); | |
printf("│"); | |
setcolor("rgb+", "b"); | |
printf(" 訊息 "); | |
setcolor("rgb", ""); | |
printf("│"); | |
gotoxy(21, 10); | |
printf("├────────────────┤"); | |
gotoxy(21,11); | |
printf("│"); | |
setcolor("", "rgb"); | |
printf("%32s", msg); | |
setcolor("rgb", ""); | |
printf("│"); | |
gotoxy(21, 12); | |
printf("╰────────────────╯"); | |
temp = getch(); | |
if(temp==224 || temp==0){getch();} // some special keys send 2 ASCII values | |
gotoxy(0,24); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******************************************************************************* | |
Author: CrBoy | |
Cutility is a command line drawing utility for Windows which is originally made | |
on 2006. This stuff is revised and released on November, 2011. | |
These code are very simple and suitable for studying. For productivity, using | |
curses may be a good idea. | |
*******************************************************************************/ | |
#ifndef __CUTILITY_H__ | |
#define __CUTILITY_H__ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <windows.h> | |
#include <conio.h> | |
#define clrscr() system("cls") | |
#ifdef __cplusplus | |
extern "C"{ | |
#endif | |
void gotoxy(int x, int y); // Move the cursor to specified position | |
void setcolor(const char *fg, const char *bg); // Usage: setcolor("rgb+", "rgb+"); | |
void msgbox(const char *msg); // Display message in a message box | |
#ifdef __cplusplus | |
} | |
#endif | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment