C语言程序设计实训_源代码

源代码在线查看: 5-3.c

软件大小: 44 K
上传用户: xiao11tian
关键词: C语言 程序设计 源代码
下载地址: 免注册下载 普通下载 VIP

相关代码

				/*5-3.c*/
				#include
				#include
				#include
				#include
				union REGS r;
				int s=0;
				int xtop,ytop,xbottom,ybottom;
				
				void drawrh(int x,int y)
				{line(x,y,x+15,y);
				 line(x+15,y-5,x+15,y+5);
				 line(x+15,y-5,x+35,y-5);
				 line(x+15,y+5,x+35,y+5);
				 line(x+35,y-5,x+35,y+5);
				 line(x+35,y,x+50,y);
				}
				void mouse(int x,int y)
				{
				line(x-5,y,x+5,y);
				line(x,y-5,x,y+5);
				}
				void read(int *x,int *y,int *mbutt,int *oldx,int *oldy)
				{
				 *oldx=*x;
				 *oldy=*y;
				 do
				 {r.x.ax=3;
				  int86(51,&r,&r);       /*产生鼠标中断*/
				  *x=r.x.cx;             /*光标当前X坐标*/
				  *y=r.x.dx;              /*光标当前Y坐标*/
				  *mbutt=r.x.bx;         /*按键状态*/
					}while(*x==*oldx&&*y==*oldy&&*mbutt==0);
				}
				void tuo(int *butt,int *mx,int *my,int *ox,int *oy)
				{
				char *p;
				while(*butt==1)
						  {
				mouse(*ox,*oy);
							 if(s==0)
							 {
							 s=1;
							 drawrh(*mx,*my);
								}
								read(mx,my,butt,ox,oy);
							drawrh(*ox,*oy);
								drawrh(*mx,*my);
							   mouse(*mx,*my);
								bar(5,5,100,25);
				  sprintf(p,"%d  %d",*mx,*my);
				outtextxy(10,10,p);
				//outtextxy(60,10,stry);
							}
				xtop=(*mx);ytop=(*my-5);
				xbottom=(*mx+50);ybottom=(*my+5);
				}
				
				void main()
				{
				int mx,my,ox,oy;
				int butt;
				char *strx,*stry;
				int gd=DETECT,gm;
				 initgraph(&gd,&gm,"c:\\bc\\bin\\bgi");
				drawrh(50,130);       /*画出要拖动的图形对象*/
				setwritemode(XOR_PUT);  /*将画线方式设为异或*/
				 r.x.ax=3;
				 int86(51,&r,&r);
				 mx=r.x.dx;
				 my=r.x.cx;
				 butt=r.x.bx;
				 //mouse(mx,my);
				 setfillstyle(1,BLACK);
				 for(;;)
				 {
				   bar(5,5,100,25);
				  sprintf(strx,"%d",mx);
					sprintf(stry,"%d",my);
				outtextxy(10,10,strx);
				outtextxy(60,10,stry);
				  read(&mx,&my,&butt,&ox,&oy);  /*读取光标当前位置*/
				  mouse(mx,my);                 /*在当前位置画出光标图形*/
				  delay(20);
				if((s==0)&&mx>50&&mx125&&my				  {
				 
				   tuo(&butt,&mx,&my,&ox,&oy);
				
				}
				if(s==1&&mx>(xtop)&&mx				  {
				 drawrh(xtop,ytop+5);
				   s=0;
				   tuo(&butt,&mx,&my,&ox,&oy);
				
				}
				mouse(ox,oy);
				mouse(mx,my);
				if(butt==2)
					{
					closegraph();
					exit(0);
					}
				}
				}
							

相关资源