Code:
#include <iostream.h>
#include <conio.h>
class TWindow
{
int Left, Top, Right, Bottom, NumWindows, TxtColour, WinColour;
char *Title;
public:
TWindow(int, int, int, int, int, int);
void Draw(void);
void SetWinSize(int, int, int, int);
void SetTitle(char *TitlePtr, int TextCol)
{strcpy(Title = new char[strlen(TitlePtr) + 1], TitlePtr);
TxtColour = TextCol;}
void SetWinColour(int Colour){WinColour = Colour;}
~TWindow(){delete []Title;}
};
TWindow::TWindow(int WinLeft = 1, int WinTop = 1, int WinRight = 80,
int WinBottom = 25 , int FontColour = WHITE,
int BackColour = BLUE)
{
strcpy(Title = new char[20], "Default Window");
Left = WinLeft;
Top = WinTop;
Right = WinRight;
Bottom = WinBottom;
TxtColour = FontColour;
WinColour = BackColour;
}
void TWindow::Draw(void)
{
int Temp;
window(Left, Top, Right, Bottom);
textbackground(WinColour);
textcolor(TxtColour);
for(int i=0; i < Bottom; i++)
for(int j=0; j < Right; j++)
cprintf(" ");
Temp = (((Right - Left) - strlen(Title)) + 1)/ 2 ;
gotoxy(++Temp, 1);
cprintf("%s", Title);
}
void TWindow::SetWinSize(int WinLeft, int WinTop, int WinRight, int WinBottom)
{
Left = WinLeft;
Top = WinTop;
Right = WinRight;
Bottom = WinBottom;
}
int main(void)
{
TWindow Win1;
Win1.Draw();
TWindow Win2(5, 5, 60, 18, YELLOW, GREEN);
Win2.Draw();
TWindow Win3(8, 8, 40, 14);
Win3.Draw();
Win1.SetWinColour(RED);
Win1.SetWinSize(10, 9, 35, 9);
Win1.SetTitle("Red Window", LIGHTGRAY);
Win1.Draw();
getchar();
return 0;
}