c语言课程设计_菜单设计
调试环境为TC2.0或者3.0。运行这个程序需要tc提供的几个头文件。建议修改options菜单中的include目录项到tc的include的目录下(具体方法可以参见本书第一章的讲解);或者把源程序拷贝到tc目录下运行。
#include <conio.h>
#include<dos.h>
#include <graphics.h>
#include<stdio.h>
#include<stdlib.h>
/*定义一些常数*/
#define NO 0
#define YES 1
#define NONE -1
#define MAX_MENU 7/*根据情况改变可以在菜单显示的最大项*/
/*全局参数*/
int X,Y;
int Selection;
int button,x,y;
void *p;
size_t area;
/*菜单结构*/
struct MENU
{
      /*左上角*/
      int x; 
      int y;
      /*右下角*/
      int x1;
      int y1;
      unsigned char Active[MAX_MENU];/* 菜单项是否激活的标志*/
      char *head;/* 菜单的名字(可选项)*/
};
int MouseOn(struct MENU *t);
void Process();
void Xorbar(int sx,int sy,int ex,int ey,int c);
void Show();
void Hide();
void Status();
/* 通过下面的参数用户可以改变按钮的位置。*/
struct MENU File={200,110,250,130};
struct MENU Edit={295,110,345,130};
struct MENU Help={390,110,440,130};
struct MENU Close={600,10,620,30};
struct MENU Neeraj={380,300,460,315};
void main()
{
 int gd = DETECT,gm;
 
 /*初始化图形界面*/
 initgraph(&gd, &gm,"");
 Selection=NONE;
 /*是否激活菜单项,YES表示激活;NO表示取消激活*/
 for(gd=0;gd<MAX_MENU;gd++)
 {
 File.Active[gd]=YES;
 Edit.Active[gd]=YES;
 Help.Active[gd]=YES;
 Close.Active[gd]=YES;
 }
 /*菜单项的名字,用户可以修改以显示其他的名称*/
 File.head="[ File Menu ]";
 Edit.head="[ Edit Menu ]";
 Help.head="[ Help Menu ]";
 Close.head="[ Exit ]";
 /*为界面分配内存*/
 area=imagesize(0,0,150,150);
 p=malloc(area);
 
 /*没有足够的内存*/
 if(p==NULL)
 {
 closegraph();
 restorecrtmode();
 printf("Not Enough Memory !\n try to reduce the area used.\n");
 exit(1);
 }
 setfillstyle(1,7);
 bar(0,0,640,480);
 X=2;Y=2;
 /*绘制这个界面*/
 Process();
 End();
 /*关闭图形显示方式*/
 closegraph();
 printf("GUI-MENUS By Neeraj Sharma  -   n21@indiatimes.com\n");
 getch();
}
void Process()
{
 /*文件菜单项的子菜单项*/
 char *fm[]={"New","Open","Save","Save as","Exit"};
 /*编辑菜单项的子菜单项*/
 char *em[]={"Undo","Cut","Copy","Paste","Delete","Select All"};
 /*帮助菜单项的子菜单项*/
 char *hm[]={"Help Topics","About Menus"};
 
 /* 如果用户在这里改变的了菜单项的值,那么也同样需要改变在函数
    中的PullMenuDown(char *,int)值*/
 char KEY;
 /* 绘制各个菜单 */
 Win(140,100,500,140);
 /* 绘制文件菜单项 */
 DrawBtn(&File,"File");
 /* 绘制编辑菜单项 */
 DrawBtn(&Edit,"Edit");
 /* 绘制帮助菜单项*/
 DrawBtn(&Help,"Help");
 settextstyle(0,0,0);
 outtextxy(Close.x+7,Close.y+7,"x");
 Comments();
 Show();
 /* 正如下面所示用户可以激活和取消激活一个菜单项
    下面的'save as'被取消激活*/
 File.Active[3]=NO;/* Save as*/
 Edit.Active[0]=NO;/* 取消激活*/
 while(1)
 {
  if(kbhit())
  {
   KEY=getch();
   /*如果用户按下"ESC"或者"-"推出程序*/
   if(KEY==27|| KEY==45) break;
  }
  Status();
  /*如果按下鼠标左键*/
  if(button==1)
  {<
	
相关新闻>>
- 发表评论
- 
				
- 最新评论 进入详细评论页>>








