Advertisement
Guest User

Untitled

a guest
Apr 19th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.03 KB | None | 0 0
  1. include <windows.h>
  2. #include <time.h>
  3.  
  4. //V-6
  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 = "Show";
  12. LPCSTR button_clear_text = "Clear";
  13. LPCSTR button_about_text = "About";
  14.  
  15. LPCSTR main_window_name = "Hello App";
  16. LPCSTR main_window_class = "hello_class";
  17.  
  18. LPCSTR about_text = "Sergey Rakhmanov (IU3-21B)";
  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.                                        100, 100, 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.                                        100, 250, 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(204, 51, 0));
  105.            hbrush = CreateSolidBrush(RGB(204, 51, 0));
  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, 600, 100, 624, 300);
  135.  
  136.                    hbrush = CreateSolidBrush(RGB(0, 255, 0));
  137.                    hpen = CreatePen(PS_SOLID, 10,RGB(0, 255, 0));
  138.                    SelectObject(hdc, hbrush);
  139.                    SelectObject(hdc, hpen);
  140.  
  141.                    Ellipse(hdc, 525, 50, 698, 200);
  142.                    break;
  143.                case 2:
  144.                    break;
  145.                case 3:
  146.                    TextOut(hdc, 500, 100, about_text, strlen(about_text));
  147.                    break;
  148.            }
  149.  
  150.            EndPaint(hwnd, &ps);
  151.            return 0;
  152.  
  153.        case WM_DESTROY :
  154.            PostQuitMessage(0);
  155.            return 0;
  156.    }
  157.  
  158.    return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement