Advertisement
pfoco

Cores com Funções em Linguagem C

Dec 17th, 2015
2,219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.47 KB | None | 0 0
  1. /*
  2.  
  3.   * Programa: Cores em linguagem C com funções
  4.   * Data de criação: 30/11/2015
  5.   * Autor: Eric Cancellgliere (http://programacaoemfoco.com.br)
  6.   * Versão: 1.0
  7.   * Última modificação em [30/11/2015] feita por [Eric Cancellgliere]
  8.  
  9. */
  10.  
  11. //bibliotecas
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <locale.h>
  15. #include <windows.h>
  16. #include <conio.h>
  17. #include <string.h>
  18.  
  19. enum DOS_COLORS {
  20.         BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN,
  21.         LIGHT_GRAY, DARK_GRAY, LIGHT_BLUE, LIGHT_GREEN, LIGHT_CYAN,
  22.         LIGHT_RED, LIGHT_MAGENTA, YELLOW, WHITE };
  23. // -------------------------------------------------------------------------
  24. void textcolor (DOS_COLORS iColor)
  25. {
  26.         HANDLE hl = GetStdHandle(STD_OUTPUT_HANDLE);
  27.         CONSOLE_SCREEN_BUFFER_INFO bufferInfo;
  28.         BOOL b = GetConsoleScreenBufferInfo(hl, &bufferInfo);
  29.         bufferInfo.wAttributes &= 0x00F0;
  30.         SetConsoleTextAttribute (hl, bufferInfo.wAttributes |= iColor);
  31. }
  32. // -------------------------------------------------------------------------
  33. void backcolor (DOS_COLORS iColor)
  34. {
  35.         HANDLE hl = GetStdHandle(STD_OUTPUT_HANDLE);
  36.         CONSOLE_SCREEN_BUFFER_INFO bufferInfo;
  37.         BOOL b = GetConsoleScreenBufferInfo(hl, &bufferInfo);
  38.         bufferInfo.wAttributes &= 0x000F;
  39.         SetConsoleTextAttribute (hl, bufferInfo.wAttributes |= (iColor << 4));
  40. }
  41. // -------------------------------------------------------------------------
  42.  
  43. int main(void){
  44.     //variáveis
  45.     int fundo, texto;
  46.     DOS_COLORS c[16] = {BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, LIGHT_GRAY, DARK_GRAY,
  47.                         LIGHT_BLUE, LIGHT_GREEN, LIGHT_CYAN, LIGHT_RED, LIGHT_MAGENTA, YELLOW, WHITE};
  48.    
  49.     //comando de regionalização
  50.     setlocale(LC_ALL, "Portuguese");
  51.     //título do programa
  52.     SetConsoleTitle("Cores com funcoes");
  53.    
  54.     printf ("Tabela de cores:\n\n");
  55.     printf ("\t0 - Preto\t\t8 - Cinza Escuro\n");
  56.     printf ("\t1 - Azul\t\t9 - Azul Claro\n");
  57.     printf ("\t2 - Verde\t\t10 - Verde Claro\n");
  58.     printf ("\t3 - Ciano\t\t11 - Ciano Claro\n");
  59.     printf ("\t4 - Vermelho\t\t12 - Vermelho Claro\n");
  60.     printf ("\t5 - Magenta\t\t13 - Magenta Claro\n");
  61.     printf ("\t6 - Marrom\t\t14 - Amarelo\n");
  62.     printf ("\t7 - Cinza Claro\t\t15 - Branco\n");
  63.    
  64.     printf ("\n\nCor de fundo: ");
  65.     scanf("%d", &fundo);
  66.    
  67.     printf ("Cor do texto: ");
  68.     scanf("%d", &texto);
  69.    
  70.     system ("cls");
  71.    
  72.     backcolor(c[fundo]);
  73.     textcolor(c[texto]);
  74.    
  75.     printf ("As cores da tela e do texto foram alteradas!\n\n");
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement