bruno63 icon

Paint #1

bruno63 | PRO | 11/08/15 03:23:33 PM UTC | 0 ⭐ | 10318 👁️ | Never ⏰ | []
C++ (WinAPI) |

0 B

|

None

|

0 👍

/

0 👎

#include <Windows.h>
#include <string>
using namespace std;
 
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
 
LPTSTR className = L"nazwaKlasy";
WNDCLASSEX wc;// , wc2;
HWND hwnd, knefel;
MSG msg;
PAINTSTRUCT ps;
RECT rect;
HDC hdc;
POINT pojnt = { rect.right - 85,rect.top + 30 }, trojkat[3];
HPEN p1 = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
HBRUSH b1 = CreateSolidBrush(RGB(255, 255, 255));
HBRUSH b2 = CreateSolidBrush(RGB(255, 255, 255));
HBRUSH brushes[12] = { CreateSolidBrush(RGB(255,0,0)),
CreateSolidBrush(RGB(0,255,0)),
CreateSolidBrush(RGB(0,0,255)),
CreateSolidBrush(RGB(255,255,0)),
CreateSolidBrush(RGB(255,0,255)),
CreateSolidBrush(RGB(0,255,255)),
CreateSolidBrush(RGB(127,0,0)),
CreateSolidBrush(RGB(0,127,0)),
CreateSolidBrush(RGB(0,0,127)),
CreateSolidBrush(RGB(127,127,0)),
CreateSolidBrush(RGB(127,0,127)),
CreateSolidBrush(RGB(0,127,127)) };
int figora = 2;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR plCmdLine, int mShowCMD)
{
 
    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    wc.lpszClassName = className;
    wc.lpszMenuName = NULL;
    wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
 
    if (RegisterClassEx(&wc))
    {
        if ((hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, className, L"Paint", WS_OVERLAPPEDWINDOW, 500, 300, 900, 700, NULL, NULL, hInstance, NULL)) != NULL)
        {
            ShowWindow(hwnd, mShowCMD);
            UpdateWindow(hwnd);
 
            while (GetMessage(&msg, NULL, 0, 0))
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
 
        }
        else
            MessageBox(NULL, L"Error", L"Create Window", MB_OK);
 
    }
    else
        MessageBox(NULL, L"Error", L"Register CLASS", MB_OK);
 
 
 
    ShowWindow(hwnd, mShowCMD);
    DestroyWindow(hwnd);
    return 0;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
    GetClientRect(hwnd, &rect);
    switch (msg)
    {
    case WM_SIZE:
    {
        UpdateWindow(hwnd);
        break;
    }
    case WM_LBUTTONDOWN:
    {
        pojnt.x = LOWORD(lparam);
        pojnt.y = HIWORD(lparam);
        if (pojnt.x >= (rect.right - 110) && pojnt.x <= (rect.right - 79) && pojnt.y >= (rect.top + 310) && pojnt.y <= (rect.top + 341))
            figora = 0;
        else if (pojnt.x >= (rect.right - 73) && pojnt.x <= (rect.right - 42) && pojnt.y >= (rect.top + 310) && pojnt.y <= (rect.top + 341))
            figora = 1;
        else if (pojnt.x >= (rect.right - 36) && pojnt.x <= (rect.right - 5) && pojnt.y >= (rect.top + 310) && pojnt.y <= (rect.top + 341))
            figora = 2;
        InvalidateRect(hwnd, &rect, 0);
        break;
    }
    case WM_RBUTTONDOWN:
    {
        InvalidateRect(hwnd, &rect, 2);
        break;
    }
    case WM_PAINT:
    {
        hdc = BeginPaint(hwnd, &ps);
        GetClientRect(hwnd, &rect);
        if (pojnt.x >= (rect.right - 115) && pojnt.y <= (rect.top + 315))
        {
            COLORREF bg = GetPixel(hdc, pojnt.x, pojnt.y);
            b2 = CreateSolidBrush(RGB(GetRValue(bg), GetGValue(bg), GetBValue(bg)));
        }
        if (pojnt.x <= (rect.right - 115) || pojnt.y >= (rect.top + 346))
        {
            SelectObject(hdc, b2);
            switch (figora)
            {
            case 0:
            {
                Rectangle(hdc, pojnt.x - 20, pojnt.y - 20, pojnt.x + 20, pojnt.y + 20);
                break;
            }
            case 1:
            {
                trojkat[0] = pojnt;
                trojkat[0].y -= 15;
                trojkat[1] = pojnt;
                trojkat[1].x += 18;
                trojkat[1].y += 15;
                trojkat[2] = pojnt;
                trojkat[2].x -= 18;
                trojkat[2].y += 15;
                Polygon(hdc, trojkat, 3);
                break;
            }
            case 2:
            {
                Ellipse(hdc, pojnt.x - 20, pojnt.y - 20, pojnt.x + 20, pojnt.y + 20);
                break;
            }
            }
        }
        b1 = CreateSolidBrush(RGB(255, 255, 255));
        SelectObject(hdc, b1);
        Rectangle(hdc, rect.right - 115, rect.top, rect.right, rect.top + 346);
        p1 = CreatePen(PS_NULL, 1, RGB(0, 0, 0));
        SelectObject(hdc, p1);
        for (int i = 1; i<3; i++)
            for (int j = 0; j<6; j++)
            {
                b1 = brushes[(i - 1) * 6 + j];
                SelectObject(hdc, b1);
                Rectangle(hdc, rect.right - 110 / i, rect.top + 5 + 50 * j, rect.right - 110 / i + 50, rect.top + 55 + 50 * j);
            }
        p1 = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
        SelectObject(hdc, p1);
        b1 = CreateSolidBrush(RGB(255, 255, 255));
        SelectObject(hdc, b1);
        Rectangle(hdc, rect.right - 110, rect.top + 310, rect.right - 79, rect.top + 341);
        Rectangle(hdc, rect.right - 73, rect.top + 310, rect.right - 42, rect.top + 341);
        Rectangle(hdc, rect.right - 36, rect.top + 310, rect.right - 5, rect.top + 341);
        b1 = CreateSolidBrush(RGB(0, 0, 0));
        SelectObject(hdc, b1);
        Rectangle(hdc, rect.right - 102, rect.top + 318, rect.right - 87, rect.top + 333);
        MoveToEx(hdc, rect.right - 58, rect.top + 316, 0);
        LineTo(hdc, rect.right - 48, rect.top + 333);
        LineTo(hdc, rect.right - 67, rect.top + 333);
        LineTo(hdc, rect.right - 58, rect.top + 316);
        Ellipse(hdc, rect.right - 29, rect.top + 317, rect.right - 12, rect.top + 334);
        //TextOutA(hdc,pojnt.x,pojnt.y,"TU KLIK",7);
        //SetPixel(hdc,pojnt.x,pojnt.y,RGB(255,0,0));
        EndPaint(hwnd, &ps);
        UpdateWindow(hwnd);
        break;
    }
    case WM_CLOSE:
    {
        if (MessageBox(hwnd, L"Zamkn��?", L"Allert", MB_YESNO | MB_ICONWARNING) == IDYES)
        {
            DestroyWindow(hwnd);
        }
        break;
    }
    case WM_DESTROY:
    {
        PostQuitMessage(0);
        break;
    }
    default:
    {
        return DefWindowProc(hwnd, msg, wparam, lparam);
    }
    }
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎