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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
#include <iostream>
#include <vector>
#include "conio.h"
#include "windows.h"
using namespace std;
typedef struct _Rect{
int left;
int top;
int right;
int bottom;
}Rect;
void gotoxy(int x, int y)
{
static HANDLE hStdout = NULL;
COORD coord;
coord.X = x;
coord.Y = y;
if(!hStdout)
{
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
}
SetConsoleCursorPosition(hStdout,coord);
}
void DrawRect(Rect rect)
{
int x1=rect.left, x2=rect.right, y1=rect.top, y2=rect.bottom;
int i;
//horisontella sidor
for(i=0; i<x2-x1; i++)
{
gotoxy(x1+i, y1);
cout<<(char)196;
}
for(i=0; i<x2-x1; i++)
{
gotoxy(x1+i, y2);
cout<<(char)196;
}
//vertikala sidor
for(i=0; i<y2-y1; i++)
{
gotoxy(x1, y1+i);
cout<<(char)179;
}
for(i=0; i<y2-y1; i++)
{
gotoxy(x2, y1+i);
cout<<(char)179;
}
gotoxy(x1, y1);
cout<< (char)218; //övre vänster hörn
gotoxy(x2, y1);
cout<< (char)191; //övre högra hörn
gotoxy(x1, y2);
cout<< (char)192; //nedre vänsta hörn
gotoxy(x2, y2);
cout<< (char)217; //nedre högra hörn
}
int main()
{
Rect aRect={30, 3, 49, 14};
//int width=aRect.right-aRect.left, heigth=aRect.bottom-aRect.top;
DrawRect(aRect);
cout << endl << endl;
return 0;
}
|