Linguagem C/C++ Manipulando Cores com a Função System

Linguagem C/C++ Manipulando Cores com a Função System
   1 #include <windows.h>
  2  #include "resource.h"
  3  #include <stdio.h>
  4  #include <time.h>
  5  
  6  #define BTN_SAIR 2
  7  
  8  LRESULT CALLBACK ProcJan(HWND, UINT, WPARAM, LPARAM);
  9  char szNomeAplic[] = "Principal";
 10  
 11  HMENU menuP, sMenu;
 12  
 13  static HWND Lista;
 14  
 15  int WINAPI WinMain(HINSTANCE hCopia, HINSTANCE hCopiaAnt, LPSTR szLinhaCmd, int iCmdMostrar) {
 16      HWND     hjan;
 17      MSG      msg;
 18      WNDCLASS classjan;
 19  
 20      classjan.style         = CS_HREDRAW | CS_VREDRAW;
 21      classjan.lpfnWndProc   = ProcJan;
 22      classjan.cbClsExtra    = 0;
 23      classjan.cbWndExtra    = 0;
 24      classjan.hInstance     = hCopia;
 25      classjan.hIcon         = LoadIcon(hCopia, IDI_ICON);
 26      classjan.hCursor       = LoadCursor(NULL, IDC_ARROW);
 27      classjan.hbrBackground = GetSysColorBrush(COLOR_INACTIVECAPTION);
 28      classjan.lpszMenuName  = NULL;
 29      classjan.lpszClassName = szNomeAplic;
 30  
 31      if(!RegisterClass(&classjan)) {
 32          return 0;
 33      }
 34  
 35      hjan = CreateWindow(szNomeAplic, "Janela Principal", WS_OVERLAPPEDWINDOW,
 36                          CW_USEDEFAULT, CW_USEDEFAULT, 500, 300,
 37                          NULL, NULL, hCopia, NULL);
 38  
 39      ShowWindow(hjan, iCmdMostrar);
 40      UpdateWindow(hjan);
 41  
 42      while(GetMessage(&msg, NULL, 0, 0)) {
 43          TranslateMessage(&msg);
 44          DispatchMessage (&msg);
 45      }
 46  
 47      return msg.wParam;
 48  }
 49  
 50  LRESULT CALLBACK ProcJan(HWND hjan, UINT iMsg, WPARAM wParam, LPARAM lParam) {
 51  
 52      switch(iMsg) {
 53          case WM_CREATE:
 54              menuP = CreateMenu();
 55              sMenu = CreateMenu();
 56  
 57              AppendMenu(menuP, MF_POPUP, (UINT_PTR) sMenu, "Arquivo");
 58              AppendMenu(menuP, MF_STRING, NULL, "Editar");
 59              AppendMenu(menuP, MF_STRING, NULL, "Copiar");
 60              AppendMenu(menuP, MF_STRING, 1, "Evento");
 61  
 62              AppendMenu(sMenu, MF_STRING, NULL, "SUB 1");
 63              AppendMenu(sMenu, MF_STRING, NULL, "Camera");
 64              AppendMenu(sMenu, MF_STRING, NULL, "Rede");
 65  
 66              SetMenu(hjan, menuP);
 67  
 68              char pl[] = "Mas ele foi ferido pelas nossas transgressões, e moído pelas nossas iniquidades; o castigo que nos traz a paz estava sobre ele, e, pelas suas pisaduras, fomos sarados. \nIsaías 53:5";
 69              CreateWindow(
 70                  TEXT("static"), pl, WS_VISIBLE | WS_CHILD | ES_LEFT,
 71                  10, 20, 430, 70,
 72                  hjan, NULL, NULL, NULL
 73              );
 74  
 75              CreateWindow(
 76                  TEXT("button"), TEXT("Cor 1"), WS_VISIBLE | WS_CHILD,
 77                  10, 100, 100, 20,
 78                  hjan, 3, NULL, NULL
 79              );
 80              CreateWindow(
 81                  TEXT("button"), TEXT("Cor 2"), WS_VISIBLE | WS_CHILD,
 82                  120, 100, 100, 20,
 83                  hjan, 4, NULL, NULL
 84              );
 85              CreateWindow(
 86                  TEXT("button"), TEXT("Cor 3"), WS_VISIBLE | WS_CHILD,
 87                  230, 100, 100, 20,
 88                  hjan, 5, NULL, NULL
 89              );
 90              CreateWindow(
 91                  TEXT("button"), TEXT("Cor 4"), WS_VISIBLE | WS_CHILD,
 92                  340, 100, 100, 20,
 93                  hjan, 6, NULL, NULL
 94              );
 95  
 96              CreateWindow(
 97                  TEXT("button"), TEXT("Executar"), WS_VISIBLE | WS_CHILD,
 98                  10, 140, 100, 20,
 99                  hjan, NULL, NULL, NULL
100              );
101              CreateWindow(
102                  TEXT("button"), TEXT("Sair"), WS_VISIBLE | WS_CHILD,
103                  160, 140, 100, 20,
104                  hjan, (HWND) BTN_SAIR, NULL, NULL
105              );
106  
107              struct tm *ptr;
108              time_t lt;
109              lt = time(NULL);
110              ptr = localtime(&lt);
111  
112              CreateWindow(
113                  TEXT("static"), asctime(ptr), WS_VISIBLE | WS_CHILD,
114                  10, 180, 200, 20,
115                  hjan, NULL, NULL, NULL
116              );
117  
118              Lista = CreateWindow( /**static HWND Lista -> Declarado No escopo*/
119                  "combobox", NULL, WS_CHILD|WS_TABSTOP|WS_VISIBLE|CBS_DROPDOWNLIST|CBS_SORT|WS_VSCROLL,
120                  320, 140, 95, 150,
121                  hjan, NULL, NULL, NULL
122              );
123              SendMessage(Lista, CB_ADDSTRING, 0, (LPARAM)"C/C++");
124              SendMessage(Lista, CB_ADDSTRING, 0, (LPARAM)"PHP");
125              SendMessage(Lista, CB_ADDSTRING, 0, (LPARAM)"JS");
126              SendMessage(Lista, CB_ADDSTRING, 0, (LPARAM)"HTML");
127              SendMessage(Lista, CB_ADDSTRING, 0, (LPARAM)"XSLT");
128              SendMessage(Lista, CB_ADDSTRING, 0, (LPARAM)"PASCAL");
129              SendMessage(Lista, CB_ADDSTRING, 0, (LPARAM)"XML");
130              return 0;
131          case WM_COMMAND:
132              if(LOWORD(wParam)==1) {
133                  SetWindowText(hjan,"Alterar Título!!!!!!!!!!");
134              }
135              if(LOWORD(wParam)==BTN_SAIR) {
136                  exit(0);
137              }
138              if(LOWORD(wParam)==3) {
139                  system("color 1a");
140              }
141              if(LOWORD(wParam)==4) {
142                  system("color c0");
143              }
144              if(LOWORD(wParam)==5) {
145                  system("color a4");
146              }
147              if(LOWORD(wParam)==6) {
148                  system("color 25");
149              }
150              return 0;
151  
152          case WM_DESTROY:
153              PostQuitMessage(0);
154              return 0;
155      }
156      return DefWindowProc(hjan, iMsg, wParam, lParam);
157  
158  }
159  

Comentários