📄 menu2.c
字号:
size=imagesize(mn->coor[0],mn->coor[1],mn->coor[2],mn->coor[3]);
if(NULL==(MenuImageBuf=(unsigned char *)farmalloc(size)))
{
clearviewport();
outtextxy(100,100,"Out of memory!");
outtextxy(100,110,"Press any key...");
getch();
return 1;
}
getimage(mn->coor[0],mn->coor[1],mn->coor[2],mn->coor[3],MenuImageBuf);
setcolor(AllColors[MenuEdge]);
setfillstyle(SOLID_FILL,AllColors[MenuInGround]);
Bar_3d(mn->coor[0],mn->coor[1]+1,mn->coor[2],mn->coor[3],1,1);
for(i=0;i<mn->itemnum;i++)
{
if(i==mn->select)
In_Active_SubMenuItem(ord,i,1);
else
{
setcolor(AllColors[MenuInItem]);
outtextxy(mn->itemdispxy[i*2]+1,mn->itemdispxy[i*2+1],mn->itemname[i]);
}
}
return 0;
}
static void Exit_Menu(int ord)
{
MENUTYPE *mn=&SubMenu[ord];
if(MenuImageBuf)
{
putimage(mn->coor[0],mn->coor[1],MenuImageBuf,COPY_PUT);
farfree(MenuImageBuf);
}
}
void In_Active_MainMenuItem(int select, char In_Active)
{
MENUTYPE *tp=&MainMenu;
int start,end,bot,top;
start=tp->itemcoor[select*4]+8;
top=tp->itemcoor[select*4+1]+2;
end=tp->itemcoor[select*4+2]-8;
bot=tp->itemcoor[select*4+3]-2;
if(In_Active==0)
{
setfillstyle(SOLID_FILL,AllColors[MenuInGround]);
bar(start,top,end,bot);
setcolor(AllColors[MenuInItem]);
setcolor(AllColors[MenuInItem]);
line(tp->itemdispxy[select*2]-1,tp->itemdispxy[select*2+1]+texth,tp->itemdispxy[select*2]+textw,tp->itemdispxy[select*2+1]+texth);
outtextxy(tp->itemdispxy[select*2],tp->itemdispxy[select*2+1],tp->itemname[select]);
}
else
{
setfillstyle(SOLID_FILL,AllColors[MenuActiveGround]);
Bar_3d(start,top+1,end,bot-1,1,0);
setfillstyle(1,GREEN);
bar(start+1,top+1,end-1,bot-1);
setcolor(LIGHTRED);
line(tp->itemdispxy[select*2]-1,tp->itemdispxy[select*2+1]+texth,tp->itemdispxy [select*2] +textw,tp->itemdispxy[select*2+1]+texth);
setcolor(AllColors[MenuActiveItem]);
outtextxy(tp->itemdispxy[select*2],tp->itemdispxy[select*2+1],tp->itemname[select]);
}
}
void In_Active_SubMenuItem(int ord,int select,char In_Active)
{
MENUTYPE *tp=&SubMenu[ord];
int start,end,bot,top;
start=tp->itemcoor[select*4]+2;
top=tp->itemcoor[select*4+1]+1;
end=tp->itemcoor[select*4+2]-2;
bot=tp->itemcoor[select*4+3]-1;
if(In_Active==0)
{
setfillstyle(SOLID_FILL,AllColors[MenuInGround]);
bar(start,top,end,bot+1);
setcolor(AllColors[MenuInItem]);
outtextxy(tp->itemdispxy[select*2],tp->itemdispxy[select*2+1],tp->itemname[select]);
}
else
{
Bar_3d(start,top,end,bot+1,1,0);
setfillstyle(SOLID_FILL,AllColors[MenuActiveGround]);
bar(start,top+1,end,bot);
setcolor(AllColors[MenuActiveItem]);
outtextxy(tp->itemdispxy[select*2],tp->itemdispxy[select*2+1],tp->itemname[select]);
}
}
void Initial_Graphics(void)
{
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "");
errorcode = graphresult();
if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
Good_Bye("Graphics error.","Try again!!");
}
}
int Get_Key(void)
{
int key;
key=bioskey(0);
if(key==F1)
Message_Box("Please make Help file...");
else if(key<<8)
{
key=key&0x00ff;
if(isalpha(key))
key=toupper(key);
}
return key;
}
static void Get_Item_Count(char * *s,int *count,int *len,int *maxlen)
{
int i,j;
for((*maxlen)=0,(*len)=0,i=0;s[i]!=NULL;i++)
{
j=strlen(s[i]);
(*len)+=j;
if(j>(*maxlen))(*maxlen)=j;
}
(*count)=i;
}
void About(void)
{
int MidX,MidY,x1,y1,x2,y2,size;
void *Buffer;
MidX=(WindowMaxX-WindowMinX)/2;
MidY=(WindowMaxY-WindowMinY)/2;
x1=MidX-90; x2=MidX+90; y1=MidY-100; y2=MidY+100;
size=imagesize(x1,y1,x2,y2);
if((Buffer=malloc(size))==NULL)
{
outtextxy(100,100,"Out of memory! Press any key to continue.");
getch();
}
else
{
getimage(x1,y1,x2,y2,Buffer);
setfillstyle(SOLID_FILL,BLUE);
bar(x1,y1,x2-9,y2-9);
setfillstyle(SOLID_FILL,BLACK);
bar(x1+8,y2-8,x2,y2); bar(x2-8,y1+8,x2,y2);
setcolor(GREEN);
settextjustify(CENTER_TEXT,CENTER_TEXT);
outtextxy(MidX-4,MidY-60,"GRAPHICS MENU DEMO");
outtextxy(MidX-4,MidY-40,"PROGRAM");
getch();
putimage(x1,y1,Buffer,COPY_PUT);
free(Buffer);
settextjustify(LEFT_TEXT,TOP_TEXT);
}
}
void Message_Box(char *Message)
{
int MidX,MidY,x1,y1,x2,y2,size,Len;
void *Buffer;
MidX=(WindowMaxX-WindowMinX)/2;
MidY=(WindowMaxY-WindowMinY)/2;
Len=8*(strlen(Message)+1)/2;
x1=MidX-Len-5*8;
x2=MidX+Len+5*8;
y1=MidY-50;
y2=MidY+50;
size=imagesize(x1,y1,x2,y2);
if((Buffer=malloc(size))==NULL)
{
outtextxy(100,100,"Out of memory! Press any key to continue.");
getch();
}
else
{
getimage(x1,y1,x2,y2,Buffer);
setfillstyle(SOLID_FILL,CYAN);
bar(x1,y1,x2-13,y2-13);
setfillstyle(SOLID_FILL,BLACK);
bar(x1+12,y2-12,x2,y2);
bar(x2-12,y1+12,x2,y2);
setcolor(YELLOW);
settextjustify(CENTER_TEXT,CENTER_TEXT);
outtextxy(MidX,MidY-20,Message);
setfillstyle(SOLID_FILL, LIGHTRED);
bar(MidX-3*8,MidY+16,MidX+3*8,MidY+34);
setcolor(YELLOW);
outtextxy(MidX,MidY+26,"OK");
getch();
putimage(x1,y1,Buffer,COPY_PUT);
free(Buffer);
settextjustify(LEFT_TEXT,TOP_TEXT);
}
}
void Good_Bye(char *pcInf1,char *pcInf2)
{
int f;
clrscr();
window(23,6,53,12);
textbackground(LIGHTBLUE);
clrscr();
highvideo();
textcolor(LIGHTRED);
gotoxy(12,3);
cprintf(pcInf1);
gotoxy(8,5);
textcolor(YELLOW);
cprintf(pcInf2);
window(1,1,80,25);
for (f=1;f<14;f++)
printf("\n");
for(f=400;f<800;f+=100)
{
sound(f);
delay(100);
}
nosound();
exit(0);
}
int Exit_Program(char *Message)
{
int MidX,MidY,x1,y1,x2,y2,size,Len;
int key1,key2,pos;
void *Buffer;
MidX=(WindowMaxX-WindowMinX)/2;
MidY=(WindowMaxY-WindowMinY)/2;
Len=8*(strlen(Message)+1)/2;
x1=MidX-Len-5*8;
x2=MidX+Len+5*8;
y1=MidY-50;
y2=MidY+50;
size=imagesize(x1,y1,x2,y2);
if((Buffer=malloc(size))==NULL)
{
outtextxy(100,100,"Out of memory! Press any key to continue.");
getch();
}
else
{
getimage(x1,y1,x2,y2,Buffer);
setfillstyle(SOLID_FILL,BLUE);
bar(x1,y1,x2-13,y2-13);
setfillstyle(SOLID_FILL,BLACK);
bar(x1+12,y2-12,x2,y2);
bar(x2-12,y1+12,x2,y2);
setcolor(YELLOW);
settextjustify(CENTER_TEXT,CENTER_TEXT);
outtextxy(MidX,MidY-20,Message);
setfillstyle(SOLID_FILL, GREEN);
bar(MidX-63,MidY+16,MidX-35,MidY+34);
setcolor(WHITE);
outtextxy(MidX-50,MidY+26,"Yes");
outtextxy(MidX+50,MidY+26,"No");
while((key1=getch())!=13)
{
key2=key1=getch();
if(key1==0)
key2=getch();
if(key2==77)
{
pos=1;
setfillstyle(SOLID_FILL, BLUE);
bar(MidX-63,MidY+16,MidX-35,MidY+34);
setcolor(WHITE);
outtextxy(MidX-50,MidY+26,"Yes");
setfillstyle(SOLID_FILL, GREEN);
bar(MidX+35,MidY+16,MidX+68,MidY+34);
setcolor(YELLOW);
outtextxy(MidX+50,MidY+26,"No");
}
else if(key2==75)
{
pos=0;
setfillstyle(SOLID_FILL, BLUE);
bar(MidX+35,MidY+16,MidX+68,MidY+34);
setcolor(WHITE);
outtextxy(MidX+50,MidY+26,"No");
setfillstyle(SOLID_FILL, GREEN);
bar(MidX-63,MidY+16,MidX-35,MidY+34);
setcolor(YELLOW);
outtextxy(MidX-50,MidY+26,"Yes");
}
}
putimage(x1,y1,Buffer,COPY_PUT);
free(Buffer);
settextjustify(LEFT_TEXT,TOP_TEXT);
}
return(pos);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -