基于VS 2010的文本菜单系统,理论上最大可以实现1~255个菜单级数和目录数
全部源码下载(整个工程文件):
menu-systemV1.0.rar
(1002.01 KB, 下载次数: 29)
部分源程序预览:
- //---------------------------------------------------//
- //产品:多级菜单程序
- //作者:詹磊
- //版本:v1.0
- //说明:本程序仅供测试使用,在创建链表时出现错误将产生未知后果
- //修改历史:1、7/30 创建
- // 2、7/31 添加自动计算菜单目录信息功能
- // 3、8/12 代码整理
- //功能描述:理论上可以实现255级树形单列文本菜;
- // 单每个菜单最大目录数为255个;
- // 通过定义MaxDisplayNumber来设置每面菜单显示的目录数;
- //运行环境:VC2010
- //---------------------------------------------------//
- #include "..\Include\menu.h" /*菜单头文件*/
- //--主菜单--//
- MenuInfo mainMenu; //菜单结构体
- char MeunName[]="主菜单"; //菜单名字表
- //--一级菜单--//
- MenuInfo Clock,Calendar,Music,Radio,Games,Set,System; //菜单结构体
- char *mainMenuSubdirectory[7]={"时钟","日历","音乐","收音","游戏","设置","系统"}; //菜单名字表
- //--二级菜单--//
- MenuInfo SetClock,SetDate,SetAlarm,SetSystem; //菜单结构体
- char *SetSubdirectory[4]={"时间","日期","闹钟","系统"}; //菜单名字表
- //--三级菜单--//
- MenuInfo SetSecond,SetMinute,SetHour; //菜单结构体
- char *SetClockSubdirectory[3]={"秒","分","时"}; //菜单名字表
- MenuInfo SetYear,SetMonth,SetDay,SetWeek; //菜单结构体
- char *SetDateSubdirectory[4]={"年","月","日","星期"}; //菜单名字表
- MenuInfo SetAlarmSecond,SetAlarmMinute,SetAlarmHour; //菜单结构体
- char *SetAlarmSubdirectory[3]={"秒","分","时"}; //菜单名字表
- //-------------------------------------------//
- //函数名:创建菜单反向链式表函数
- //入口:MenuInfo *pM:菜单子目录的链式表头
- //出口:Void
- //功能:*pM必须为链式表头,否则会造成目录缺项
- //-------------------------------------------//
- void makeReversChainTable(MenuInfo *pM)
- {
- MenuInfo *tempM;
- pM->last=mNULL;
- pM->meunStatus=mNULL;
- pM->pFunction=fNULL;
- if(pM->next==mNULL)
- {
- return;
- }
- while(pM->next!=mNULL)
- {
- pM->meunStatus=mNULL;
- pM->pFunction=fNULL;
- tempM=pM->next;
- tempM->last=pM;
- pM=pM->next;
- }
- }
- //-------------------------------------------//
- //函数名:创建菜单父节点函数
- //入口:MenuInfo *pParentM:父节点结构体
- // MenuInfo *pM:菜单子目录的链式表头
- //出口:Void
- //功能:*pM必须为链式表头,否则会造成目录缺项
- //-------------------------------------------//
- void makeParentNode(MenuInfo *pParentM,MenuInfo *pM)
- {
- if(pM->last!=mNULL)
- return;
- else
- {
- pParentM->meunStatus=pM;
- while(pM->next!=mNULL)
- {
- pM->parentMenus=pParentM;
- pM=pM->next;
- }
- pM->parentMenus=pParentM;
- }
- }
- //-------------------------------------------//
- //函数名:创建菜单目录信息函数
- //入口:MenuInfo *pM:菜单子目录的链式表头
- //出口:Void
- //功能:*pM必须为链式表头,否则会造成未知后果
- //-------------------------------------------//
- void makeDirectoryNumber(MenuInfo *pM)
- {
- UINT8 i=1;
- if((pM->last!=mNULL)||(pM->parentMenus==mNULL))
- return ;
- else
- {
- while(pM->next!=mNULL)
- {
- pM->serialNumber=i;
- pM=pM->next;
- i++;
- }
- pM->parentMenus->directoryNumber=pM->serialNumber=i;
- }
- }
- //-------------------------------------------//
- //函数名:获取菜单名字函数
- //入口:char **pChar:菜单名字所在的数组的指针
- // MenuInfo *pM:菜单子目录的链式表头
- //出口:Void
- //功能:*pM必须为链式表头,否则会造成未知后果
- //-------------------------------------------//
- void getMenuName(char **pChar,MenuInfo *pM)
- {
- UINT8 i;
- i=0;
- if(pM->last!=mNULL)
- return;
- else
- {
- while(pM->next!=mNULL)
- {
- pM->pMeunName=pChar[i];
- pM=pM->next;
- i++;
- }
- pM->pMeunName=pChar[i];
- }
- }
- //-------------------------------------------//
- //函数名:创建菜单链式表函数
- //入口:Void
- //出口:Void
- //功能:相同的父节点的结构体组成一个链式表;
- // 必须创建仔细否则将产生未知后果。
- //-------------------------------------------//
- void makeMenuList()
- {
- //----目录链式表----//
- mainMenu.next=mNULL;
- mainMenu.last=mNULL;
- //------------------//
- Clock.next=&Calendar;
- Calendar.next=&Music;
- Music.next=&Radio;
- Radio.next=&Games;
- Games.next=&Set;
- Set.next=&System;
- System.next=mNULL;
- makeReversChainTable(&Clock);
- //------------------//
- SetClock.next=&SetDate;
- SetDate.next=&SetAlarm;
- SetAlarm.next=&SetSystem;
- SetSystem.next=mNULL;
- makeReversChainTable(&SetClock);
- //------------------//
- SetSecond.next=&SetMinute;
- SetMinute.next=&SetHour;
- SetHour.next=mNULL;
- makeReversChainTable(&SetSecond);
- //------------------//
- SetYear.next=&SetMonth;
- SetMonth.next=&SetDay;
- SetDay.next=&SetWeek;
- SetWeek.next=mNULL;
- makeReversChainTable(&SetYear);
- //------------------//
- SetAlarmSecond.next=&SetAlarmMinute;
- SetAlarmMinute.next=&SetAlarmHour;
- SetAlarmHour.next=mNULL;
- makeReversChainTable(&SetAlarmSecond);
- //----子菜单父节点名以及父菜单光标位置----//
- makeParentNode(&mainMenu,&Clock);
- makeParentNode(&Set,&SetClock);
- makeParentNode(&SetClock,&SetSecond);
- makeParentNode(&SetDate,&SetYear);
- makeParentNode(&SetAlarm,&SetAlarmSecond);
- }
- //-------------------------------------------//
- //函数名:菜单信息初始化函数
- //入口:Void
- //出口:Void
- //功能:配置菜单的初始化信息,必须设置仔细否
- // 则将产生未知后果
- //-------------------------------------------//
- void menuInfoInit()
- {
- //----父菜单目录数以及子菜单目录序号----//
- makeDirectoryNumber(&Clock);
- makeDirectoryNumber(&SetClock);
- makeDirectoryNumber(&SetSecond);
- makeDirectoryNumber(&SetYear);
- makeDirectoryNumber(&SetAlarmSecond);
- //----菜单名字----//
- mainMenu.pMeunName=MeunName;
- getMenuName(mainMenuSubdirectory,&Clock);
- getMenuName(SetSubdirectory,&SetClock);
- getMenuName(SetClockSubdirectory,&SetSecond);
- getMenuName(SetDateSubdirectory,&SetYear);
- getMenuName(SetAlarmSubdirectory,&SetAlarmSecond);
- //----功能函数----//
- System.pFunction=aboutSystem;
- Clock.pFunction=displayClock;
- Calendar.pFunction=displayDate;
- }
- //-------------------------------------------//
- //函数名:时间显示函数
- //入口:Void
- //出口:Void
- //功能:显示时间
- //-------------------------------------------//
- void displayClock()
- {
- struct tm * tmptr;
- int hour1,min1,second1;
- time_t secnow;
- time(&secnow);
- tmptr = localtime(&secnow);
- hour1 = tmptr->tm_hour;
- min1 = tmptr->tm_min;
- second1=tmptr->tm_sec;
- printf("┌───>>时钟显示<<───┐\n");
- printf("│北京时间:%.2d:%.2d:%.2d │\n",hour1,min1,second1);
- printf("└────────────┘\n");
- }
- //-------------------------------------------//
- //函数名:日期显示函数
- //入口:Void
- //出口:Void
- //功能:显示日期
- //-------------------------------------------//
- void displayDate()
- {
- char p[7][4]={"日","一","二","三","四","五","六"};
- struct tm * tmptr;
- int year,month,day,week;
- time_t secnow;
- time(&secnow);
- tmptr = localtime(&secnow);
- year = tmptr->tm_year;
- month = tmptr->tm_mon;
- day=tmptr->tm_mday;
- week=tmptr->tm_wday;
- printf("┌───>>日期显示<<───┐\n");
- printf("│%d年%d月%d日 星期%s │\n",year+1900,month+1,day,p[week]);
- printf("└────────────┘\n");
- }
- //-------------------------------------------//
- //函数名:系统信息显示函数
- //入口:Void
- //出口:Void
- //功能:显示系统信息
- //-------------------------------------------//
- void aboutSystem()
- {
- printf("┌───>>关于系统<<───┐\n");
- printf("│名称:多级菜单系统 │\n");
- printf("│作者:詹磊(沐雨迎风) │\n");
- printf("│版本:V1.0 │\n");
- printf("│说明:‘↑’->光标上移 │\n");
- printf("│ ‘←’->返回 │\n");
- printf("│ ‘→’->进入 │\n");
- printf("│ ‘↓’->光标下移 │\n");
- printf("└────────────┘\n");
- }
- //-------------------------------------------//
- //函数名:菜单显示函数
- //入口:MenuInfo *pM:需要显示的菜单结构体地址
- //出口:UINT8 :0
- //功能:显示菜单,包括目录、菜单名、光标、光标位置
- //-------------------------------------------//
- UINT8 menuDisplay(MenuInfo *pM)
- #define MaxDisplayNumber 5
- {
- MenuInfo *tempM=pM->meunStatus;
- UINT8 i=0;
- if(tempM->serialNumber>MaxDisplayNumber)
- {
- while(i<(MaxDisplayNumber-1))
- {
- i++;
- tempM=tempM->last;
- }
- }
- else
- {
- while(tempM->last!=mNULL)
- {
- tempM=tempM->last;
- }
- }
- i=0;
- printf("┌─>>多级菜单系统V1.0<<─┐\n");
- printf(" ---------%s---------\n %d/%d\n",pM->pMeunName,pM->meunStatus->serialNumber,pM->directoryNumber);
- do
- {
- if(tempM==pM->meunStatus)
- printf(" >>%s\n",tempM->pMeunName);
- else
- printf(" %s\n",tempM->pMeunName);
- if(tempM->next!=mNULL)
- tempM=tempM->next;
- i++;
- }while(i<MaxDisplayNumber&&i<pM->directoryNumber);
- while(i<MaxDisplayNumber)
- {
- printf("\n");
- i++;
- }
- printf("└────────────┘\n");
- return 0;
- }
复制代码
|