Guest User

Untitled

a guest
Apr 26th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.47 KB | None | 0 0
  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <stddef.h>
  4. #include <conio.h>
  5.  
  6.  
  7. // ФУНКЦИИ МЕНЮ
  8. void ViewMenu ();
  9. void Move ();
  10. void ViewSubMenu ();
  11. void SubMenu_off ();
  12. void BackLight (int x, int y);
  13. void BackLight_off ();
  14.  
  15. HANDLE hOut;
  16. COORD coord = {0,0};
  17. CONSOLE_CURSOR_INFO ConCurInf;
  18.  
  19. int hor_flag=0;
  20. int ver_flag=0;
  21. char* menu[4][5] = {
  22.                       {" List               ",
  23.                        "  View              ",
  24.                        "  Clear             ",
  25.                        NULL
  26.                       },
  27.                      
  28.                       {" Student            ",
  29.                        "  Add               ",
  30.                        "  Delete            ",
  31.                        "  Edit              ",
  32.                        NULL
  33.                       },
  34.                      
  35.                       {" Sort by            ",
  36.                        "  Date              ",
  37.                        "  Name              ",
  38.                        NULL
  39.                       },
  40.                      
  41.                       {" Exit               ",
  42.                        NULL
  43.                       },
  44.                     };
  45.                    
  46.  
  47. main ()
  48. {
  49.   hOut = GetStdHandle(STD_OUTPUT_HANDLE);
  50.   ConCurInf.dwSize = 10;
  51.   ConCurInf.bVisible = FALSE;
  52.   SetConsoleCursorInfo(hOut,&ConCurInf);
  53.   ViewMenu();
  54.   getch();
  55. }
  56. // MENU*************************************************************************
  57. //******************************************************************************
  58. //******************************************************************************
  59.  
  60. void ViewMenu ()
  61. {
  62.   int i=0;
  63.   coord.X=0;
  64.   coord.Y=0;
  65.   SetConsoleCursorPosition(hOut,coord);
  66.   SetConsoleTextAttribute (hOut,0x70);
  67.   while (i<4)
  68.   {
  69.     printf("%s",menu[i++][0]);      
  70.   }
  71.   Move();        
  72. }
  73.  
  74. void Move ()
  75. {
  76.   char key=0;
  77.  
  78.   coord.X = 60;coord.Y=0;
  79.   SetConsoleCursorPosition (hOut,coord);
  80.    
  81.    while (key != 13)
  82.    {
  83.       BackLight (coord.X, coord.Y);
  84.       ViewSubMenu ();
  85.       key = getch();
  86.       switch (key)
  87.       {
  88.        case 0x4d: if (coord.X==60) break;
  89.                   coord.X += 20;
  90.                   coord.Y =0;
  91.                   SetConsoleCursorPosition (hOut, coord); break;
  92.        case 0x4b: if (coord.X==0) break;
  93.                   coord.X -= 20;
  94.                   coord.Y =0;
  95.                   SetConsoleCursorPosition (hOut, coord); break;
  96.        case 0x48: if (coord.Y==0) break;
  97.                   coord.Y --;
  98.                   SetConsoleCursorPosition (hOut, coord); break;
  99.        case 0x50: if (coord.X == 0)
  100.                   if (coord.Y == 2) break;
  101.                   if (coord.X == 20)
  102.                   if (coord.Y == 3) break;
  103.                   if (coord.X == 40)
  104.                   if (coord.Y == 2) break;
  105.                   if (coord.X == 60)
  106.                   if (coord.Y == 0) break;
  107.                   coord.Y ++;
  108.                   SetConsoleCursorPosition (hOut, coord); break;          
  109.       }
  110.    }
  111. }
  112.  
  113. void ViewSubMenu ()
  114. {
  115.  
  116.   if (coord.Y == 0)
  117.   {
  118.     int tmp = coord.X;
  119.     int i=1;
  120.     SubMenu_off ();
  121.     SetConsoleTextAttribute (hOut, 0x70);
  122.     coord.X = tmp;
  123.     SetConsoleCursorPosition (hOut, coord);
  124.     while (menu[coord.X/20][i])
  125.     {
  126.       coord.Y++;
  127.       SetConsoleCursorPosition (hOut, coord);
  128.       printf("%s",menu[coord.X/20][i++]);      
  129.     }
  130.     coord.X =  tmp;
  131.     coord.Y = 0;
  132.     SetConsoleCursorPosition (hOut, coord);
  133.     hor_flag = coord.X;    
  134.   }
  135. }
  136.  
  137. void SubMenu_off ()
  138. {
  139.   int i=1;
  140.   coord.X = hor_flag;
  141.   SetConsoleCursorPosition (hOut, coord);
  142.   SetConsoleTextAttribute (hOut, 0x00);
  143.   while (menu[hor_flag/20][i])
  144.     {
  145.       coord.Y++;
  146.       SetConsoleCursorPosition (hOut, coord);
  147.       printf("%s",menu[hor_flag/20][i++]);      
  148.     }
  149.   coord.X = hor_flag;
  150.   coord.Y = 0;
  151.   SetConsoleCursorPosition (hOut, coord);        
  152. }
  153.  
  154.  
  155. void BackLight (int x, int y)
  156. {
  157.   BackLight_off();
  158.   int tmp=coord.X;
  159.   SetConsoleTextAttribute (hOut, 0x31);
  160.   printf("%s",menu[x/20][y]);
  161.   coord.X =tmp;
  162.   SetConsoleCursorPosition (hOut, coord);
  163.   ver_flag = y;      
  164. }
  165.  
  166. void BackLight_off ()
  167. {
  168.   int tmpx = coord.X;
  169.   int tmp = coord.Y;
  170.   SetConsoleTextAttribute (hOut, 0x70);
  171.   coord.X = hor_flag;
  172.   coord.Y = ver_flag;
  173.   SetConsoleCursorPosition (hOut, coord);
  174.   printf("%s",menu[coord.X/20][coord.Y]);
  175.   coord.X = tmpx; coord.Y = tmp;
  176.   SetConsoleCursorPosition (hOut, coord);      
  177. }
Add Comment
Please, Sign In to add comment