//**************************************
//
//INCLUDE files for :messagebox maker
//**************************************
//
class CMessageBox
{
private:
charTitle[30];
charMessage[40];
intPosX, PosY;
intWidth, Height;
intHeaderColor, BodyColor;
public:
CMessageBox();
~CMessageBox();
voidSetHeaderBody(char *, char *);
voidSetWidth(int);
voidSetHeight(int);
voidSetPosX(int);
voidSetPosY(int);
voidSetHeaderColor(int);
voidSetBodyColor(int);
friend voidPrintScreen(CMessageBox &);
char*GetHeader();
char*GetBody();
intGetWidth();
intGetHeight();
intGetPosX();
intGetPosY();
intGetHeaderColor();
intGetBodyColor();
};
CMessageBox :: CMessageBox()
{
strcpy(Title, "ERROR");
strcpy(Message, "Unknown operation");
PosX=PosY=5;
Width=40;
Height=15;
HeaderColor=1;
BodyColor=7;
}
CMessageBox :: ~CMessageBox()
{
textcolor(0);
window(1,1,80,25); clrscr();
}
void CMessageBox :: SetHeaderBody(char *head, char *body)
{
strcpy(Title, head);
strcpy(Message, body);
PosX=PosY=10;
Width=strlen(body)+4;
Height=5;
HeaderColor=11;
BodyColor=13;
}
void CMessageBox :: SetWidth(int width)
{
Width=(width>=20 && width <60)?width:20;
}
void CMessageBox :: SetHeight(int height)
{
Height=(height>=4 && height<10)?height:4;
}
void CMessageBox :: SetPosX(int x)
{
PosX=(x>=1 && x<50)?x:20;
}
void CMessageBox :: SetPosY(int y)
{
PosY=(y>=1 && y<50)?y:20;
}
void CMessageBox :: SetHeaderColor(int color)
{
HeaderColor=(color>=1 && color<=15)?color:13;
}
void CMessageBox :: SetBodyColor(int color)
{
BodyColor=(color>=1 && color<=15)?color:13;
}
void PrintScreen(CMessageBox &mb)
{
window(mb.PosX, mb.PosY, (mb.PosX+mb.Width), (mb.PosY+2)); textbackground(mb.HeaderColor);clrscr();
gotoxy(((mb.PosX+mb.Width-(strlen(mb.Title)))/2)-1,2); textcolor(WHITE);cprintf(mb.Title);
textbackground(mb.BodyColor);
window(mb.PosX, mb.PosY+3, mb.PosX+mb.Width, mb.Height);clrscr();
gotoxy(((mb.PosX+mb.Width-(strlen(mb.Message)))/2)-1, wherey()+2);
textcolor(BLACK);
cprintf(mb.Message);
}
char *CMessageBox :: GetHeader()
{
return Title;
}
char *CMessageBox :: GetBody()
{
return Message;
}
int CMessageBox :: GetWidth()
{
return Width;
}
int CMessageBox :: GetHeight()
{
return Height;
}
int CMessageBox :: GetPosX()
{
return PosX;
}
int CMessageBox :: GetPosY()
{
return PosY;
}
int CMessageBox :: GetHeaderColor()
{
return HeaderColor;
}
int CMessageBox :: GetBodyColor()
{
return BodyColor;
}
code:
#include
#include
int main()
{
CMessageBox messagebox;
PrintScreen(messagebox);
getch();
}