Computer Science Canada

creating window using graphics

Author:  rickdragon [ Tue Jan 13, 2004 9:27 pm ]
Post subject:  creating window using graphics

// creating window

#include<iostream.h>
#include<conio.h>
#include<alloc.h>
#include<stdlib.h>
class window1
{
int left,top,right,bottom;
char attr;
char *oldno;
void drawbox(void);
void drawchar(char,int);
public:
void init(int,int,int,int,char);
void reinit();
};
void window1::init(int l,int t,int r,int b,char at)
{
int size = (r-l+1)*(b-t+1)*2;
oldno = (char *)malloc(size);
if(oldno==NULL)
gettext(l,t,r,b,oldno);
left=l;top=t;bottom=b;right=r;attr=at;
drawbox();
window(l+1,t+1,r-1,b-1);
textattr(attr);
clrscr();
cprintf("Welcome to window class"); // display message
}
void window1::reinit()
{
puttext(left,top,right,bottom,oldno);
free(oldno);
}
void window1::drawbox()
{
gotoxy(left,top);drawchar('*',1);
gotoxy(left+1,top);drawchar('*',(right-left-1));
gotoxy(right,top);drawchar('*',1);
for(int i=1;i<=bottom-top-1;i++)
{
gotoxy(left,top+i);drawchar('*',1);
gotoxy(right,top+i);
drawchar('*',1);
}
gotoxy(left,bottom);drawchar('*',1);
gotoxy(left+1,bottom);drawchar('*',(right-left-1));
gotoxy(right,bottom);drawchar('*',1);
}
void window1::drawchar(char ch,int times)
{
for(int i=0;i<times;i++)
{
putch(ch);
}
}
void main()
{
clrscr();
window1 first,second;
first.init(10,5,70,20,0x3f);
getch();
/*
window(1,1,80,25);
second.init(20,7,50,10,0x4f);
getch();
second.reinit();
getch();
*/
}

------ if u like my work plz reply me

Author:  McKenzie [ Tue Jan 13, 2004 10:24 pm ]
Post subject: 

Rick, a few suggestions.
1. Inform everyone which compiler your code is for.
2. Attach your code rather than posting it as body text.
3. Give some context to your work (i.e. why you are posting, why you feel this is good code for people to see)

Good stuff though.

Author:  G-lant [ Sun Feb 29, 2004 2:53 pm ]
Post subject: 

I dont have a C++ compiler so I cant run it and see how good/bad it is

but........... you should have made it a exe for us with no compiler

Shocked


: