Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.75 KB | None | 0 0
  1. /*
  2.    @author Ramon Caldeira
  3. */
  4.  
  5. #include <windows.h>
  6. #include <stdio.h>
  7. #include <conio.h>
  8.  
  9. #define TEXT_NORMAL   15
  10. #define TEXT_REVERSE 240
  11.  
  12. #define ENTER 13
  13. #define UP    72
  14. #define DOWN  80
  15.  
  16. typedef short  COLOR;
  17.  
  18. void printxy(int x, int y, char* text);
  19. void setColor(COLOR c);
  20.  
  21. void Entrar();
  22. void Cadastrar();
  23. void Sair();
  24.  
  25.  
  26. struct OPTION {
  27.    char* description;
  28.    void (*function)();
  29. };
  30.  
  31. OPTION options[3] =
  32. {  {"Entrar", Entrar },
  33.    {"Cadastrar", Cadastrar },
  34.    {"Sair", Sair},
  35. };
  36.  
  37. int main() {
  38.    int selecionado= 0;
  39.    bool done = false;
  40.    char ch;
  41.    
  42.    do {
  43.       for(int i = 0; i < 3; i++) {
  44.          setColor((selecionado == i) ? TEXT_REVERSE : TEXT_NORMAL);
  45.          printxy(10, 5 + (i * 2), options[i].description);
  46.       }    
  47.      
  48.       ch = getch();
  49.      
  50.       switch(ch) {
  51.          case ENTER:
  52.             options[selecionado].function();
  53.             break;
  54.          case UP:
  55.             selecionado = (selecionado == 0) ? 0 : selecionado - 1;
  56.             break;
  57.          case DOWN:
  58.             selecionado = (selecionado == 2) ? 2 : selecionado + 1;
  59.             break;
  60.       }
  61.      
  62.    } while(!done);
  63.  
  64.    getchar();
  65.    return 0;
  66. }
  67.  
  68. void printxy(int x, int y, char* text) {
  69.    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
  70.    COORD c = {x - 1, y - 1};
  71.    SetConsoleCursorPosition(hOut, c);
  72.    printf("%s", text);
  73. }
  74.  
  75. void setColor(COLOR c) {
  76.    HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
  77.    SetConsoleTextAttribute(hOut, c);
  78. }
  79.  
  80. void Entrar() {
  81.    system("cls");
  82.    printf("NOME: \n\n");
  83.    printf("SENHA: ");
  84. }
  85.  
  86. void Cadastrar() {
  87.    system("cls");
  88.    printf("NOME: \n\n");
  89.    printf("E-MAIL: \n\n");
  90.    printf("SENHA: \n\n");
  91. }
  92.  
  93. void Sair() {
  94.    exit(0);
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement