#include "datatype.h"
#include "menu.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
void func(void)
{
}
//首先定义一个菜单结构体
typedef struct menu //定义一个菜单
{
unsigned char range_from,range_to; //当前显示的项开始及结束序号
unsigned char itemCount; //项目总数
unsigned char selected; //当前选择项
unsigned char *menuItems[17]; //菜单项目
struct menu **subMenus; //子菜单
struct menu *parent; //上级菜单 ,如果是顶级则为null
void (**func)(); //选择相应项按确定键后执行的函数
}Menu;
Menu MainMenu = { //定义主菜单
0,3,4,0, //默认显示0-3项,总共4项,当前选择第0项
{
"测量表 ", // >表示有下级选项
"其他设置 ",
"保护设定 ",
"查询 >"
}
};
Menu searchMenu = { //查询菜单
0,3,6,0,
{
"记帐记录明细 ",
"未采集记录数 ",
"设备机号 ",
"本机IP地址 ",
"记录空间大小 ",
"软件版本 "
}
};
Menu *currentMenu; //当前的菜单
//初始化菜单:
void initMenu()
{
char mempool[512];
init_mempool (&mempool, sizeof(mempool));
MainMenu.subMenus = malloc(sizeof(&MainMenu)*4);
MainMenu.subMenus[0] = &searchMenu;//第1到3项没有子菜单置null,选择后程序会调用func中相应项中的函数
MainMenu.subMenus[1] = NULL;
MainMenu.subMenus[2] = NULL;
MainMenu.subMenus[3] = NULL;//第四项查询有子菜单
MainMenu.func = malloc(sizeof(&func)*4);
MainMenu.func[0] = NULL;
MainMenu.func[1] = NULL;
MainMenu.func[2] = &func;//当选择了并按了确定,会执行func函数
MainMenu.func[3] = NULL;
MainMenu.parent = NULL;//表示是顶级菜单
searchMenu.subMenus = malloc(sizeof(&searchMenu)*6);
searchMenu.subMenus[0] = searchMenu.subMenus[1] = searchMenu.subMenus[2] = searchMenu.subMenus[3] = searchMenu.subMenus[4] = searchMenu.subMenus[5] = NULL;
searchMenu.func = malloc(sizeof(&printf)*6);
searchMenu.func[0] = searchMenu.func[1] = searchMenu.func[2] = searchMenu.func[3] = searchMenu.func[4] = searchMenu.func[5] = NULL;
searchMenu.parent = &MainMenu;//上一级菜单是MainMenu.进入查询子菜单后按返回键,将会显示这个菜单项
currentMenu = &MainMenu;
}
void main(void)
{
} |