标题:[转载]基于Graphics的图形菜单程序
取消只看楼主
一笔苍穹
Rank: 1
等 级:新手上路
帖 子:640
专家分:0
注 册:2006-5-25
 问题点数:0 回复次数:1 
[转载]基于Graphics的图形菜单程序

作者:怀念晚秋
编译环境:TC + Graphics
有关Graphics的介绍参见《[C图形专区] 版序:动手搭建你的工作平台

程序简介:
一个MM写的一个 菜单程序 用的是 SVGA256.BGI 显示程序(没有的要去下载)

源码如下帖:

搜索更多相关主题的帖子: Graphics 图形 菜单 
2006-05-26 16:42
一笔苍穹
Rank: 1
等 级:新手上路
帖 子:640
专家分:0
注 册:2006-5-25
得分:0 

#include "graphics.h"
#include "dos.h"
union REGS regs;
int huge Return_SVGA256();
void setup_svga256();
void init();
void cursor();
void newxy();
int x_max=1023,y_max=767,xmin,ymin,xmax,ymax;
void *yellow,*red;
main()
{int button,xm,ym,x,y,x1=400,y1=300,row=0,size;
setup_svga256();
size=imagesize(0,0,63,33);
yellow=malloc(size);
red=malloc(size);
setfillstyle(1,37);
bar(0,0,63,33);
getimage(0,0,63,33,red);
setfillstyle(1,0);
bar(0,0,97,34);
setfillstyle(1,14);
bar(0,0,63,33);
getimage(0,0,63,33,yellow);
setfillstyle(1,0);
bar(0,0,97,34);
clrscr();
setcolor(42);
rectangle(0,0,x_max,y_max);
setfillstyle(1,42);
bar(0,0,x_max,35);
setfillstyle(1,37);
bar(1,36,x_max-1,71);
setfillstyle(1,149);
bar(1,72,x_max-1,y_max-1);
settextstyle(0,0,3);
setcolor(51);
outtextxy(10,8,"WINDOWS");
settextstyle(0,0,2);
setcolor(16);
outtextxy(10,45,"File");
outtextxy(154,45,"Edit");
outtextxy(298,45,"Tool");
outtextxy(442,45,"Abou");
outtextxy(586,45,"Quit");
init();
setwritemode(XOR_PUT);
cursor(x1,y1);
while(1)
{newxy(&x,&y,&button);
cursor(x1,y1);
cursor(x,y);
x1=x,y1=y;
if(x>10&&x<106&&y>37&&y<71)
{if(row!=0&&row!=1)
{putimage(10+(row-1)*96+(row-1)*48,37,yellow,XOR_PUT);
putimage(10+(row-1)*96+(row-1)*48,37,red,XOR_PUT);
putimage(10,37,red,XOR_PUT);
putimage(10,37,yellow,XOR_PUT);}
if(row==0)
{putimage(10,37,red,XOR_PUT);
putimage(10,37,yellow,XOR_PUT);}
row=1;
if(button==1)
{int row1=0;
setcolor(49);
rectangle(10-5,73,129,215);
setfillstyle(1,54);
bar(11-5,73,128,214);
setcolor(15);
outtextxy(10,9+72,"New");
outtextxy(10,42+72,"Open");
outtextxy(10,76+72,"Save");
outtextxy(10,110+72,"Close");
while(1)
{
newxy(&x,&y,&button);
cursor(x1,y1);
cursor(x,y);
x1=x,y1=y;
if(x>6&&x<118&&y>71&&y<108)
{if(row1!=1&&row1!=0)
{putimage(6,72+(row1-1)*36,yellow,1);
putimage(6,72,yellow,1);}
if(row1==0)
{putimage(6,72,yellow,1);}
row1=1;}
if(x>6&&x<118&&y>107&&y<143)
{if(row1!=2&&row1!=0)
{putimage(6,72+(row1-1)*36,yellow,1);
putimage(6,108,yellow,1);}
row1=2;}
if(x>6&&x<118&&y>143&&y<179)
{if(row1!=3&&row1!=0)
{putimage(6,72+(row1-1)*36,yellow,1);
putimage(6,144,yellow,1);}
row1=3;}
if(x>6&&x<118&&y>179&&y<215)
{if(row1!=4&&row1!=0)
{putimage(6,72+(row1-1)*36,yellow,1);
putimage(6,177,yellow,1);}
row1=4;}
if(x<0||x>130||y<36||y>220)
{setfillstyle(1,149);
bar(4,72,130,220);
break;}}}
}

if(x>154&&x<250&&y>37&&y<71)
{if(row!=0&&row!=2)
{putimage(10+(row-1)*96+(row-1)*48,37,red,XOR_PUT);
putimage(10+(row-1)*96+(row-1)*48,37,yellow,XOR_PUT);
putimage(154,37,red,XOR_PUT);
putimage(154,37,yellow,XOR_PUT);}
if(row==0)
{putimage(154,37,red,XOR_PUT);
putimage(154,37,yellow,XOR_PUT);}
row=2;
if(button==1)
{int row1=0;
setcolor(49);
rectangle(149,73,279,215);
setfillstyle(1,54);
bar(150,73,278,214);
setcolor(15);
outtextxy(154,9+72,"Delete");
outtextxy(154,42+72,"Amend");
outtextxy(154,76+72,"Insert");
while(1)
{
newxy(&x,&y,&button);
cursor(x1,y1);
cursor(x,y);
x1=x,y1=y;
if(x>151&&x<278&&y>71&&y<108)
{if(row1!=1&&row1!=0)
{putimage(151,72+(row1-1)*36,yellow,1);
putimage(151,72,yellow,1);}
if(row1==0)
{putimage(151,72,yellow,1);}
row1=1;}
if(x>151&&x<278&&y>107&&y<143)
{if(row1!=2&&row1!=0)
{putimage(151,72+(row1-1)*36,yellow,1);
putimage(151,108,yellow,1);}
row1=2;}
if(x>151&&x<278&&y>143&&y<179)
{if(row1!=3&&row1!=0)
{putimage(151,72+(row1-1)*36,yellow,1);
putimage(151,144,yellow,1);}
row1=3;}
if(x<130||x>280||y<36||y>220)
{setfillstyle(1,149);
bar(148,72,280,220);
break;}}}}


if(x>298&&x<394&&y>37&&y<71)
{if(row!=0&&row!=3)
{putimage(10+(row-1)*96+(row-1)*48,37,yellow,XOR_PUT);
putimage(10+(row-1)*96+(row-1)*48,37,red,XOR_PUT);
putimage(298,37,red,XOR_PUT);
putimage(298,37,yellow,XOR_PUT);}
if(row==0)
{putimage(298,37,red,XOR_PUT);
putimage(298,37,yellow,XOR_PUT);}
row=3;
if(button==1)
{int row1=0;
setcolor(49);
rectangle(292,73,428,215);
setfillstyle(1,54);
bar(293,73,427,214);
setcolor(15);
outtextxy(298,9+72,"Rubber");
outtextxy(298,42+72,"color");
while(1)
{
newxy(&x,&y,&button);
cursor(x1,y1);
cursor(x,y);
x1=x,y1=y;
if(x>298&&x<428&&y>71&&y<108)
{if(row1!=1&&row1!=0)
{putimage(298,72+(row1-1)*36,yellow,1);
putimage(298,72,yellow,1);}
if(row1==0)
{putimage(298,72,yellow,1);}
row1=1;}
if(x>298&&x<428&&y>107&&y<143)
{if(row1!=2&&row1!=0)
{putimage(298,72+(row1-1)*36,yellow,1);
putimage(298,108,yellow,1);}
row1=2;}
if(x>298&&x<428&&y>143&&y<179)
{if(row1!=3&&row1!=0)
{putimage(298,72+(row1-1)*36,yellow,1);
putimage(298,144,yellow,1);}
row1=3;}
if(x<270||x>429||y<36||y>220)
{setfillstyle(1,149);
bar(291,72,429,220);
break;}}}
}

if(x>442&&x<538&&y>37&&y<71)
{if(row!=0&&row!=4)
{putimage(10+(row-1)*96+(row-1)*48,37,yellow,XOR_PUT);
putimage(10+(row-1)*96+(row-1)*48,37,red,XOR_PUT);
putimage(442,37,red,XOR_PUT);
putimage(442,37,yellow,XOR_PUT);}
if(row==0)
{putimage(442,37,red,XOR_PUT);
putimage(442,37,yellow,XOR_PUT);}
row=4;
if(button==1)
{int row1=0;
setcolor(49);
rectangle(436,73,810,215);
setfillstyle(1,54);
bar(436,73,809,214);
setcolor(15);
outtextxy(442,9+72,"This is a menu program.");
outtextxy(442,42+72,"I hope you can acquire");
outtextxy(442,76+72,"something from this!");
while(1)
{
newxy(&x,&y,&button);
cursor(x1,y1);
cursor(x,y);
x1=x,y1=y;
if(x<410||x>811||y<36||y>220)
{setfillstyle(1,149);
bar(435,72,811,220);
break;}}}}

if(x>586&&x<682&&y>37&&y<71)
{if(row!=0&&row!=5)
{putimage(10+(row-1)*96+(row-1)*48,37,yellow,XOR_PUT);
putimage(10+(row-1)*96+(row-1)*48,37,red,XOR_PUT);
putimage(586,37,red,XOR_PUT);
putimage(586,37,yellow,XOR_PUT);}
if(row==0)
{putimage(586,37,red,XOR_PUT);
putimage(586,37,yellow,XOR_PUT);}
row=5;
if(button==1)
exit(1);}
}}


int huge Return_SVGA256()
{return(4);}

void setup_svga256(void)
{
int gm,driver = DETECT;
installuserdriver("svga256",Return_SVGA256);
initgraph(&driver,&gm,"");
}

void init()
{int retcode=0;
regs.x.ax=0;
int86(51,&regs,&regs);
retcode=regs.x.ax;
if(retcode==0)
return 0;
regs.x.ax=7;
regs.x.cx=2;
regs.x.dx=1010;
int86(51,&regs,&regs);
regs.x.ax=8;
regs.x.cx=8;
regs.x.dx=760;
int86(51,&regs,&regs);}

void cursor(int x,int y)
{int x1,x2,x3,x4,x5,x6;
x1=x+4;
x2=y+20;
x3=x+20;
x4=y+20;
x5=x1+4,x6=x2-5;
setcolor(149);
setlinestyle(0,0,3);
line(x,y,x1,x2);
line(x,y,x3,x4);
line(x1,x2,x5,x6);
line(x3,x4,x5+1,x6+1);
setcolor(48);
line(x,y,x1,x2);
line(x,y,x3,x4);
line(x1,x2,x5,x6);
line(x3,x4,x5+1,x6+1);}

void newxy(int *x,int *y,int *button)
{int xx=*x,yy=*y,but=0,xnew,ynew;
do{regs.x.ax=3;
int86(51,&regs,&regs);
xnew=regs.x.cx;
ynew=regs.x.dx;
*button=regs.x.bx;
}while(xnew==xx&&ynew==yy&&*button==but);
*x=xnew;
*y=ynew;}

2006-05-26 16:42



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-67448-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.813178 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved