bruno63

Paint #1

Nov 8th, 2015
732
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Windows.h>
  2. #include <string>
  3. using namespace std;
  4.  
  5. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  6.  
  7. LPTSTR className = L"nazwaKlasy";
  8. WNDCLASSEX wc;// , wc2;
  9. HWND hwnd, knefel;
  10. MSG msg;
  11. PAINTSTRUCT ps;
  12. RECT rect;
  13. HDC hdc;
  14. POINT pojnt = { rect.right - 85,rect.top + 30 }, trojkat[3];
  15. HPEN p1 = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
  16. HBRUSH b1 = CreateSolidBrush(RGB(255, 255, 255));
  17. HBRUSH b2 = CreateSolidBrush(RGB(255, 255, 255));
  18. HBRUSH brushes[12] = { CreateSolidBrush(RGB(255,0,0)),
  19. CreateSolidBrush(RGB(0,255,0)),
  20. CreateSolidBrush(RGB(0,0,255)),
  21. CreateSolidBrush(RGB(255,255,0)),
  22. CreateSolidBrush(RGB(255,0,255)),
  23. CreateSolidBrush(RGB(0,255,255)),
  24. CreateSolidBrush(RGB(127,0,0)),
  25. CreateSolidBrush(RGB(0,127,0)),
  26. CreateSolidBrush(RGB(0,0,127)),
  27. CreateSolidBrush(RGB(127,127,0)),
  28. CreateSolidBrush(RGB(127,0,127)),
  29. CreateSolidBrush(RGB(0,127,127)) };
  30. int figora = 2;
  31. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR plCmdLine, int mShowCMD)
  32. {
  33.  
  34.     wc.cbSize = sizeof(WNDCLASSEX);
  35.     wc.style = CS_HREDRAW | CS_VREDRAW;
  36.     wc.lpfnWndProc = WndProc;
  37.     wc.cbClsExtra = 0;
  38.     wc.cbWndExtra = 0;
  39.     wc.hInstance = hInstance;
  40.     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  41.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  42.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  43.     wc.lpszClassName = className;
  44.     wc.lpszMenuName = NULL;
  45.     wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
  46.  
  47.     if (RegisterClassEx(&wc))
  48.     {
  49.         if ((hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, className, L"Paint", WS_OVERLAPPEDWINDOW, 500, 300, 900, 700, NULL, NULL, hInstance, NULL)) != NULL)
  50.         {
  51.             ShowWindow(hwnd, mShowCMD);
  52.             UpdateWindow(hwnd);
  53.  
  54.             while (GetMessage(&msg, NULL, 0, 0))
  55.             {
  56.                 TranslateMessage(&msg);
  57.                 DispatchMessage(&msg);
  58.             }
  59.  
  60.         }
  61.         else
  62.             MessageBox(NULL, L"Error", L"Create Window", MB_OK);
  63.  
  64.     }
  65.     else
  66.         MessageBox(NULL, L"Error", L"Register CLASS", MB_OK);
  67.  
  68.  
  69.  
  70.     ShowWindow(hwnd, mShowCMD);
  71.     DestroyWindow(hwnd);
  72.     return 0;
  73. }
  74. LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
  75. {
  76.     GetClientRect(hwnd, &rect);
  77.     switch (msg)
  78.     {
  79.     case WM_SIZE:
  80.     {
  81.         UpdateWindow(hwnd);
  82.         break;
  83.     }
  84.     case WM_LBUTTONDOWN:
  85.     {
  86.         pojnt.x = LOWORD(lparam);
  87.         pojnt.y = HIWORD(lparam);
  88.         if (pojnt.x >= (rect.right - 110) && pojnt.x <= (rect.right - 79) && pojnt.y >= (rect.top + 310) && pojnt.y <= (rect.top + 341))
  89.             figora = 0;
  90.         else if (pojnt.x >= (rect.right - 73) && pojnt.x <= (rect.right - 42) && pojnt.y >= (rect.top + 310) && pojnt.y <= (rect.top + 341))
  91.             figora = 1;
  92.         else if (pojnt.x >= (rect.right - 36) && pojnt.x <= (rect.right - 5) && pojnt.y >= (rect.top + 310) && pojnt.y <= (rect.top + 341))
  93.             figora = 2;
  94.         InvalidateRect(hwnd, &rect, 0);
  95.         break;
  96.     }
  97.     case WM_RBUTTONDOWN:
  98.     {
  99.         InvalidateRect(hwnd, &rect, 2);
  100.         break;
  101.     }
  102.     case WM_PAINT:
  103.     {
  104.         hdc = BeginPaint(hwnd, &ps);
  105.         GetClientRect(hwnd, &rect);
  106.         if (pojnt.x >= (rect.right - 115) && pojnt.y <= (rect.top + 315))
  107.         {
  108.             COLORREF bg = GetPixel(hdc, pojnt.x, pojnt.y);
  109.             b2 = CreateSolidBrush(RGB(GetRValue(bg), GetGValue(bg), GetBValue(bg)));
  110.         }
  111.         if (pojnt.x <= (rect.right - 115) || pojnt.y >= (rect.top + 346))
  112.         {
  113.             SelectObject(hdc, b2);
  114.             switch (figora)
  115.             {
  116.             case 0:
  117.             {
  118.                 Rectangle(hdc, pojnt.x - 20, pojnt.y - 20, pojnt.x + 20, pojnt.y + 20);
  119.                 break;
  120.             }
  121.             case 1:
  122.             {
  123.                 trojkat[0] = pojnt;
  124.                 trojkat[0].y -= 15;
  125.                 trojkat[1] = pojnt;
  126.                 trojkat[1].x += 18;
  127.                 trojkat[1].y += 15;
  128.                 trojkat[2] = pojnt;
  129.                 trojkat[2].x -= 18;
  130.                 trojkat[2].y += 15;
  131.                 Polygon(hdc, trojkat, 3);
  132.                 break;
  133.             }
  134.             case 2:
  135.             {
  136.                 Ellipse(hdc, pojnt.x - 20, pojnt.y - 20, pojnt.x + 20, pojnt.y + 20);
  137.                 break;
  138.             }
  139.             }
  140.         }
  141.         b1 = CreateSolidBrush(RGB(255, 255, 255));
  142.         SelectObject(hdc, b1);
  143.         Rectangle(hdc, rect.right - 115, rect.top, rect.right, rect.top + 346);
  144.         p1 = CreatePen(PS_NULL, 1, RGB(0, 0, 0));
  145.         SelectObject(hdc, p1);
  146.         for (int i = 1; i<3; i++)
  147.             for (int j = 0; j<6; j++)
  148.             {
  149.                 b1 = brushes[(i - 1) * 6 + j];
  150.                 SelectObject(hdc, b1);
  151.                 Rectangle(hdc, rect.right - 110 / i, rect.top + 5 + 50 * j, rect.right - 110 / i + 50, rect.top + 55 + 50 * j);
  152.             }
  153.         p1 = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
  154.         SelectObject(hdc, p1);
  155.         b1 = CreateSolidBrush(RGB(255, 255, 255));
  156.         SelectObject(hdc, b1);
  157.         Rectangle(hdc, rect.right - 110, rect.top + 310, rect.right - 79, rect.top + 341);
  158.         Rectangle(hdc, rect.right - 73, rect.top + 310, rect.right - 42, rect.top + 341);
  159.         Rectangle(hdc, rect.right - 36, rect.top + 310, rect.right - 5, rect.top + 341);
  160.         b1 = CreateSolidBrush(RGB(0, 0, 0));
  161.         SelectObject(hdc, b1);
  162.         Rectangle(hdc, rect.right - 102, rect.top + 318, rect.right - 87, rect.top + 333);
  163.         MoveToEx(hdc, rect.right - 58, rect.top + 316, 0);
  164.         LineTo(hdc, rect.right - 48, rect.top + 333);
  165.         LineTo(hdc, rect.right - 67, rect.top + 333);
  166.         LineTo(hdc, rect.right - 58, rect.top + 316);
  167.         Ellipse(hdc, rect.right - 29, rect.top + 317, rect.right - 12, rect.top + 334);
  168.         //TextOutA(hdc,pojnt.x,pojnt.y,"TU KLIK",7);
  169.         //SetPixel(hdc,pojnt.x,pojnt.y,RGB(255,0,0));
  170.         EndPaint(hwnd, &ps);
  171.         UpdateWindow(hwnd);
  172.         break;
  173.     }
  174.     case WM_CLOSE:
  175.     {
  176.         if (MessageBox(hwnd, L"Zamkn��?", L"Allert", MB_YESNO | MB_ICONWARNING) == IDYES)
  177.         {
  178.             DestroyWindow(hwnd);
  179.         }
  180.         break;
  181.     }
  182.     case WM_DESTROY:
  183.     {
  184.         PostQuitMessage(0);
  185.         break;
  186.     }
  187.     default:
  188.     {
  189.         return DefWindowProc(hwnd, msg, wparam, lparam);
  190.     }
  191.     }
  192. }
Advertisement