A small text box for console based applications. It can be used as a help dialog box or showing the tips, hints in a game or as an information box. Its length and height can be changed.
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 | #include <stdio.h> #include <conio.h> #include <string.h> #define TITLE_LENGTH 20 #define TEXT_LENGTH 20 void make_textbox(struct textbox); void draw_box(int left, int top,int width, int height); struct textbox { int left; int top; int width; int height; char title[TITLE_LENGTH+30]; char text[TEXT_LENGTH+30]; }; void main(void) { struct textbox aboutbox={10,3,62,15,"About Textbox Program CopyRight (c) 1999 by Muhammad Saqib."}; struct textbox errorbox={20,7,40,9,"Warning Press Esc to Exit!"}; _setcursortype(_NOCURSOR); textbackground(BLACK); clrscr(); make_textbox(aboutbox); getch(); textbackground(BLACK); clrscr(); make_textbox(errorbox); getch(); _setcursortype(_NOCURSOR); } void make_textbox(struct textbox box) { textbackground(BLUE); textcolor(WHITE); draw_box(box.left,box.top,box.width,box.height); gotoxy(box.left+(box.width-strlen(box.title))/2-1,box.top); cputs(box.title); gotoxy(box.left+(box.width-strlen(box.text))/2-1,box.top+(box.height-1)/2); cputs(box.text); } void draw_box(int left, int top, int width, int height) { int j; char string[81]; window(left,top,left+width-1,top+height-1); clrscr(); window(left,top,left+width-1,top+height); for(j=1;j<width-1;j++) string[j]='\xC4'; string[width]='\0'; string[0]='\xDA'; string[width-1]='\xBF'; gotoxy(1,1); cputs(string); string[0]='\xC0'; string[width-1]='\xD9'; gotoxy(1, height); cputs(string); for(j=2;j<height;j++) { gotoxy(1,j); putch('\xB3'); gotoxy(width, j); putch('\xB3'); } window(1,1,80,25); } |