
admin
admin
-
个人空间
- 组别:管理员
- 性别:
- 来自:
- 积分:352
- 帖子:345
- 注册:
2006-10-19
|
在DOS窗口中用鼠标的程序(trubo C for windows 集成实验环境共享版 编译通过)
/* Note:Your choice is C IDE */ #include "stdio.h" #include<dos.h> #include<graphics.h> #define ture 1 #define false 0 int mouse_installed=false; void qp() { clrscr(); } void noise() { sound(10000); delay(2000); nosound(); } /* --------------------------------------------------------------------------------------------------- */ /* ------------------------------------------鼠标功能区-------------------------------------- */ /* ---------------------------------------------------------------------------------------------------- */ int InitMouse(void) { union REGS r; r.x.ax=0; int86(0x33,&r,&r); if(r.x.ax==0xffff) mouse_installed=ture; else mouse_installed=false; return(r.x.bx); } int ShowMouse(void) { union REGS r; if(mouse_installed==false) return (-1); r.x.ax=0x0001; int86(0x33,&r,&r); return(0); } int HideMouse(void) { union REGS r; if(mouse_installed==false) return (-1); r.x.ax=0x0002; int86(0x33,&r,&r); return(0); } int GetMouseXY(int *x,int *y) { union REGS r; if(mouse_installed==false) return (-1); r.x.ax=0x0003; int86(0x33,&r,&r); *x=r.x.cx; *y=r.x.dx; return(0); } int SetMouseXY(int x,int y) { union REGS r; if(mouse_installed==false) return (-1); r.x.ax=0x0004; r.x.cx=x; r.x.dx=y; int86(0x33,&r,&r); return(0); } int GetPressInfo(int button) { union REGS r; if(mouse_installed==false) return (-1); r.x.ax=0x0005; r.x.bx=button; int86(0x33,&r,&r); return(r.x.bx); } int GetReleaseInfo(int button) { union REGS r; if(mouse_installed==false) return (-1); r.x.ax=0x0006; r.x.bx=button; int86(0x33,&r,&r); return(r.x.bx); } int SetXRange(int min,int max) { union REGS r; if(mouse_installed==false) return (-1); r.x.ax=0x0007; r.x.cx=min; r.x.dx=max; int86(0x33,&r,&r); return(0); } int SetYRange(int min,int max) { union REGS r; if(mouse_installed==false) return (-1); r.x.ax=0x0008; r.x.cx=min; r.x.dx=max; int86(0x33,&r,&r); return(0); } /* -------------------------------------------------------------------------------------------------- */ /* ------------------------------------------学生功能区------------------------------------------------- */ /* --------------------------------------------------------------------------------------------------- */ /* 定义结构 */ struct student{ int stunum; char stuname[20]; char stusex[20]; int stuage; }; static struct student stu[49]; static int flg[49]; /* ------------------------------------------添加学生------------------------------------------------- */ void addstu() { int opx,x,y,xo,i; int mouse_buttons; struct student newstu; opx=1; gotoxy(13,21); printf("Input Number:") ; gotoxy(13,22); printf("Input Name :") ; gotoxy(13,23); printf("Input Sex :") ; gotoxy(13,24); printf("Input Age :") ; gotoxy(13,25); printf("ADDSTUDENT :") ; mouse_buttons=InitMouse(); while(1) { xo=y; GetMouseXY(&x,&y); if(y>xo) { if(opx<5) { setfillstyle(1,0); bar(216,(opx*18+340),226,(opx*18+358)); noise(); ++opx; } } if(y<xo) { if(opx>1) { setfillstyle(1,0); bar(216,(opx*18+340),226,(opx*18+358)); noise(); --opx; } } setfillstyle(1,RED); bar(216,(opx*18+340),226,(opx*18+358)); if(GetPressInfo(0)==1) { setfillstyle(1,WHITE); bar(1,1,24,24); if(opx==1) { gotoxy(30,21); scanf("%d",&newstu.stunum ); } if(opx==2) { gotoxy(30,22); scanf("%s",newstu.stuname ); } if(opx==3) { gotoxy(30,23); scanf("%s",newstu.stusex ); } if(opx==4) { gotoxy(30,24); scanf("%d",&newstu.stuage ); } if(opx==5) { for(i=0;i<49;i++) { if(flg !=7) { stu=newstu; flg=7; setfillstyle(1,0); bar(216,(6*18+340),226,(6*18+358)); return; } } } } if(GetReleaseInfo(0)==1) { setfillstyle(1,0); bar(1,1,24,24); } if(GetPressInfo(mouse_buttons-1)==1) { setfillstyle(1,WHITE); bar(26,1,49,24); return; } if(GetReleaseInfo(mouse_buttons-1)==1) { setfillstyle(1,0); bar(26,1,49,24); } gotoxy(40,3); printf("Mouse X:%d",x); gotoxy(40,4); printf("Mouse Y:%d",y); } } /* ----------------------------------------显示学生------------------------------------------------- */ void showstu() { int i; int hh; struct student bufstu; hh=9; for(i=0;i<49;i++) { if(flg==7) { bufstu=stu; gotoxy(15,hh); printf("%d",bufstu.stunum); gotoxy(28,hh); printf("%s",bufstu.stuname) ; gotoxy(41,hh); printf("%s",bufstu.stusex) ; gotoxy(54,hh); printf("%d",bufstu.stuage) ; hh++; } } } /* ------------------------------------------删除学生------------------------------------------------- */ void deletestu() { int opx,x,y,xo,i,order,AGE; struct student dbufstu; int mouse_buttons; opx=1; gotoxy(26,21); printf("Input Number:") ; gotoxy(26,22); printf("Input Age :") ; mouse_buttons=InitMouse(); while(1) { xo=y; GetMouseXY(&x,&y); if(y>xo) { if(opx<2) { setfillstyle(1,0); bar(306,(opx*18+340),316,(opx*18+358)); noise(); ++opx; } } if(y<xo) { if(opx>1) {
setfillstyle(1,0); bar(306,(opx*18+340),316,(opx*18+358)); noise(); --opx; } } setfillstyle(1,RED); bar(306,(opx*18+340),316,(opx*18+358)); if(GetPressInfo(0)==1) { setfillstyle(1,WHITE); bar(1,1,24,24); if(opx==1) { gotoxy(41,21); scanf("%d",&order); for( i=0;i<49;i++) { if(stu.stunum==order) { flg=0; stu.stunum=-1; gotoxy(20,3); printf("SUCCESS"); return; } } gotoxy(20,3); printf("FAILED"); return; } if(opx==2) { gotoxy(41,22); scanf("%d",&AGE); for( i=0;i<49;i++) { if(stu.stuage==AGE) { flg=0; } } gotoxy(20,3); printf("FAILED"); return; } } if(GetReleaseInfo(0)==1) { setfillstyle(1,0); bar(1,1,24,24); } if(GetPressInfo(mouse_buttons-1)==1) { setfillstyle(1,WHITE); bar(26,1,49,24); return; } if(GetReleaseInfo(mouse_buttons-1)==1) { setfillstyle(1,0); bar(26,1,49,24); } gotoxy(40,3); printf("Mouse X:%d",x); gotoxy(40,4); printf("Mouse Y:%d",y); } } /* ------------------------------------------学生排序------------------------------------------------- */ void taxis() { int opx,x,y,xo,i,j,AGE,f; struct student buf; int mouse_buttons; opx=1; gotoxy(39,21); printf("ByNumber:") ; gotoxy(39,22); printf("ByAge :") ; mouse_buttons=InitMouse(); while(1) { xo=y; GetMouseXY(&x,&y); if(y>xo) { if(opx<2) { setfillstyle(1,0); bar(386,(opx*18+340),396,(opx*18+358)); noise(); ++opx; } } if(y<xo) { if(opx>1) {
setfillstyle(1,0); bar(386,(opx*18+340),396,(opx*18+358)); noise(); --opx; } } setfillstyle(1,RED); bar(386,(opx*18+340),396,(opx*18+358)); if(GetPressInfo(0)==1) { setfillstyle; bar(1,1,24,24); if(opx==1) { for(i=0;i<49;i++) { f=i; for(j=i+1;j<49;j++) { if(stu[j].stunum>stu[f].stunum) { f=j; } } buf=stu[f]; stu[f]=stu; stu=buf; } return; } if(opx==2) { for(i=0;i<49;i++) { f=i; for(j=i+1;j<49;j++) { if(stu[j].stuage>stu[f].stuage) { f=j; } } buf=stu[f]; stu[f]=stu; stu=buf; } return; } } if(GetReleaseInfo(0)==1) { setfillstyle(1,0); bar(1,1,24,24); } if(GetPressInfo(mouse_buttons-1)==1) { setfillstyle(1,WHITE); bar(26,1,49,24); return; } if(GetReleaseInfo(mouse_buttons-1)==1) { setfillstyle(1,0); bar(26,1,49,24); } gotoxy(40,3); printf("Mouse X:%d",x); gotoxy(40,4); printf("Mouse Y:%d",y); } } /* -------------------------------------------------------------------------------------------------- */ /* ------------------------------------------图形界面区------------------------------------------------- */ /* --------------------------------------------------------------------------------------------------- */ void startcolourface()/* ------------------------------------------初始化屏幕------------------------------------------------- 程序*/ { int dr=DETECT; int mode; char pd; initgraph(&dr,&mode,""); } void clickadd()/* ------------------点击添加学生---------------------- */ { showstu(); } void clickdel()/* ------------------点击删除学生---------------------- */ { deletestu(); } void showmainface()/* ------------------------------------------显示主程序界面------------------------------------------------- */ { rectangle(100,100,500,300); line(100,130,500,130); line(200,100,200,130); line(300,100,300,130); line(400,100,400,130); gotoxy(15,7); printf("Number"); gotoxy(28,7); printf("Name") ; gotoxy(41,7); printf("Sex") ; gotoxy(54,7); printf("Age") ; } void otherop() { rectangle(100,305,500,330); line(200,310,200,330); line(300,310,300,330); line(400,310,400,330); gotoxy(15,18); printf("AddStudent"); gotoxy(28,18); printf("DeleteStu") ; gotoxy(41,18); printf("Taxis") ; gotoxy(54,18); printf("Exit") ; rectangle(0,0,50,100); line(0,25,50,25); line(25,0,25,25); } void mouseoption()/* ------------------------------------------显示鼠标界面------------------------------------------------- */ { int opx,x,y,xo; int mouse_buttons; opx=1; mouse_buttons=InitMouse(); while(1) { showmainface(); showstu(); otherop(); xo=x; GetMouseXY(&x,&y); if(x>xo) { if(opx<4) { setfillstyle(1,0); bar((opx*100),333,(opx*100+100),343); noise(); ++opx; } } if(x<xo) { if(opx>1) {
setfillstyle(1,0); bar((opx*100),333,(opx*100+100),343); noise(); --opx; } } setfillstyle(1,RED); bar((opx*100),333,(opx*100+100),343); if(GetPressInfo(0)==1) { setfillstyle(1,WHITE); bar(1,1,24,24); if(opx==1) { addstu(); qp(); continue; } if(opx==2) { deletestu(); qp(); continue; } if(opx==3) { taxis(); qp(); continue; } if(opx==4) { break; } } if(GetReleaseInfo(0)==1) { setfillstyle(1,0); bar(1,1,24,24); } if(GetPressInfo(mouse_buttons-1)==1) { setfillstyle(1,WHITE); bar(26,1,49,24); } if(GetReleaseInfo(mouse_buttons-1)==1) { setfillstyle(1,0); bar(26,1,49,24); } gotoxy(40,3); printf("Mouse X:%d",x); gotoxy(40,4); printf("Mouse Y:%d",y); } } /* --------------------------------------------------------------------------------------------------------------- */ /* ------------------------------------------程序入口点------------------------------------------------- */ /* -------------------------------------------------------------------------------------------------------------------*/ main() { int a; struct student stu1[]={{1,"lili","girl",19},{7,"lilei","boy",15},{5,"tom","boy",22},{4,"david","boy",18},{3,"jim","boy",20},{6,"lucy","girl",18},{2,"xiaohong","girl",17}}; for(a=0;a<7;a++) { stu[a]=stu1[a]; flg[a]=7; } startcolourface(); gotoxy(27,7); printf("Turbo C Student System") ; gotoxy(24,10); printf("author : liaojiao") ; gotoxy(24,12); printf("MyWebsite : http://www.jococ.com") ; gotoxy(24,14); printf("Press Any Key To Continue....") ; InitMouse(); ShowMouse(); getch(); qp(); HideMouse(); mouseoption(); }
 admin 最后编辑于 2008-08-22 20:23:10
|