#ifndef __WINDOWS_H #define __WINDOWS_H #ifndef __cplusplus #error Must use C++ for the type WINDOWS. #endif #include #include #include #include #include #define wincolor newcolor(4,100,100,160) #define Begin do{ #define End }while(1); typedef char *string; void mov(int y,char ex[68]); int MsgType(int x1,int y1,int x2,int choice); int MsgBox(string ex,string ex1,string ex2); static int mov_p = 0,mov_z = 0,mov_i = 1; /****************************** boolean ********************************/ typedef enum {false,true} boolean; /************************* Creating New Color *****************************/ int newcolor(int number,int red,int green,int blue) { if(number != 7 && number != 8 && number != 15) { struct palettetype no; getpalette(&no); setrgbpalette(no.colors[number],red,green,blue); } return number; } /*****************************************************************/ /* $ Refer time(). */ string TextOut(int x,int y,string pt, ...) { string buf; va_list b; va_start(b,pt); vsprintf(buf,pt,b); outtextxy(x,y,buf); va_end(b); return buf; } /*************************** Time And Date ********************************/ string getTime(int x,int y) { string a; struct time t; gettime(&t); a = TextOut(x,y,"%02d:%02d:%02d",t.ti_hour,t.ti_min,t.ti_sec); return a; } string getDate(int x,int y) { string a; struct date d; getdate(&d); a = TextOut(x,y,"%02d:%02d:%04d",d.da_day,d.da_mon,d.da_year); return a; } /************************Initialization************************/ /* $ This is a base class. */ class Option { protected : int px,py,sx,sy,bkg,col,ftype,fsize,fhv,fontcol; public: void setLocation(int setx = 0,int sety = 0) { px = setx ; py = sety ; } void setSize(int sizex,int sizey) { sx = sizex; sy = sizey; } void setBkColor(int x) { bkg = x; } void setColor(int x) { col = x; } void setFont(int x,int y,int z) { ftype = x; fhv = y; fsize = z; } void setFontColor(int x) { fontcol = x; } }; /****************************Creating Button***************************/ /* $ Button(..)Is the constructor. $ add() Display The Button. $ Pressed() detect the current position of mouse and gives the press effect. */ class Button:public Option { string z; int updep,dndep; public: Button(string what,int dn = 0,int up = 15) { z = what; // dn and up denote the depth px = 0,py = 0; // of button sx = 100,sy = 20; col = 256; ftype = 0; fhv = 0; fsize = 1; fontcol = 0; updep = up; dndep = dn; } boolean add(void) { setlinestyle(0,1,2); settextstyle(0,0,1); setcolor(updep); rectangle(px,py,px+sx-1,py+sy-1); setcolor(dndep); rectangle(px+2,py+2,px+sx,py+sy); rectangle(px+2,py+1,px+sx+1,py+sy+1); setfillstyle(1,col); if(col == 256) setfillstyle(1,getpixel(px-1,py-1)); bar(px+1,py+1,px+sx-1,py+sy-1); text(fontcol); setlinestyle(0,1,1); return true; } boolean clicked(void) { if(pxm.x&&pym.y) { hidemouse(); cbutton(); delay(200); add(); delay(200); showmouse(); return true; } return false; } void text(int color) { setcolor(color); settextstyle(ftype,fhv,fsize); settextjustify(CENTER_TEXT,CENTER_TEXT); outtextxy(px+(sx/2),py+1+(sy/2),z); settextjustify(LEFT_TEXT,RIGHT_TEXT); } void mouse(int f,int i) { if(pxm.x&&pym.y) text(f); else text(i); } private:int cbutton(void); }; //private Members of class Button int Button::cbutton(void) { setlinestyle(0,1,2); settextstyle(0,0,1); setcolor(dndep); rectangle(px,py,px+sx,py+sy); setcolor(updep); rectangle(px+1,py+1,px+sx,py+sy); setcolor(col); if(col == 256) setcolor(getpixel(px-1,py-1)); rectangle(px+1,py+1,px+sx+1,py+sy+1); setfillstyle(1,col); if(col == 256) setfillstyle(1,getpixel(px-1,py-1)); bar(px+1,py+1,px+sx-1,py+sy-1); text(fontcol); return 0; } /* $ This is used for message detecting. */ enum _M_S_G { WD_CLOSE = 1, WD_MAX, WD_MIN, WD_KBHIT, WD_LBUTTONDOWN, WD_RBUTTONDOWN, WD_LBUTTONUP, WD_RBUTTONUP, WD_DBCLK }; typedef enum _M_S_G MSG; /**************************** Creating Window ****************************/ class Window:virtual public Option { Button *clo,*max,*min; int bt,bcol,btext,upbut,dnbut; string ch; /* $ CREAT (..) initialize this class. */ public: boolean creat(string what,int x = 0,int y = 7,int z = 0,int p = 0,int q = 15) { wincolor; // x -> type 0f button(max = 2,min = 1,..) px = 0,py = 0; // y -> colour of buttons sx = getmaxx(); // z -> color of button text sy = getmaxy(); // p -> depth of button (lower) bkg = 0; // q -> depth of button (upper) ch = what; bt = x; bcol = y; btext = z; upbut = p; dnbut = q; col = 4; ftype = 0; fhv = 0; fsize = 1; fontcol = 0; return true; } /* $ The Showwindow() Displays windo. */ string Showwindow(void) { setlinestyle(0,1,1); setlinestyle(0,1,2); setcolor(8); rectangle(px+2,py+2,px+sx-2,py+sy-2); line(px,py+27,px+sx,py+27); setcolor(15); rectangle(px,py,px+sx,py+sy); line(px,py+25,px+sx,py+25); setcolor(7); rectangle(px+1,py+1,px+sx-1,py+sy-1); line(px+1,py+26,px+sx-1,py+26); setfillstyle(1,col); bar(px+1,py+3,px+sx-1,py+24); setfillstyle(1,bkg); bar(px+3,py+28,px+sx-3,py+sy-3); setcolor(fontcol); settextstyle(ftype,fhv,fsize); outtextxy(px+8,py+10,ch); winbut(); return ch; } friend int GetMsg(MSG *a1,Window *w,string a2,string a3); private:int winbut(void); int close(void); }; //private Members of class Window int Window::winbut(void) { clo = new Button("x",upbut,dnbut); clo -> setSize(13,13); clo -> setLocation(px+sx-19,py+6); clo -> setColor(bcol); clo -> setFontColor(btext); clo -> add(); if(bt == 1 || bt == 2) { max = new Button("",upbut,dnbut); max -> setSize(13,13); max -> setLocation(px+sx-36,py+6); max -> setColor(bcol); max -> setFontColor(btext); max -> add(); if(bcol != 7 && bt < 2) setcolor(7); else if(bcol == 7 && bt < 2) setcolor(8); else if(bt == 2) setcolor(btext); rectangle(px+sx-33,py+9,px+sx-26,py+16); rectangle(px+sx-33,py+10,px+sx-26,py+16); min = new Button("_",upbut,dnbut); min -> setSize(13,13); min -> setLocation(px+sx-51,py+6); min -> setFontColor(btext); min -> setColor(bcol); min -> add(); } return 0; } int Window::close(void) { int ret = 0; if(clo -> clicked()) ret = 1; else if(bt == 1 || bt == 2) { if(min -> clicked()) ret = 3; } if(bt == 2) { if(max -> clicked()) { hidemouse(); rectangle(px+sx-33,py+9,px+sx-26,py+16); rectangle(px+sx-33,py+10,px+sx-26,py+16); showmouse(); delay(200); ret = 2; } } return ret; } /************************** MESSAGE HANDLER *************************/ /* String a2 for Normal Charectors. String a3 for Arrow Key Page up ect. *a1 Is the message handler. *w Is the window handler. */ int GetMsg(MSG *a1,Window *w,string a2,string a3) { int a; *a2 = 0; *a3 = 0; if(kbhit()) { *a1 = WD_KBHIT; *a2 = getch(); if(*a2 == 0) *a3 = getch(); return 0; } getmouse(); if((m.b & 1) == 1) { m.lcheck = 1; *a1 = WD_LBUTTONDOWN; return 0; } else if((m.b & 2) == 2) { m.rcheck = 1; *a1 = WD_RBUTTONDOWN; return 0; } else if(m.lcheck == 1) { m.lcheck = 0; moveonly(m.x,m.y,m.x,m.y); for(int I = 0;I < 6 && m.b == 0;I++) { delay(30); getmouse(); } moveonly(0,0,getmaxx(),getmaxy()); if((m.b & 1) == 1) { *a1 = WD_DBCLK; return 0; } else if((a = w -> close()) != 0) { *a1 = (enum _M_S_G) (a); return 0; } else { *a1 = WD_LBUTTONUP; return 0; } } else if(m.rcheck == 1) { m.rcheck = 0; *a1 = WD_RBUTTONUP; return 0; } return 1; } /**************************** Creating TextField **************************/ class TextField:public Option { int mi,i; char p[30];int _p_ass; public: TextField(int i1) { mi = i1; i = 0; px = 0; py = 0; _p_ass = 0; strcpy(p,""); } char* getText() { return p; } void add(void) { setfillstyle(1,15); bar(px+2,py+2,px+1+((mi+1) * 9),py + 16); setcolor(0); rectangle(px+1,py+1,px+2+((mi+1) * 9),py+17); } /* $ This helps to check the click in the edit box. $ *tt 'll have a value 1 when Enter key is pressed 2 when tab key is pressed and 'll break the loop in both cases. */ boolean clicked(int *tt) { boolean ret = false; int txt; if(m.x > px && m.x < px + 3 + ((mi + 1) * 9) && m.y > py && m.y < py + 20) ret = tclicked(&txt); *tt = txt; return ret; } /* $ This is used for initialization,jump(on press of tab key) etc. */ boolean tclicked(int *txt) { char a; string buf; *txt = 0; hidemouse(); delay(100); getmouse(); settextstyle(0,0,1); setcolor(0); outtextxy(px + 3 + (i * 9),py + 7,"_"); showmouse(); do { getmouse(); if(kbhit()) { a = getch(); hidemouse(); if(a != 0 || (i == 0 && a == 8)); { setcolor(15); outtextxy(px + 3 + (i * 9),py + 7,"_"); } switch(a) { case 0: getch(); break; case 8: if(i == 0) { sound(1000); delay(50); nosound(); setcolor(0); outtextxy(px+3+(i*9),py+7,"_"); break; } i--; setfillstyle(1,15); bar(px+3+(i*9),py+5,px+3+((i+1)*9),py+14); setcolor(0); outtextxy(px+3+(i*9),py+7,"_"); p[i] = NULL; break; case 13: setcolor(15); outtextxy(px + 3 + (i * 9),py + 7,"_"); *txt = 1; showmouse(); return true; case 9: setcolor(15); outtextxy(px + 3 + (i * 9),py + 7,"_"); *txt = 2; showmouse(); return true; default: if(i < mi) { sprintf(buf,"%c",a); setcolor(0); if(_p_ass == 0) outtextxy(px + 4 + (i * 9),py + 6,buf); else outtextxy(px + 4 + (i * 9),py + 6,"*"); strcat(p,buf); i++; } setcolor(0); outtextxy(px+3+(i*9),py+7,"_"); } showmouse(); } } while((m.b & 3) == 0 || (m.x > px && m.x < px + 3 + ((mi + 1) * 9) && m.y > py && m.y < py+20)); setcolor(15); outtextxy(px + 3 + (i * 9),py + 7,"_"); return true; } void pass(void) { _p_ass = 1; } }; /************************** Creating CheckBox ****************************/ class CheckBox:public Option { string ch; boolean selec; public: CheckBox(string what) { px = 0,py = 0; ch = what; ftype = 0; fhv = 0; fsize = 1; fontcol = 0; selec = false; } boolean add(void) { setcolor(0); rectangle(px,py,px+8,py+8); setfillstyle(1,15); bar(px+1,py+1,px+7,py+7); setcolor(fontcol); settextstyle(ftype,fhv,fsize); outtextxy(px+12,py+1,ch); return true; } boolean clicked() { if(m.x > px && m.x < px+8 && m.y > py && m.y < py+8) { setSelected(selec); selec = (boolean)!selec; return true; } else return false; } boolean isSelected() { return selec; } boolean setSelected(boolean a) { hidemouse(); settextstyle(0,0,2); setcolor(a * 15); rectangle(px+3,py+3,px+5,py+5); rectangle(px+3,py+3,px+4,py+4); showmouse(); delay(50); return true; } }; /*****************************PASSWORD FUNTION****************************/ /* $ string pass collect the password. */ boolean password(string pass) { Button *ok; TextField *t; class _pass:public Window { public: _pass() { creat("password"); setLocation(getmaxx()/2-100,getmaxy()/2-60); setSize(200,100); setBkColor(4); setColor(9); Showwindow(); t = new TextField(16); t->setLocation(getmaxx()/2-77,getmaxy()/2-20); t->pass(); t->add(); ok = new Button("OK"); ok -> setSize(30,20); ok -> setLocation(300,250); ok -> setColor(4); ok -> setFontColor(8); ok -> add(); settextstyle(8,0,5); setcolor(4); settextjustify(CENTER_TEXT,CENTER_TEXT); outtextxy(getmaxx()/2 + 10,115,"TURBO C++"); outtextxy(getmaxx()/2 + 10,325,"VERSION 3.0"); settextjustify(LEFT_TEXT,RIGHT_TEXT); rectangle(70,50,580,430); rectangle(68,48,582,432); } }; string buf; cleardevice(); _pass *ww; newcolor(0,8,8,90); MSG msg; int ent; char ext,ext1; ww = new _pass(); showmouse(); Begin while(GetMsg(&msg,ww,&ext,&ext1)) { setcolor(YELLOW); mov(380," Designed By Muhammad Ajmal P 1st Year E.I. CITV "); ok -> mouse(0,8); } switch(msg) { case WD_CLOSE: closegraph(); exit(0); break; case WD_KBHIT: if(ext == 27) { closegraph(); exit(0); } break; case WD_LBUTTONUP: if(t->clicked(&ent)); if(ok->clicked() == 1 || ent == 1) { if(strcmp(pass,t->getText()) == 0) { strcpy(t->getText(),""); newcolor(0,0,0,0); return true; } else { MsgType(250,200,150,NULL); MsgBox("Password","","INVALID LOGIN"); closegraph(); exit(0); } } break; } End } /*******************************MOVEING DISPLAY FUNTION*********************/ movdsp(int i,int y,char ex[68]) { int p,q; for(q = 0;q < i;q++) { p = 56 - i + q; if(i < 98 && p >= 24) { setfillstyle(1,0); bar(p * 8,y - 2,(p+1) * 8,y + 15); settextstyle(0,0,1); TextOut(p * 8,y,"%c",ex[q]); } } return 0; } void mov(int y,char ex[68]) { mov_p = (mov_z +(mov_i / 200)); if(mov_p > mov_z) { movdsp(mov_p,y,ex); mov_z++; } if(mov_p > 97) { mov_p = 0; mov_z = 0; } if(mov_i > 200) mov_i = 0; mov_i++; delay(1); } /******************************* Msg Box ***********************************/ #define OK 1 #define YESNO 2 #define TRY 3 static int M_sgch = 1, M_sgx1 = getmaxx()/2 - 100, M_sgy1 = getmaxy()/2 - 60, M_sgx2 = 0, M_sgy2; int MsgType(int x1,int y1,int x2,int choice) { M_sgx1 = x1; M_sgy1 = y1; M_sgx2 = x2; M_sgy2 = 5; M_sgch = choice; return 0; } int MsgBox(string ex,string ex1,string ex2,string ex3,string ex4,string ex5) { int half = M_sgx1 + (M_sgx2/2); string buf; Button *ok,*yes,*no; hidemouse(); class msgwin:public Window { public: msgwin() { creat(ex); setLocation(M_sgx1,M_sgy1); setSize(M_sgx2,55 + (17 * M_sgy2)); setBkColor(4); setColor(9); setFontColor(14); Showwindow(); if(M_sgch == 1 || M_sgch == 3) { if(M_sgch == 1) ok = new Button("OK"); else if(M_sgch == 3) ok = new Button("Try Again"); ok -> setColor(7); ok -> setLocation(half - 40,M_sgy1 + (M_sgy2 * 17) + 30); ok -> setSize(80,17); ok -> add(); } if(M_sgch == YESNO) { yes = new Button("YES"); yes -> setColor(7); yes -> setLocation(half - 55,M_sgy1 + (M_sgy2 * 17) + 30); yes -> setSize(40,17); yes -> add(); no = new Button("NO"); no -> setColor(7); no -> setLocation(half + 15,M_sgy1 + (M_sgy2 * 17) + 30); no -> setSize(40,17); no -> add(); } settextstyle(0,0,1); setcolor(BLACK); settextjustify(CENTER_TEXT,CENTER_TEXT); outtextxy(half,M_sgy1 + 35,ex1); outtextxy(half,M_sgy1 + 52,ex2); outtextxy(half,M_sgy1 + 69,ex3); outtextxy(half,M_sgy1 + 86,ex4); outtextxy(half,M_sgy1 + 101,ex5); settextjustify(LEFT_TEXT,RIGHT_TEXT); } }; msgwin *m; MSG msg; m = new msgwin(); showmouse(); Begin while(GetMsg(&msg,m,0,0)) { } switch(msg) { case WD_CLOSE: return 0; case WD_LBUTTONUP: if(ok -> clicked() && (M_sgch == OK || M_sgch == TRY)) return OK; else if(M_sgch == YESNO && yes -> clicked()) return 1; else if(M_sgch == YESNO && no -> clicked()) return 2; break; } End } int MsgBox(string ex,string ex1,string ex2,string ex3,string ex4) { if(M_sgy2 > 4) M_sgy2 = 4; int I = MsgBox(ex,ex1,ex2,ex3,ex4,""); return I; } int MsgBox(string ex,string ex1,string ex2,string ex3) { if(M_sgy2 > 3) M_sgy2 = 3; int I = MsgBox(ex,ex1,ex2,ex3,""); return I; } int MsgBox(string ex,string ex1,string ex2) { if(M_sgy2 > 2) M_sgy2 = 2; int I = MsgBox(ex,ex1,ex2,""); return I; } int MsgBox(string ex,string ex1) { M_sgy2 = 1; int I = MsgBox(ex,ex1,""); return I; } #endif /*************************************************************************** Designed By Muhammad Ajmal P ajumalp@gmail.com ***************************************************************************/