[P]转载:ahong007
[CODE]unsigned char tempin,tempout,temprun;
unsigned char Key_Value();
unsigned char Change_Value(unsigned char);
void Delay_1(unsigned int m);
void Run_Satus();
char * MainMenuTitle = "主菜单";
const char * MainMenuItems[] = { "1.室内温度调整", "2.室外温度调整", "3.运行时间调整", "4.ESC 退出",
};
TMenu MainMenu;
void OnSelectMainMenu(int index)
{ if (index < 0 || index >= sizeof(MainMenuItems) / sizeof(char *)) return; ClearScreen(); switch (index) { case 0: TextOut(0, 1, "室内调整开始 "); tempin=Change_Value(tempin); TextOut(0, 1, "室内调整完毕"); Delay_1(300000); break; case 1: TextOut(0, 1, "室外调整开始 "); tempout=Change_Value(tempout); TextOut(0, 1, "室外调整完毕"); Delay_1(300000); break; case 2: TextOut(0, 1, "运行时间调整开始"); tempout=Change_Value(temprun); TextOut(0, 1, "运行时间完毕"); Delay_1(300000); break; case 3: break; } ClearScreen();
}
UINT OnMainMenuOk(void * arg)
{ TMenu * pMenu = (TMenu *)arg; if (pMenu) OnSelectMainMenu(pMenu->Current); return 0;
}
UINT OnMainMenuCancel(void * arg)
{ TMenu * pMenu = (TMenu *)arg; if (pMenu) { CloseMenu(pMenu); } return 0;
}
UINT OnMainMenuOtherKey(void * arg)
{ TMenu * pMenu = (TMenu *)arg; char key; if (pMenu) { key = pMenu->EventArg; OnSelectMainMenu(key - '1'); DrawMenu(pMenu); } return 0;
}
void InitMenu()
{ InitializeMenu(&MainMenu, MainMenuTitle, MainMenuItems, sizeof
(MainMenuItems) / sizeof(char *)); MainMenu.OnOk = OnMainMenuOk; MainMenu.OnOtherKey = OnMainMenuOtherKey; MainMenu.OnCancel = OnMainMenuCancel;
}
unsigned char Key_Value()
{ unsigned char KeyTemp; KeyTemp=GetKey(); switch(KeyTemp) { case(VK_ESCAPE): return(0); break; case(VK_ENTER): return(1); break; case(VK_UP): return(2); break; case(VK_DOWN): return(3); break; }
}
unsigned char Change_Value(unsigned char temp2)
{ unsigned char temp3; temp3=temp2;
while((Key_Value()!=0)&&(Key_Value()!=1)) { if(Key_Value()==2)temp3++; else if(Key_Value()==3)temp3--; ClearLine(1); TextOut(0, 1, "调整状态%d", temp3); } if(Key_Value()==1)return(temp3); else if(Key_Value()==0) return(temp2);
} void Delay_1(unsigned int m) {while(m--); }
void Run_Satus()
{ ClearScreen(); TextOut(0, 0, "室内温度 %d",tempin); TextOut(0, 1, "室外温度 %d",tempout); TextOut(0, 2, "运行时间 %d",temprun); TextOut(0, 3, "ENTER 进入调整");
}
void tmain()
{ tempin=30; tempout=30; temprun=30; unsigned char key; InitMenu(); while(1) { Run_Satus(); key=GetKey(); if(key==VK_ENTER)ShowMenu(&MainMenu); }
}
[/CODE][/P] |