改一下:
#include<stdio.h>
#include<windows.h>
HANDLE hStd = 0;
void _Say(SHORT x, SHORT y, char *s, WORD Color)
{
SetConsoleTextAttribute(hStd, Color);
COORD pos = {x, y};
SetConsoleCursorPosition(hStd, pos);
printf(s);
}
void _menu(char *menu[], int count, WORD color)
{
int i;
for (i=0; i<count; i++)
_Say(i*10+2, 3, menu[i], color);
}
main()
{
hStd = GetStdHandle(STD_OUTPUT_HANDLE);
WORD selecolor = BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED;
WORD forecolor = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
char *menu[]={"菜单1","菜单2","菜单3"};
int k, sele=0, menucount=3;
printf("\n用上下左右方向键选择,回车确定\n");
_menu(menu, menucount, forecolor);
_Say(sele*10+2, 3, menu[sele], selecolor);
while ((k=getch()) != '\r')
{
if (k==72 || k==75 || k==77 || k==80)
{
_Say(sele*10+2, 3, menu[sele], forecolor);
sele = (k==72 || k==75) ? --sele : ++sele;
if (sele == menucount)
sele = 0;
else if (sele < 0)
sele = menucount - 1;
_Say(sele*10+2, 3, menu[sele], selecolor);
}
}
SetConsoleTextAttribute(hStd, forecolor);
printf("\n\n选择:%s\n", menu[sele]);
}