標題:
VS 2010文本多級菜單程序系統(tǒng)設(shè)計,理論可實現(xiàn)1~255個菜單級數(shù)和目錄數(shù)
[打印本頁]
作者:
51hei學習技術(shù)中
時間:
2017-3-16 03:12
標題:
VS 2010文本多級菜單程序系統(tǒng)設(shè)計,理論可實現(xiàn)1~255個菜單級數(shù)和目錄數(shù)
基于VS 2010的文本菜單系統(tǒng),理論上最大可以實現(xiàn)1~255個菜單級數(shù)和目錄數(shù)
0.png
(51.59 KB, 下載次數(shù): 117)
下載附件
2017-3-16 03:07 上傳
全部源碼下載(整個工程文件):
menu-systemV1.0.rar
(1002.01 KB, 下載次數(shù): 31)
2017-3-16 03:10 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
部分源程序預(yù)覽:
//---------------------------------------------------//
//產(chǎn)品:多級菜單程序
//作者:詹磊
//版本:v1.0
//說明:本程序僅供測試使用,在創(chuàng)建鏈表時出現(xiàn)錯誤將產(chǎn)生未知后果
//修改歷史:1、7/30 創(chuàng)建
// 2、7/31 添加自動計算菜單目錄信息功能
// 3、8/12 代碼整理
//功能描述:理論上可以實現(xiàn)255級樹形單列文本菜;
// 單每個菜單最大目錄數(shù)為255個;
// 通過定義MaxDisplayNumber來設(shè)置每面菜單顯示的目錄數(shù);
//運行環(huán)境:VC2010
//---------------------------------------------------//
#include "..\Include\menu.h" /*菜單頭文件*/
//--主菜單--//
MenuInfo mainMenu; //菜單結(jié)構(gòu)體
char MeunName[]="主菜單"; //菜單名字表
//--一級菜單--//
MenuInfo Clock,Calendar,Music,Radio,Games,Set,System; //菜單結(jié)構(gòu)體
char *mainMenuSubdirectory[7]={"時鐘","日歷","音樂","收音","游戲","設(shè)置","系統(tǒng)"}; //菜單名字表
//--二級菜單--//
MenuInfo SetClock,SetDate,SetAlarm,SetSystem; //菜單結(jié)構(gòu)體
char *SetSubdirectory[4]={"時間","日期","鬧鐘","系統(tǒng)"}; //菜單名字表
//--三級菜單--//
MenuInfo SetSecond,SetMinute,SetHour; //菜單結(jié)構(gòu)體
char *SetClockSubdirectory[3]={"秒","分","時"}; //菜單名字表
MenuInfo SetYear,SetMonth,SetDay,SetWeek; //菜單結(jié)構(gòu)體
char *SetDateSubdirectory[4]={"年","月","日","星期"}; //菜單名字表
MenuInfo SetAlarmSecond,SetAlarmMinute,SetAlarmHour; //菜單結(jié)構(gòu)體
char *SetAlarmSubdirectory[3]={"秒","分","時"}; //菜單名字表
//-------------------------------------------//
//函數(shù)名:創(chuàng)建菜單反向鏈式表函數(shù)
//入口: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;
}
}
//-------------------------------------------//
//函數(shù)名:創(chuàng)建菜單父節(jié)點函數(shù)
//入口:MenuInfo *pParentM:父節(jié)點結(jié)構(gòu)體
// 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;
}
}
//-------------------------------------------//
//函數(shù)名:創(chuàng)建菜單目錄信息函數(shù)
//入口: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;
}
}
//-------------------------------------------//
//函數(shù)名:獲取菜單名字函數(shù)
//入口:char **pChar:菜單名字所在的數(shù)組的指針
// 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];
}
}
//-------------------------------------------//
//函數(shù)名:創(chuàng)建菜單鏈式表函數(shù)
//入口:Void
//出口:Void
//功能:相同的父節(jié)點的結(jié)構(gòu)體組成一個鏈式表;
// 必須創(chuàng)建仔細否則將產(chǎn)生未知后果。
//-------------------------------------------//
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);
//----子菜單父節(jié)點名以及父菜單光標位置----//
makeParentNode(&mainMenu,&Clock);
makeParentNode(&Set,&SetClock);
makeParentNode(&SetClock,&SetSecond);
makeParentNode(&SetDate,&SetYear);
makeParentNode(&SetAlarm,&SetAlarmSecond);
}
//-------------------------------------------//
//函數(shù)名:菜單信息初始化函數(shù)
//入口:Void
//出口:Void
//功能:配置菜單的初始化信息,必須設(shè)置仔細否
// 則將產(chǎn)生未知后果
//-------------------------------------------//
void menuInfoInit()
{
//----父菜單目錄數(shù)以及子菜單目錄序號----//
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);
//----功能函數(shù)----//
System.pFunction=aboutSystem;
Clock.pFunction=displayClock;
Calendar.pFunction=displayDate;
}
//-------------------------------------------//
//函數(shù)名:時間顯示函數(shù)
//入口: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");
}
//-------------------------------------------//
//函數(shù)名:日期顯示函數(shù)
//入口: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");
}
//-------------------------------------------//
//函數(shù)名:系統(tǒng)信息顯示函數(shù)
//入口:Void
//出口:Void
//功能:顯示系統(tǒng)信息
//-------------------------------------------//
void aboutSystem()
{
printf("┌───>>關(guān)于系統(tǒng)<<───┐\n");
printf("│名稱:多級菜單系統(tǒng) │\n");
printf("│作者:詹磊(沐雨迎風) │\n");
printf("│版本:V1.0 │\n");
printf("│說明:‘↑’->光標上移 │\n");
printf("│ ‘←’->返回 │\n");
printf("│ ‘→’->進入 │\n");
printf("│ ‘↓’->光標下移 │\n");
printf("└────────────┘\n");
}
//-------------------------------------------//
//函數(shù)名:菜單顯示函數(shù)
//入口:MenuInfo *pM:需要顯示的菜單結(jié)構(gòu)體地址
//出口: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("┌─>>多級菜單系統(tǒng)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;
}
復(fù)制代碼
作者:
mxjmjl
時間:
2018-5-3 10:36
菜單太多看了頭都痛,不過用學習和找借鑒是不錯的。
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1