今天下午下个菜单程序试试看,主要是要用鼠标控制的,现在还没写完,发现有一些问题值得大家讨论下,也希望用c写过鼠标控制菜单程序的朋友一起来探讨下.首先是鼠标假如没按键而位置在菜单选向上的时候,大家觉得这个时候应该在菜单主标题这里显示什么样的效果呢?是用rectangle画一个框还是添加背景颜色呢?同样在菜单选向里也应该显示什么样的效果.第二个问题是假如有滚屏的话你们觉得是把一大块保存下来,还是一行行保存好呢?希望写过类似程序的朋友以及想写这个程序的朋友提点意见吧,谢谢.
/*email: milo_zy@sohu.com*/
#include "stdio.h"
#include "dos.h"
#include "stdlib.h"
#include "graphics.h"
#define WAITING 0xff00
#define LEFTPRESS 0xff01
#define LEFTCLICK 0xff10
#define LEFTDRAG 0xff19
#define MOUSEMOVE 0xff08
int Keystate;/*这里的开始都与鼠标有关*/
int MouseExist;
int MouseButton;
int MouseX;
int MouseY;
void *save;/*储存一块地方用的*/
struct time now;/*这里开始的变量都是时间有关*/
int old,new;
char ss[10];
struct caidan/*用来检验是否菜单已经打开*/
{
int on;/*菜单打开1,否则0*/
char ml[5][20];/*子目录*/
}c[4];
/*鼠标光标外形定义*/
typedef struct
{
unsigned int shape[32];
char hotx;
char hoty;
}SHAPE;
/*箭头型*/
SHAPE ARROW={
{
0x3fff,0x1fff,0x0fff,0x07ff,
0x03ff,0x01ff,0x00ff,0x007f,
0x003f,0x00ff,0x01ff,0x10ff,
0x30ff,0xf87f,0xf87f,0xfc3f,
0x0000,0x7c00,0x6000,0x7000,
0x7800,0x7c00,0x7e00,0x7f00,
0x7f80,0x7e00,0x7c00,0x4600,
0x0600,0x0300,0x0300,0x0180
},
0,0,
};
void TimeDelay(unsigned long microsec); /*延时函数 传入微秒数*/
void MouseOn();/*鼠标光标显示*/
void MouseOff();/*鼠标光标掩示*/
void MouseReset();/*鼠标状态值初始化*/
void MouseSetXY(int x,int y);/*设置鼠标当前位置*/
int LeftPress();/*获取鼠标按下键的信息*/
void MouseGetXY();/*获取鼠标当前位置*/
void prtime();/*输出时间的函数*/
void cdbegain();/*菜单各参数初始状态*/
void Init();/*开始画面*/
void delcd();/*先把已有的菜单删除了*/
void drawcdml(int n);/*输出菜单中的具体内容*/
void drawcd(int l,int u,int r,int d,int n);/*画菜单*/
void mouseleft();/*左键按下画菜单具体内容*/
void Move();/*测试过程*/
void main(void)
{
Init();
Move();
MouseOff();
closegraph();
}
void TimeDelay(unsigned long microsec) /*延时函数 传入微秒数*/
{
union REGS r;
r.h.ah=0x86;
r.x.cx=microsec>>16;
r.x.dx=microsec;
int86(0x15,&r,&r);
}
void MouseOn()/*鼠标光标显示*/
{
_AX=0x01;
geninterrupt(0x33);
}
void MouseOff()/*鼠标光标掩示*/
{
_AX=0x02;
geninterrupt(0x33);
}
void MouseReset()/*鼠标状态值初始化*/
{
_AX=0x00;
geninterrupt(0x33);
}
void MouseSetXY(int x,int y)/*设置鼠标当前位置*/
{
_CX=x;
_DX=y;
_AX=0x04;
geninterrupt(0x33);
}
int LeftPress()/*获取鼠标按下键的信息*/
{
_AX=0x03;
geninterrupt(0x33);
return(_BX&1);
}
void MouseGetXY()/*获取鼠标当前位置*/
{
_AX=0x03;
geninterrupt(0x33);
MouseX=_CX;
MouseY=_DX;
}
void prtime()/*输出时间的函数*/
{
gettime(&now);
new=now.ti_sec;
if(abs(new-old)>=1)
{
setfillstyle(SOLID_FILL,7);/*把原来的老时间给去除*/
bar(500,8,620,18);
old=new;
sprintf(ss,"%02d:%02d:%02d",now.ti_hour,now.ti_min,now.ti_sec);
setcolor(0);
outtextxy(500,8,ss);
}
}
void cdbegain()/*菜单各参数初始状态*/
{int i;
for(i=0;i<4;i++)/*所有菜单都已经关闭*/
c[i].on=0;
strcpy(c[0].ml[0],"Open");/*各菜单的各选项*/
strcpy(c[0].ml[1],"New");
strcpy(c[0].ml[2],"Save");
strcpy(c[0].ml[3],"Save as");
strcpy(c[0].ml[4],"Exit");
strcpy(c[1].ml[0],"Undo");
strcpy(c[1].ml[1],"Cut");
strcpy(c[1].ml[2],"Copy");
strcpy(c[1].ml[3],"Paste");
strcpy(c[1].ml[4],"Properties");
strcpy(c[2].ml[0],"Styles");
strcpy(c[2].ml[1],"L Icons");
strcpy(c[2].ml[2],"S Icons");
strcpy(c[2].ml[3],"\0");
strcpy(c[2].ml[4],"\0");
strcpy(c[3].ml[0],"Textcolor");
strcpy(c[3].ml[1],"Backcolor");
strcpy(c[3].ml[2],"Clearscr");
strcpy(c[3].ml[3],"\0");
strcpy(c[3].ml[4],"\0");
}
void Init()/*开始画面*/
{
int gd=DETECT,gm;
unsigned size;
initgraph(&gd,&gm,"c:\\tc");
gettime(&now);/*获取时间*/
old=now.ti_sec;
prtime();/*输出时间*/
setcolor(15);
size=imagesize(40,21,140,130);
save=malloc(size);/*开辟存储空间*/
setbkcolor(BLUE);/*以下是开始界面初始化*/
rectangle(2,25,638,470);
outtextxy(10,40,"Because of c,I make a lot of friends.");/*测试菜单不覆盖原来的东西*/
outtextxy(10,60,"Because of c,I'm afraid I can do ......");
outtextxy(10,80,"Thank you for all the friends in the c classroom.");
outtextxy(400,110,"milo_zy");
outtextxy(390,130,"2003.9.20");
setfillstyle(SOLID_FILL,7);
bar(0,0,640,20);
setcolor(RED);
outtextxy(50,8,"File");
outtextxy(150,8,"Edit");
outtextxy(250,8,"Tool");
outtextxy(350,8,"Color");
cdbegain();/*菜单各参数初始状态*/
MouseOn();
}
void delcd()/*先把已有的菜单删除了*/
{
int i;
for(i=0;i<4;i++)
if(c[i].on==1)
{
if(i==0)/*开始恢复原来的样子*/
putimage(40,21,save,COPY_PUT);
else if(i==1)
putimage(140,21,save,COPY_PUT);
else if(i==2)
putimage(240,21,save,COPY_PUT);
else
putimage(340,21,save,COPY_PUT);
c[i].on=0;
break;
}
}
void drawcdml(int n)/*输出菜单中的具体内容*/
{
int i,j=30,k;
switch(n)
{
case 0:k=50;break;
case 1:k=150;break;
case 2:k=250;break;
case 3:k=350;break;
}
setcolor(6);
for(i=0;i<5;i++)
{
outtextxy(k,j,c[n].ml[i]);/*第一个菜单*/
j+=20;
}
}
void drawcd(int l,int u,int r,int d,int n)/*画菜单*/
{ /*前面4个参数是上下左右位置,最后一个参数是第几个菜单目录*/
getimage(l-10,u,r+60,d,save);
setfillstyle(SOLID_FILL,7);
bar(l-10,u,r+60,d);
setcolor(4);
rectangle(l-8,u+1,r+58,d-2);
if(n==1)/*这里开始用n判定输入哪个菜单的选项*/
drawcdml(0);
else if(n==2)
drawcdml(1);
else if(n==3)
drawcdml(2);
else drawcdml(3);
}
void mouseleft()/*左键按下画菜单具体内容*/
{
delcd();/*先
把已有的菜单删除了*/
if(MouseX>=50&&MouseX<=80)/*第1个菜单*/
{
c[0].on=1;
drawcd(50,21,80,130,1);
}
else if(MouseX>=150&&MouseX<=180)/*第2个菜单*/
{
c[1].on=1;
drawcd(150,21,180,130,2);
}
else if(MouseX>=250&&MouseX<=280)/*第3个菜单*/
{
c[2].on=1;
drawcd(250,21,280,130,3);
}
else if(MouseX>=350&&MouseX<=390)/*第4个菜单*/
{
c[3].on=1;
drawcd(350,21,380,130,4);
}
}
void Move()/*测试过程*/
{int x,y;/*为了让鼠标先离原位就先将他们离开前的坐标记下*/
while(!kbhit())
{
prtime();/*输出时间*/
if(LeftPress())/*按左键盘了*/
{
MouseGetXY();
if(MouseY>=5&&MouseY<=15)/*在菜单栏上*/
{
MouseOff();
x=MouseX;y=MouseY;
MouseSetXY(200,200);
mouseleft();
MouseSetXY(x,y);
MouseOn();
}
else
{
MouseOff();
delcd();/*删除原有的菜单*/
MouseOn();
}
prtime();
TimeDelay(500000);/*按了鼠标一次以后就停些时间才可以按*/
}
}
free(save);
}
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |