Advertisement
Guest User

Untitled

a guest
Apr 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.01 KB | None | 0 0
  1. #include <windows.h>
  2. #include <time.h>
  3. #include "stdafx.h"
  4.  
  5.  
  6. LPCSTR registration_error_message = "Couldn't initialize class!";
  7. LPCSTR registration_error_title = "Error: initializing";
  8. LPCSTR creating_window_error_title = "Error: creating";
  9. LPCSTR creating_window_error_message = "Couldn't create window!";
  10.  
  11. LPCSTR button_show_text = "ФЛАГ СТРАНЫ";
  12. LPCSTR button_clear_text = "СТЕРЕТЬ ФЛАГ";
  13. LPCSTR button_about_text = "СОЗДАТЕЛЬ";
  14.  
  15. LPCSTR main_window_name = "Hello App";
  16. LPCSTR main_window_class = "hello_class";
  17.  
  18. LPCSTR about_text = "MИХАЙЛОВА ИРИНА ИУ3-21Б ";
  19.  
  20. LRESULT CALLBACK window_callback(HWND, UINT, WPARAM, LPARAM);
  21. HINSTANCE hInst;
  22.  
  23. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) {
  24.     HWND main_window;
  25.     MSG msg;
  26.     WNDCLASSEX wc;
  27.  
  28.     wc.cbSize = sizeof(wc);
  29.     wc.style = CS_HREDRAW | CS_VREDRAW;
  30.     wc.lpfnWndProc = window_callback;
  31.     wc.lpszMenuName = NULL;
  32.     wc.lpszClassName = main_window_class;
  33.     wc.cbWndExtra = 0;
  34.     wc.cbClsExtra = 0;
  35.     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  36.     wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  37.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  38.     wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
  39.     wc.hInstance = hInstance;
  40.  
  41.     if (!RegisterClassEx(&wc)) {
  42.         MessageBox(NULL, registration_error_message, registration_error_title, MB_OK);
  43.         return NULL;
  44.     }
  45.  
  46.     main_window = CreateWindow(main_window_class,
  47.         main_window_name,
  48.         WS_OVERLAPPEDWINDOW,
  49.         CW_USEDEFAULT,
  50.         CW_USEDEFAULT,
  51.         CW_USEDEFAULT,
  52.         CW_USEDEFAULT,
  53.         NULL,
  54.         NULL,
  55.         hInstance,
  56.         NULL);
  57.  
  58.     if (!main_window) {
  59.         MessageBox(NULL, creating_window_error_message, creating_window_error_title, MB_OK);
  60.         return NULL;
  61.     }
  62.  
  63.     ShowWindow(main_window, iCmdShow);
  64.     UpdateWindow(main_window);
  65.  
  66.     while (GetMessage(&msg, NULL, 0, 0)) {
  67.         TranslateMessage(&msg);
  68.         DispatchMessage(&msg);
  69.     }
  70.     return msg.wParam;
  71. }
  72.  
  73. #define BTN_WIDTH 150
  74. #define BTN_HEIGHT 20
  75. LRESULT CALLBACK window_callback(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) {
  76.     HDC hdc;
  77.     PAINTSTRUCT ps;
  78.     RECT rect;
  79.     HWND button_show, button_clear, button_author;
  80.     int loword;
  81.     static int choise = 0;
  82.     static HPEN hpen;
  83.     static HBRUSH hbrush;
  84.  
  85.     switch (iMsg) {
  86.     case WM_CREATE:
  87.         button_show = CreateWindow("button", button_show_text,
  88.             WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
  89.             100, 50, BTN_WIDTH, BTN_HEIGHT,
  90.             hwnd, (HMENU)1, hInst, NULL);
  91.  
  92.         button_clear = CreateWindow("button", button_clear_text,
  93.             WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
  94.             300, 50, BTN_WIDTH, BTN_HEIGHT,
  95.             hwnd, (HMENU)2, hInst, NULL);
  96.  
  97.         button_author = CreateWindow("button", button_about_text,
  98.             WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
  99.             500, 50, BTN_WIDTH, BTN_HEIGHT,
  100.             hwnd, (HMENU)3, hInst, NULL);
  101.         return 0;
  102.  
  103.     case WM_COMMAND:
  104.         hpen = CreatePen(PS_SOLID, 10, RGB(0, 0, 0));
  105.         hbrush = CreateSolidBrush(RGB(255, 255, 255));
  106.         loword = LOWORD(wParam);
  107.  
  108.         switch (loword) {
  109.         case 1:
  110.             choise = 1;
  111.             break;
  112.         case 2:
  113.             choise = 2;
  114.             break;
  115.         case 3:
  116.             choise = 3;
  117.             break;
  118.         default:
  119.             break;
  120.         }
  121.  
  122.         InvalidateRect(hwnd, NULL, TRUE);
  123.         return 0;
  124.  
  125.     case WM_PAINT:
  126.         hdc = BeginPaint(hwnd, &ps);
  127.  
  128.         GetClientRect(hwnd, &rect);
  129.         SelectObject(hdc, hbrush);
  130.         SelectObject(hdc, hpen);
  131.  
  132.         switch (choise) {
  133.         case 1:
  134.             Rectangle(hdc, 200, 200, 700, 300);
  135.  
  136.             hbrush = CreateSolidBrush(RGB(10, 10, 132));
  137.             hpen = CreatePen(PS_SOLID, 10, RGB(0, 0, 0));
  138.             SelectObject(hdc, hbrush);
  139.             SelectObject(hdc, hpen);
  140.  
  141.             Rectangle(hdc, 200, 300, 700, 400);
  142.  
  143.             hbrush = CreateSolidBrush(RGB(255, 0, 0));
  144.             hpen = CreatePen(PS_SOLID, 10, RGB(0, 0, 0));
  145.             SelectObject(hdc, hbrush);
  146.             SelectObject(hdc, hpen);
  147.             Rectangle(hdc, 200, 400, 700, 500);
  148.             break;
  149.         case 2:
  150.             break;
  151.         case 3:
  152.             TextOut(hdc, 500, 300, about_text, strlen(about_text));
  153.             break;
  154.         }
  155.  
  156.         EndPaint(hwnd, &ps);
  157.         return 0;
  158.  
  159.     case WM_DESTROY:
  160.         PostQuitMessage(0);
  161.         return 0;
  162.     }
  163.  
  164.     return DefWindowProc(hwnd, iMsg, wParam, lParam);
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement