#include <conio.h>
#include"win_mous.cpp"// Must include for Win & mouse functions#define DRAW 2
#define PUSH 1
#define UNPUSH 0
//--------------------------------------------------------------------------int mx,my,button;
void wmouse();
int check_pos(int cx,int cy,int cx1,int cy1);
void DrawMbox(int xx,int yy,char *e);
int Ebox(char *e);
//--------------------------------------------------------------------------void main()
{
int ox,oy;
G();
setfillstyle(1,3);
bar(0,0,640,480);
showmouse();
Ebox("Move me around !");
getch();
closegraph();
}
//--------------------------------------------------------------------------void wmouse() // stops continue looping
{
int ox,oy;
ox=mx;oy=my;
while(ox==mx && oy==my && button==1)
getmouse(&button,&mx,&my);
}
//--------------------------------------------------------------------------int check_pos(int cx,int cy,int cx1,int cy1)
{
int flag;
flag=0;
if(mx>=cx && mx<=cx1 && my>=cy && my<=cy1) flag=1;
return flag;
}
//--------------------------------------------------------------------------void DrawMbox(int xx,int yy,char *e)
{
int t;
Win("Message Box",xx+1,yy+1,xx+272,yy+119,1);
// setcolor(0);// rectangle(xx,yy,xx+273,yy+120);
setfillstyle(1,0);
fillellipse(xx+36,yy+58,15,15);
setfillstyle(1,12);
fillellipse(xx+33,yy+55,15,15);
setcolor(15);
for(t=0;t<=3;t++)
{
line(xx+26,yy+47+t,xx+42,yy+59+t);
line(xx+42,yy+47+t,xx+26,yy+59+t);
}
Button("Ok",xx+110,yy+90,xx+160,yy+110,DRAW);
setcolor(0);
settextstyle(0,0,0);
outtextxy(xx+68,yy+55,e);
}
//--------------------------------------------------------------------------int Ebox(char *e)
{
int tx,ty,a,b;
// text="Message Box or Error Box";
hidemouse();
tx=177;ty=70;
DrawMbox(tx,ty,e);
showmouse();
while(1)
{
if(kbhit()) break;
showmouse();
getmouse(&button,&mx,&my);
if((button & 1)==1)
{
if(check_pos(tx+110,ty+90,tx+160,ty+110))//ok
{
Button("",tx+110,ty+90,tx+160,ty+110,PUSH);
while((button & 1)==1)
getmouse(&button,&mx,&my);
Button("",tx+110,ty+90,tx+160,ty+110,UNPUSH);
hidemouse();
setfillstyle(1,3);// clear win
bar(0,0,640,480);
setcolor(1);
outtextxy(260,200,"Press any key");
showmouse();
return(1);
}
if(check_pos(tx+4,ty,tx+252,ty+20))// click on top blue strip
{
a=mx-tx;
b=my-ty;
setcolor(15);
setlinestyle(1,1,1);
setwritemode(XOR_PUT);
getmouse(&button,&mx,&my);
while((button & 1)==1)
{
getmouse(&button,&mx,&my);
tx=mx-a;
ty=my-b;
hidemouse();
rectangle(tx+1,ty+1,tx+272,ty+119);
showmouse();
wmouse();
hidemouse();
rectangle(tx+1,ty+1,tx+272,ty+119);
showmouse();
}
setlinestyle(0,0,0);
setwritemode(COPY_PUT);
hidemouse();
setfillstyle(1,3);
bar(0,0,640,480);
DrawMbox(tx,ty,e);
showmouse();
}
}
while((button & 1)==1)
getmouse(&button,&mx,&my);
}
showmouse();
return 1;
}