c++ 菜单动态效果

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdarg.h> 
#include <time.h>
#include "hello.h"
#include <share.h>
#include <Windows.h>
//#define  var 333;
//移动光标位置
void gotoxy(int x,int y)
{
    COORD xy;
    HANDLE hstdout;
    hstdout=GetStdHandle(STD_OUTPUT_HANDLE);
    xy.X=x;
    xy.Y=y;
    SetConsoleCursorPosition(hstdout,xy);
    //CloseHandle(hstdout);
}
void fillchar(char a,int charlen)
{
    COORD xy={0};
    HANDLE hstdout;
    long byw;
    
    hstdout=GetStdHandle(STD_OUTPUT_HANDLE);
    FillConsoleOutputCharacter(hstdout,a,charlen,xy,&byw);
    CloseHandle(hstdout);
}
#define  X 20
#define  Y 6
//绘制边框
void drawM(void)
{
    int i;
    //上边
    gotoxy(X,Y);
    printf("");
     for (i=1;i<=13;i++)
     {
         printf("");
     }
    printf("");
    //左边
    for (i=1;i<=16;i++)
    {
      gotoxy(X,Y+i);
      printf("");
    }
    //右边
    for (i=1;i<=16;i++)
    {
        gotoxy(X+28,Y+i);
        printf("");
    }
    //下边
    gotoxy(X,Y+17);
    printf("");
    for (i=1;i<=13;i++)
    {
         printf("");
    }
    printf("");
    return ;
    
}
//drawmenu
void drawmenu(void)
{
    gotoxy(X+3,Y+3);
    printf("1->菜单选项一");
    gotoxy(X+3,Y+3+2);
    printf("   菜单选项二");
     gotoxy(X+3,Y+3+2+2);
    printf("   退出");
    gotoxy(0,0);
}
int selmenu_Num=0;
int selmenu(void)
{ //0,1,2
  //如果按下↓selmenu_Num++; 如果>2  selmenu_Num=0;
  //如果按下↑selmenu_Num--; 如果<0  selmenu_Num=2;
    int ch=0;
    while(1)
    {
        ch=getch();
        //gotoxy(0,0);
        //printf("%d ",ch);
        if (ch==13)
        {
            return selmenu_Num;
        }
        switch(ch)
        {
        case 72://上光标
            selmenu_Num--;
            if (selmenu_Num<0)
            {
                selmenu_Num=2;
            }
            break;
        case 80: //下光标
            selmenu_Num++;
            if (selmenu_Num>2)
            {
                selmenu_Num=0;
            }
            break;
        }
     gotoxy(0,0);
    // printf("selmenu_num=%d",selmenu_Num);
       //动态菜单
       switch(selmenu_Num)
       {
       case 0:
           gotoxy(X+3,Y+3);
           printf("1->");
           gotoxy(X+3,Y+3+2);
           printf("   ");
           gotoxy(X+3,Y+3+2+2);
           printf("   ");
           gotoxy(0,0);
       break;
       case 1:
           gotoxy(X+3,Y+3);
           printf("   ");
           gotoxy(X+3,Y+3+2);
           printf("2->");
           gotoxy(X+3,Y+3+2+2);
           printf("   ");
           gotoxy(0,0);
       break;
       case 2:
           gotoxy(X+3,Y+3);
           printf("   ");
           gotoxy(X+3,Y+3+2);
           printf("   ");
           gotoxy(X+3,Y+3+2+2);
           printf("3->");
           gotoxy(0,0);
       break;
       }
    } //end while
     
    return selmenu_Num;
}
//doMenu
void doMenu(void)
{ int sel;
   sel=    selmenu();
   switch(sel)
   {
   case 0: //菜单一
        gotoxy(0,0);
        printf("\n菜单一功能\n");
       break;
   case 1:       
       gotoxy(0,0);
       printf("\n菜单二功能\n");
       break;
   case 2: //退出
       exit(1);
       break;
   }
}

int main(void)
{  //Y行 X列
  // fillchar(' ',3000);
    system("color 0a");
    system("title QQ150330575");
    drawM();
    drawmenu();
    doMenu();
    getchar();
    getchar();
    return 0;
}

 

转载于:https://www.cnblogs.com/whzym111/p/6165204.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值