void KisColorSelectorBase::canvasResourceChanged(int key, const QVariant &v)
{
    if (key == KoCanvasResourceManager::ForegroundColor || key == KoCanvasResourceManager::BackgroundColor) {
        KoColor realColor(v.value<KoColor>());
        updateColorPreview(realColor);
        if (m_colorUpdateAllowed && !m_colorUpdateSelf) {
            setColor(realColor);
        }
    }
}
Beispiel #2
0
void KisColorSelector::mouseEvent(QMouseEvent *e)
{
    if (m_grabbingComponent && (e->buttons() & Qt::LeftButton || e->buttons() & Qt::RightButton)) {

        m_grabbingComponent->mouseEvent(e->x(), e->y());

        KoColor color = m_mainComponent->currentColor();
        m_currentRealColor = color;
        updateColorPreview(color);

        Acs::ColorRole role = Acs::buttonsToRole(e->button(), e->buttons());
        updateColor(color, role, false);
    }
}
void KisColorPatches::mousePressEvent(QMouseEvent *event)
{
    KoColor koColor;
    if(!colorAt(event->pos(), &koColor))
        return;

    KisColorSelectorBase::mousePressEvent(event);
    if(event->isAccepted())
        return;

    updateColorPreview(koColor.toQColor());

    if (event->button() == Qt::LeftButton)
        m_dragStartPos = event->pos();
}
Beispiel #4
0
LRESULT CALLBACK WindowProcedure(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {

    static HWND hwndEraserWeight;
    static HWND hwndStrokeWeight;
    static HWND hwndPenTool;
    static HWND hwndLineTool;
    static HWND hwndPolygonTool;
    static HWND hwndEllipseTool;
    static HWND hwndBezierTool;
    static HWND hwndEraserTool;
    static HWND hwndFillCheck;

    static POINT pen;
    static BOOL firstLine;
    static POINT newLine;
    static BOOL firstPolygon;
    static RECT newPolygon;
    static BOOL firstEllipse;
    static RECT newEllipse;
    static BOOL firstBezier;
    static BOOL secondBezier;
    static BOOL thirdBezier;
    static POINT pointsforBezier[4];
    static HRGN lastRegion;
    static BOOL regionDeleted;

    int xMouse, yMouse;

    static RECT drawingArea = {15, 180, 580, 640};

    RECT rectRED     = {255, 100, 375, 115};
    RECT rectGREEN   = {255, 120, 375, 135};
    RECT rectBLUE    = {255, 140, 375, 155};
    RECT rectTemp;

    HDC hdc = GetDC(hwnd);
    COLORREF strokeRGB;
    int strokeWeight;
    COLORREF fillRGB;
    HBRUSH fillBrush;
    PAINTSTRUCT ps;
    HPEN strokePen;
    POINT point;
    RECT rect;

    HBRUSH hBrush;
    int xFillPreview =240 ;
    int yFillPreview = 50;
    int xStrokePreview = 320;
    int yStrokePreview = 50;
    UINT fillRED      = 255;
    UINT fillGREEN    = 255;
    UINT fillBLUE     = 255;
    UINT strokeRED    = 0;
    UINT strokeGREEN  = 0;
    UINT strokeBLUE   = 0;

    HDC hdcMem;
    BITMAP bitmap;
    HBITMAP hbmpimage = NULL;
    hbmpimage = (HBITMAP)LoadImage(hInstance, "aesthetic1.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    GetObject(hbmpimage, sizeof(bitmap), &bitmap);

    switch(message) {

        case WM_CREATE:

            CreateWindowEx(
                0,
                "Button",
                "Tools",
                WS_VISIBLE | WS_CHILD | BS_GROUPBOX,
                5, 5,
                100, 160,
                hwnd,
                0,
                hInstance,
                NULL);

            CreateWindowEx(
                0,
                "Button",
                "Style",
                WS_VISIBLE | WS_CHILD | BS_GROUPBOX,
                520, 5,
                135, 120,
                hwnd,
                0,
                hInstance,
                NULL);

            CreateWindowEx(
                0,
                "Button",
                "Color",
                WS_VISIBLE | WS_CHILD | BS_GROUPBOX,
                220, 5,
                180, 160,
                hwnd,
                0,
                hInstance,
                NULL);

            CreateWindowEx(
                0,
                "Static",
                "Fill",
                WS_VISIBLE | WS_CHILD | SS_CENTER,
                240, 25,
                45, 20,
                hwnd,
                (HMENU)0,
                hInstance,
                NULL);

            CreateWindowEx(
                0,
                "Static",
                "Stroke",
                WS_VISIBLE | WS_CHILD | SS_CENTER,
                320, 25,
                45, 20,
                hwnd,
                (HMENU)0,
                hInstance,
                NULL);

            CreateWindowEx(
                0,
                "Static",
                "R",
                WS_VISIBLE | WS_CHILD | SS_LEFT,
                240, 100,
                10, 15,
                hwnd,
                (HMENU)0,
                hInstance,
                NULL);

            CreateWindowEx(
                0,
                "Static",
                "G",
                WS_VISIBLE | WS_CHILD | SS_LEFT,
                240, 120,
                10, 15,
                hwnd,
                (HMENU)0,
                hInstance,
                NULL);

            CreateWindowEx(
                0,
                "Static",
                "B",
                WS_VISIBLE | WS_CHILD | SS_LEFT,
                240, 140,
                10, 15,
                hwnd,
                (HMENU)0,
                hInstance,
                NULL);

            hwndPenTool = CreateWindowEx(
                0,
                "Button",
                "Pen",
                WS_VISIBLE | WS_CHILD | WS_GROUP | BS_AUTORADIOBUTTON,
                15, 30,
                80, 18,
                hwnd,
                (HMENU)IDB_PEN,
                hInstance,
                NULL);

            Button_SetCheck(hwndPenTool, BST_CHECKED);

            hwndLineTool = CreateWindowEx(
                0,
                "Button",
                "Line",
                WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON,
                15, 55,
                80, 18,
                hwnd,
                (HMENU)IDB_LINE,
                hInstance,
                NULL);

            hwndPolygonTool = CreateWindowEx(
                0,
                "Button",
                "Polygon",
                WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON,
                15, 80,
                80, 18,
                hwnd,
                (HMENU)IDB_POLYGON,
                hInstance,
                NULL);

            hwndEllipseTool = CreateWindowEx(
                0,
                "Button",
                "Ellipse",
                WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON,
                15, 105,
                80, 18,
                hwnd,
                (HMENU)IDB_ELLIPSE,
                hInstance,
                NULL);

            hwndBezierTool = CreateWindowEx(
                0,
                "Button",
                "Bezier",
                WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON,
                15, 130,
                80, 18,
                hwnd,
                (HMENU)IDB_BEZIER,
                hInstance,
                NULL);

            hwndFillCheck = CreateWindowEx(
                0,
                "Button",
                "Fill",
                WS_VISIBLE | WS_CHILD | BS_AUTOCHECKBOX,
                530, 30,
                80, 18,
                hwnd,
                (HMENU)0,
                hInstance,
                NULL);

            CreateWindowEx(
                0,
                "Static",
                "Stroke",
                WS_VISIBLE | WS_CHILD,
                530, 60,
                80, 20,
                hwnd,
                (HMENU)0,
                hInstance,
                NULL);

            hwndStrokeWeight = CreateWindowEx(
                0,
                "Edit",
                "1",
                WS_VISIBLE | WS_CHILD | WS_BORDER | SS_CENTER,
                620, 60,
                20, 20,
                hwnd,
                (HMENU)0,
                hInstance,
                NULL);

            hwndEraserTool = CreateWindowEx(
                0,
                "Button",
                "Eraser",
                WS_VISIBLE | WS_CHILD | BS_AUTORADIOBUTTON,
                530, 90,
                80, 20,
                hwnd,
                (HMENU)IDB_ERASER,
                hInstance,
                NULL);

            hwndEraserWeight = CreateWindowEx(
                0,
                "Edit",
                "1",
                WS_VISIBLE | WS_CHILD | WS_BORDER | SS_CENTER,
                620, 90,
                20, 20,
                hwnd, (HMENU)0,
                hInstance,
                NULL);
            return 0;

        case WM_COMMAND:
            switch (LOWORD(wParam)) {
                default:
                    DefWindowProc(hwnd, WM_COMMAND, wParam, lParam);
                    break;
            }
            return 0;

        case WM_LBUTTONDOWN:
            xMouse = GET_X_LPARAM(lParam);
            yMouse = GET_Y_LPARAM(lParam);

            if((xMouse > rectRED.left)&&(xMouse <= rectRED.right)) {
                strokeRGB = GetPixel(hdc, xStrokePreview + 20, yStrokePreview + 20);

                if((yMouse > rectRED.top)&&(yMouse <= rectRED.bottom)) {
                    strokeRED = (xMouse - rectRED.left) * 255 / (rectRED.right - rectRED.left);
                    strokeGREEN = GetGValue(strokeRGB);
                    strokeBLUE = GetBValue(strokeRGB);
                    updateColorPreview(hdc, RGB(strokeRED, strokeGREEN, strokeBLUE), xStrokePreview, yStrokePreview);
                }

                else if((yMouse > rectGREEN.top)&&(yMouse <= rectGREEN.bottom)) {
                    strokeRED = GetRValue(strokeRGB);
                    strokeGREEN = (xMouse - rectGREEN.left) * 255 / (rectGREEN.right - rectGREEN.left);
                    strokeBLUE = GetBValue(strokeRGB);
                    updateColorPreview(hdc, RGB(strokeRED, strokeGREEN, strokeBLUE), xStrokePreview, yStrokePreview);
                }

                else if((yMouse > rectBLUE.top)&&(yMouse <= rectBLUE.bottom)) {
                    strokeRED = GetRValue(strokeRGB);
                    strokeGREEN = GetGValue(strokeRGB);
                    strokeBLUE = (xMouse - rectBLUE.left) * 255 / (rectBLUE.right - rectBLUE.left);
                    updateColorPreview(hdc, RGB(strokeRED, strokeGREEN, strokeBLUE), xStrokePreview, yStrokePreview);
                }
                return 0;
            }

                if((xMouse > drawingArea.left)&&(xMouse < drawingArea.right)&&(yMouse > drawingArea.top)&&(yMouse < drawingArea.bottom)) {
                strokeWeight = getWeight(hwndStrokeWeight);
                point = drawingLimits(xMouse, yMouse, drawingArea, strokeWeight);
                xMouse = point.x;
                yMouse = point.y;

                if((wParam == MK_LBUTTON)&&(Button_GetCheck(hwndPenTool) == BST_CHECKED)) {
                    pen.x = xMouse;
                    pen.y = yMouse;
                }

                if((wParam == MK_LBUTTON)&&(Button_GetCheck(hwndLineTool) == BST_CHECKED)) {
                    newLine.x = xMouse;
                    newLine.y = yMouse;
                    firstLine = true;
                }

                if((wParam == MK_LBUTTON)&&(Button_GetCheck(hwndPolygonTool) == BST_CHECKED)) {
                    newPolygon.left = xMouse;
                    newPolygon.top = yMouse;
                    firstPolygon = true;
                }

                if((wParam == MK_LBUTTON)&&(Button_GetCheck(hwndEllipseTool) == BST_CHECKED)) {
                    newEllipse.left = xMouse;
                    newEllipse.top = yMouse;
                    firstEllipse = true;
                }

                if((wParam == MK_LBUTTON)&&(Button_GetCheck(hwndBezierTool) == BST_CHECKED)) {
                    pointsforBezier[0] = point;
                    firstBezier  = true;
                    secondBezier = false;
                    thirdBezier  = false;
                }
            }
            return 0;

        case WM_LBUTTONUP:

            xMouse = GET_X_LPARAM(lParam);
            yMouse = GET_Y_LPARAM(lParam);

            strokeRGB = GetPixel(hdc, xStrokePreview + 20, yStrokePreview + 20);
            fillRGB = GetPixel(hdc, xFillPreview + 20, yFillPreview + 20);
            strokeWeight = getWeight(hwndStrokeWeight);

            if(firstLine) {
                point = drawingLimits(xMouse, yMouse, drawingArea, strokeWeight);
                xMouse = point.x;
                yMouse = point.y;

                strokePen = CreatePen(PS_SOLID, strokeWeight, strokeRGB);
                SelectObject(hdc, strokePen);
                MoveToEx(hdc, xMouse, yMouse, NULL);
                LineTo(hdc, newLine.x, newLine.y);
                DeleteObject(strokePen);

                firstLine = false;
            }

            if(firstPolygon) {
                point = drawingLimits(xMouse, yMouse, drawingArea, strokeWeight);
                newPolygon.right = point.x;
                newPolygon.bottom = point.y;

                strokePen = CreatePen(PS_SOLID, strokeWeight, strokeRGB);
                fillBrush = (Button_GetCheck(hwndFillCheck) == BST_CHECKED)? CreateSolidBrush(fillRGB) : (HBRUSH)GetStockObject(NULL_BRUSH);
                SelectObject(hdc, strokePen);
                SelectObject(hdc, fillBrush);
                Rectangle(hdc, newPolygon.left, newPolygon.top, newPolygon.right, newPolygon.bottom);
                DeleteObject(strokePen);
                DeleteObject(fillBrush);

                lastRegion = getLastRectRegion(newPolygon, strokeWeight, &regionDeleted);

                firstPolygon = false;
            }

            if(firstEllipse) {
                point = drawingLimits(xMouse, yMouse, drawingArea, strokeWeight);
                newEllipse.right = point.x;
                newEllipse.bottom = point.y;

                strokePen = CreatePen(PS_SOLID, strokeWeight, strokeRGB);
                fillBrush = (Button_GetCheck(hwndFillCheck) == BST_CHECKED)? CreateSolidBrush(fillRGB) : (HBRUSH)GetStockObject(NULL_BRUSH);
                SelectObject(hdc, strokePen);
                SelectObject(hdc, fillBrush);
                Ellipse(hdc, newEllipse.left, newEllipse.top, newEllipse.right, newEllipse.bottom);
                DeleteObject(strokePen);
                DeleteObject(fillBrush);

                lastRegion = getLastEllipticRegion(newEllipse, strokeWeight, &regionDeleted);

                firstEllipse = false;
            }

            if(firstBezier) {
                point = drawingLimits(xMouse, yMouse, drawingArea, strokeWeight);
                pointsforBezier[1] = point;
                firstBezier  = false;
                secondBezier = true;
                thirdBezier  = false;
            }
            return 0;

        case WM_RBUTTONDOWN:
            xMouse = GET_X_LPARAM(lParam);
            yMouse = GET_Y_LPARAM(lParam);

            if((xMouse > rectRED.left)&&(xMouse <= rectRED.right)) {
                fillRGB = GetPixel(hdc, xFillPreview + 20, yFillPreview + 20);

                if((yMouse > rectRED.top)&&(yMouse <= rectRED.bottom)) {
                    fillRED = (xMouse - rectRED.left) * 255 / (rectRED.right - rectRED.left);
                    fillGREEN = GetGValue(fillRGB);
                    fillBLUE = GetBValue(fillRGB);
                    updateColorPreview(hdc, RGB(fillRED, fillGREEN, fillBLUE), xFillPreview, yFillPreview);
                }

                else if((yMouse > rectGREEN.top)&&(yMouse <= rectGREEN.bottom)) {
                    fillRED = GetRValue(fillRGB);
                    fillGREEN = (xMouse - rectGREEN.left) * 255 / (rectGREEN.right - rectGREEN.left);
                    fillBLUE = GetBValue(fillRGB);
                    updateColorPreview(hdc, RGB(fillRED, fillGREEN, fillBLUE), xFillPreview, yFillPreview);
                }

                else if((yMouse > rectBLUE.top)&&(yMouse <= rectBLUE.bottom)) {
                    fillRED = GetRValue(fillRGB);
                    fillGREEN = GetGValue(fillRGB);
                    fillBLUE = (xMouse - rectBLUE.left) * 255 / (rectBLUE.right - rectBLUE.left);
                    updateColorPreview(hdc, RGB(fillRED, fillGREEN, fillBLUE), xFillPreview, yFillPreview);
                }
                return 0;
            }

            if((xMouse > drawingArea.left)&&(xMouse < drawingArea.right)&&(yMouse > drawingArea.top)&&(yMouse < drawingArea.bottom)) {
                strokeWeight = getWeight(hwndStrokeWeight);
                point = drawingLimits(xMouse, yMouse, drawingArea, strokeWeight);
                xMouse = point.x;
                yMouse = point.y;

                if((wParam == MK_RBUTTON)&&(Button_GetCheck(hwndBezierTool) == BST_CHECKED)&&(secondBezier)) {
                    pointsforBezier[2] = point;
                    firstBezier  = false;
                    secondBezier = false;
                    thirdBezier  = true;
                }
            }
            if(regionDeleted) {
                InvalidateRgn(hwnd, lastRegion, TRUE);
                DeleteObject(lastRegion);
                regionDeleted = false;
            }
            return 0;

        case WM_RBUTTONUP:
            xMouse = GET_X_LPARAM(lParam);
            yMouse = GET_Y_LPARAM(lParam);
            strokeRGB = GetPixel(hdc, xStrokePreview + 20, yStrokePreview + 20);
            fillRGB = GetPixel(hdc, xFillPreview + 20, yFillPreview + 20);
            strokeWeight = getWeight(hwndStrokeWeight);
            point = drawingLimits(xMouse, yMouse, drawingArea, strokeWeight);
            xMouse = point.x;
            yMouse = point.y;

            if(thirdBezier) {
                pointsforBezier[3] = point;
                strokePen = CreatePen(PS_SOLID, strokeWeight, strokeRGB);
                SelectObject(hdc, strokePen);
                PolyBezier(hdc, pointsforBezier, 4);
                DeleteObject(strokePen);
                firstBezier  = false;
                secondBezier = false;
                thirdBezier  = false;
            }
            return 0;

        case WM_MOUSEMOVE:
            xMouse = GET_X_LPARAM(lParam);
            yMouse = GET_Y_LPARAM(lParam);

            if((xMouse > drawingArea.left)&&(xMouse < drawingArea.right)
                &&(yMouse > drawingArea.top)&&(yMouse < drawingArea.bottom)) {
                strokeRGB = GetPixel(hdc, xStrokePreview + 20, yStrokePreview + 20);
                fillRGB   = GetPixel(hdc, xStrokePreview + 20, yStrokePreview + 20);

                if((wParam == MK_LBUTTON)&&(Button_GetCheck(hwndPenTool) == BST_CHECKED)) {
                    strokePen = CreatePen(PS_SOLID, 1, strokeRGB);
                    SelectObject(hdc, strokePen);
                    MoveToEx(hdc, xMouse, yMouse, NULL);
                    LineTo(hdc, pen.x, pen.y);
                    DeleteObject(strokePen);
                    pen.x = xMouse;
                    pen.y = yMouse;
                }

                if((wParam == MK_LBUTTON)&&(Button_GetCheck(hwndEraserTool) == BST_CHECKED)) {
                    strokeWeight = getWeight(hwndEraserWeight);
                    point = drawingLimits(xMouse, yMouse, drawingArea, strokeWeight);
                    xMouse = point.x;
                    yMouse = point.y;
                    rect.left = point.x - (strokeWeight/2);
                    rect.right = point.x + (strokeWeight/2);
                    rect.top = point.y - (strokeWeight/2);
                    rect.bottom = point.y + (strokeWeight/2);
                    InvalidateRect(hwnd, &rect, FALSE);
                    SendMessage(hwnd, WM_PAINT, 0, 0);
                    ValidateRect(hwnd, &rect);
                }
            }
            return 0;

        case WM_PAINT:
            hdc = BeginPaint(hwnd, &ps);

            updateColorPreview(hdc, RGB(255, 255, 255), xFillPreview, yFillPreview);

            updateColorPreview(hdc, RGB(0, 0, 0), xStrokePreview, yStrokePreview);

            hdcMem = CreateCompatibleDC(hdc);
            SelectObject(hdcMem, hbmpimage);
            BitBlt(hdc, 600, 40, 280, 600, hdcMem, 0, 0, SRCCOPY);
            DeleteDC(hdcMem);

            rectTemp.top = rectRED.top;
            rectTemp.bottom = rectRED.bottom;
            for(int i = 0; i < (rectRED.right - rectRED.left); i++) {
                int r;
                r = i * 255 / (rectRED.right - rectRED.left);
                rectTemp.left  = rectRED.left  + i;
                rectTemp.right = rectRED.left + i + 1;
                hBrush = CreateSolidBrush(RGB(r, 0, 0));
                FillRect(hdc, &rectTemp, hBrush);
                DeleteObject(hBrush);
            }

            rectTemp.top = rectGREEN.top;
            rectTemp.bottom = rectGREEN.bottom;
            for(int i = 0; i < (rectGREEN.right - rectGREEN.left); i++) {
                int g;
                g = i * 255 / (rectGREEN.right - rectGREEN.left);
                rectTemp.left  = rectGREEN.left  + i;
                rectTemp.right = rectGREEN.left + i + 1;
                hBrush = CreateSolidBrush(RGB(0, g, 0));
                FillRect(hdc, &rectTemp, hBrush);
                DeleteObject(hBrush);
            }

            rectTemp.top = rectBLUE.top;
            rectTemp.bottom = rectBLUE.bottom;
            for(int i = 0; i < (rectBLUE.right - rectBLUE.left); i++) {
                int b;
                b = i * 255 / (rectBLUE.right - rectBLUE.left);
                rectTemp.left  = rectBLUE.left  + i;
                rectTemp.right = rectBLUE.left + i + 1;
                hBrush = CreateSolidBrush(RGB(0, 0, b));
                FillRect(hdc, &rectTemp, hBrush);
                DeleteObject(hBrush);
            }

            SelectObject(hdc, CreatePen(PS_SOLID, 1, RGB(0,0,0)));
            SelectObject(hdc, (HBRUSH)GetStockObject(WHITE_BRUSH));
            Rectangle(hdc, drawingArea.left, drawingArea.top, drawingArea.right, drawingArea.bottom);

            EndPaint(hwnd, &ps);
            return 0;

        case WM_DESTROY:
            PostQuitMessage (0);
            return 0;

        default:
            return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}
/*  This function is called by the Windows function DispatchMessage()  */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
    static HWND hwndButton1, hwndButton2, hwndButton3, hwndButton4, hwndButton5, hwndButton6, hwndButton7;
    static HWND hwndCheckBox3, hwndCheckBox5, hwndCheckBox6;
    static HBITMAP hBitmap;
    static int cxClient, cyClient, cxSource, cySource;
    BITMAP bitmap;
    HDC hdc, hdcMem;
    int x, y;
    PAINTSTRUCT ps;
    LPDRAWITEMSTRUCT pdis;
    POINT pt[3];
    RECT rc,rect, rectTemp;
    HPEN hPen;
    HBRUSH hBrush;
    HBRUSH hbr;

    UINT coll = 0;
    COLORREF colRef;

    HDC hDC = GetDC(hwnd);
	static BOOL IsDrawing = FALSE;
	static int StartX, StartY;
	static int EndX, EndY;

	static BOOL isLine, isFreeHand, isEllipse, isTriangle, isRectangle, isEraser;
    int state;

    switch (message) {                                                           /* handle the messages */

        case WM_CREATE:
            hBitmap = LoadBitmap (hInst, TEXT ("header"));
            GetObject (hBitmap, sizeof (BITMAP), &bitmap);
            cxSource = bitmap.bmWidth;
            cySource = bitmap.bmHeight;

            hwndButton1 = CreateWindow ( TEXT("BUTTON"), TEXT (""),
                                        WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,
                                        50, 60, 30, 30,
                                        hwnd, (HMENU) IDB_BUTTON1, hInst, NULL);
            hwndButton2 = CreateWindow ( TEXT("BUTTON"), TEXT (""),
                                        WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,
                                        50, 95, 30, 30,
                                        hwnd, (HMENU) IDB_BUTTON2, hInst, NULL);
            hwndCheckBox3 = CreateWindow ( TEXT("BUTTON"), TEXT (""),
                                          WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
                                          20, 130, 13, 13,
                                          hwnd, (HMENU) IDR_RADIOBUTTON3, hInst, NULL);
            hwndButton3 = CreateWindow ( TEXT("BUTTON"), TEXT (""),
                                        WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,
                                        50, 130, 30, 30,
                                        hwnd, (HMENU) IDB_BUTTON3, hInst, NULL);
            hwndButton4 = CreateWindow ( TEXT("BUTTON"), TEXT (""),
                                        WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,
                                        50, 165, 30, 30,
                                        hwnd, (HMENU) IDB_BUTTON4, hInst, NULL);
            hwndCheckBox5 = CreateWindow ( TEXT("BUTTON"), TEXT (""),
                                          WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
                                          20, 200, 13, 13,
                                          hwnd, (HMENU) IDR_RADIOBUTTON5, hInst, NULL);
            hwndButton5 = CreateWindow ( TEXT("BUTTON"), TEXT (""),
                                        WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,
                                        50, 200, 30, 30,
                                        hwnd, (HMENU) IDB_BUTTON5, hInst, NULL);
            hwndCheckBox6 = CreateWindow ( TEXT("BUTTON"), TEXT (""),
                                          WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
                                          20, 235, 13, 13,
                                          hwnd, (HMENU) IDR_RADIOBUTTON6, hInst, NULL);
            hwndButton6 = CreateWindow ( TEXT("BUTTON"), TEXT (""),
                                        WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,
                                        50, 235, 30, 30,
                                        hwnd, (HMENU) IDB_BUTTON6, hInst, NULL);
            hwndButton7 = CreateWindow ( TEXT("BUTTON"), TEXT (""),
                                        WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,
                                        50, 270, 30, 30,
                                        hwnd, (HMENU) IDB_BUTTON7, hInst, NULL);
            return 0 ;
        case WM_DRAWITEM :
            pdis = (LPDRAWITEMSTRUCT) lParam;
            FillRect (pdis->hDC, &pdis->rcItem, (HBRUSH) GetStockObject (WHITE_BRUSH));
            FrameRect (pdis->hDC, &pdis->rcItem, (HBRUSH) GetStockObject (BLACK_BRUSH));
            switch (pdis->CtlID) {
                case IDB_BUTTON1 :

                    hPen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
                    SelectObject(pdis->hDC, hPen);
                    MoveToEx (pdis->hDC, 5, 18, NULL) ;
                    LineTo (pdis->hDC, 19, 4) ;

                    hPen = CreatePen(PS_SOLID, 2, RGB(0, 0, 0));
                    SelectObject(pdis->hDC, hPen);
                    MoveToEx (pdis->hDC, 8, 21, NULL) ;
                    LineTo (pdis->hDC, 22, 7) ;

                    hPen = CreatePen(PS_SOLID, 3, RGB(0, 0, 0));
                    SelectObject(pdis->hDC, hPen);
                    MoveToEx (pdis->hDC, 11, 25, NULL);
                    LineTo (pdis->hDC, 25, 11);
                    break;
                case IDB_BUTTON2 :
                    pt[0].x = 3; pt[0].y = 3;
                    pt[1].x = 3; pt[1].y = 27;
                    pt[2].x = 27; pt[2].y = 15;
                    pt[3].x = 27; pt[3].y = 3;
                    DrawBezier (pdis->hDC, pt);
                    break;
                case IDB_BUTTON3 :
                    state = SendMessage(hwndCheckBox3, BM_GETCHECK, 0, 0);
                    if(state == BST_CHECKED) {
                        Circle (pdis->hDC, 3, 3, 24, true);
                    } else {
                        Circle (pdis->hDC, 3, 3, 24, false);
                    }
                    break;
                case IDB_BUTTON4 :

                    hPen = CreatePen(PS_SOLID, 3, RGB(0, 0, 0));
                    SelectObject(pdis->hDC, hPen);
                    MoveToEx (pdis->hDC, 8, 21, NULL) ;
                    LineTo (pdis->hDC, 22, 7) ;

                    hPen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
                    SelectObject(pdis->hDC, hPen);
                    MoveToEx (pdis->hDC, 8, 21, NULL);
                    LineTo (pdis->hDC, 3, 24);
                    break;
                case IDB_BUTTON5 :

                    pt[0].x = 4;  pt[0].y = 26;
                    pt[1].x = 26; pt[1].y = 26;
                    pt[2].x = 15; pt[2].y = 3;
                    Triangle (pdis->hDC, pt);
                    break;
                case IDB_BUTTON6 :

                    pt[0].x = 3; pt[0].y = 3;
                    pt[1].x = 3; pt[1].y = 26;
                    pt[2].x = 26; pt[2].y = 26;
                    pt[3].x = 26; pt[3].y = 3;
                    Rectangle(pdis->hDC, pt);
                    break;
                case IDB_BUTTON7 :

                    pt[0].x = 3; pt[0].y = 20;
                    pt[1].x = 6; pt[1].y = 15;
                    pt[2].x = 16; pt[2].y = 15;
                    pt[3].x = 13; pt[3].y = 20;
                    Rectangle(pdis->hDC, pt);

                    hPen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
                    SelectObject(pdis->hDC, hPen);
                    MoveToEx (pdis->hDC, 6, 15, NULL);
                    LineTo (pdis->hDC, 15, 11);
                    MoveToEx (pdis->hDC, 16, 15, NULL);
                    LineTo (pdis->hDC, 25, 11);
                    MoveToEx (pdis->hDC, 13, 20, NULL);
                    LineTo (pdis->hDC, 22, 16);
                    MoveToEx (pdis->hDC, 15, 11, NULL);
                    LineTo (pdis->hDC, 25, 11);
                    MoveToEx (pdis->hDC, 25, 11, NULL);
                    LineTo (pdis->hDC, 21, 17);
                    break;
            }

            if (pdis->itemState & ODS_SELECTED)
                InvertRect (pdis->hDC, &pdis->rcItem);
            if (pdis->itemState & ODS_FOCUS)                            // Draw a focus rectangle if the button has the focus
                DrawFocusRect (pdis->hDC, &pdis->rcItem) ;
            return 0;
        case WM_LBUTTONDOWN:

                if((LOWORD(lParam) > 15) && (HIWORD(lParam) > 400) &&
                   (LOWORD(lParam) < 90) && (HIWORD(lParam) <550) ) {
                    coll = 255* (HIWORD(lParam) - 400)/150;
                    updateColorPreview(hDC, RGB(coll, coll, coll), 15, 350);
                    colRef = RGB(coll, coll, coll);
                    return 0;
                }
                hDC = GetDC(hwnd);
                StartX = LOWORD(lParam);
                StartY = HIWORD(lParam);
                EndX = LOWORD(lParam);
                EndY = HIWORD(lParam);
                if(isLine) {
                    hPen = CreatePen(PS_SOLID, 1, colRef);
                    hbr = CreateSolidBrush(colRef);
                    SelectObject(hDC, hPen);
                    SelectObject(hDC, hbr);
                    SetROP2(hDC, R2_XORPEN);
                    MoveToEx(hDC, StartX, StartY, NULL);
                    LineTo(hDC, EndX, EndY);
                    IsDrawing = TRUE;
					DeleteObject(hPen);
                    DeleteObject(hbr);
                }
                if(isFreeHand) {
                    hPen = CreatePen(PS_SOLID, 1, colRef);
                    hbr = CreateSolidBrush(colRef);
                    SelectObject(hDC, hPen);
                    SelectObject(hDC, hbr);
                    StartX = LOWORD(lParam);
                    StartY = HIWORD(lParam);
                    IsDrawing = TRUE;
					DeleteObject(hPen);
                    DeleteObject(hbr);
                }
                if(isEllipse){
                    state = SendMessage(hwndCheckBox3, BM_GETCHECK, 0, 0);
                    hPen = CreatePen(PS_SOLID, 1, colRef);
                    if(state){
                        hbr = CreateSolidBrush(colRef);
                        SelectObject(hDC, hbr);
                    } else {
                        hbr = (HBRUSH)GetStockObject(NULL_BRUSH);
                        SelectObject(hDC, hbr);
                    }
                    SelectObject(hDC, hPen);
                    SetROP2(hDC, R2_XORPEN);
                    Ellipse(hDC, StartX, StartY, EndX, EndY);
                    ReleaseDC(hwnd, hDC);
                    IsDrawing = TRUE;
            		DeleteObject(hPen);
                    DeleteObject(hbr);
                }
                if (isTriangle) {
                    state = SendMessage(hwndCheckBox5, BM_GETCHECK, 0, 0);
                    hPen = CreatePen(PS_SOLID, 1, colRef);
                    if (state){
                        hbr = CreateSolidBrush(colRef);
                        SelectObject(hDC, hbr);
                    } else {
                        hbr = (HBRUSH)GetStockObject(NULL_BRUSH);
                        SelectObject(hDC, hbr);
                    }
                    SelectObject(hDC, hPen);
                    SetROP2(hDC, R2_XORPEN);

                    pt[0].x = StartX;  pt[0].y = EndY;
                    pt[1].x = (EndX + StartX) / 2; pt[1].y = StartY;
                    pt[2].x = EndX; pt[2].y = EndY;
                    Triangle(hDC, pt);
                    ReleaseDC(hwnd, hDC);
                    IsDrawing = TRUE;
            		DeleteObject(hPen);
                    DeleteObject(hbr);
                }
                if (isRectangle) {
                    hPen = CreatePen(PS_SOLID, 1, colRef);
                    state = SendMessage(hwndCheckBox6, BM_GETCHECK, 0, 0);
                    if (state) {
                        hbr = CreateSolidBrush(colRef);
                    } else {
                        hbr = (HBRUSH)GetStockObject(NULL_BRUSH);
                    }
                    SelectObject(hDC, hbr);
                    SelectObject(hDC, hPen);
                    SetROP2(hDC, R2_XORPEN);

                    pt[0].x = StartX; pt[0].y = StartY;
                    pt[1].x = StartX; pt[1].y = EndY;
                    pt[2].x = EndX; pt[2].y = EndY;
                    pt[3].x = EndX; pt[3].y = StartY;
                    Rectangle(hDC, pt);
                    ReleaseDC(hwnd, hDC);
                    IsDrawing = TRUE;
            		DeleteObject(hPen);
                    DeleteObject(hbr);
                }
                if (isEraser) {
                    rect.left = StartX - 15;
                    rect.right = StartX + 15;
                    rect.top = StartY - 15;
                    rect.bottom = StartY + 15 ;
                    InvalidateRect(hwnd, &rect, FALSE);
                    SendMessage(hwnd, WM_PAINT, 0, 0);
                    ValidateRect(hwnd, &rect);
                }
                ReleaseDC(hwnd, hDC);
                return 0;

        case WM_MOUSEMOVE:

            if(IsDrawing) {
                hDC = GetDC(hwnd);

                if(isLine) {
                    hPen = CreatePen(PS_SOLID, 1, colRef);
                    SelectObject(hDC, hPen);
                    SetROP2(hDC, R2_NOTXORPEN);
                    MoveToEx(hDC, StartX, StartY, NULL);
                    LineTo(hDC, EndX, EndY);
                    EndX = LOWORD(lParam);
                    EndY = HIWORD(lParam);
                    MoveToEx(hDC, StartX, StartY, NULL);
                    LineTo(hDC, EndX, EndY);
					DeleteObject(hPen);
                }
                if(isFreeHand)  {
                    hPen = CreatePen(PS_SOLID, 1, colRef);
                    SelectObject(hDC, hPen);
                    MoveToEx(hDC, EndX, EndY, NULL);
				    EndX = LOWORD(lParam);
				    EndY = HIWORD(lParam);
				    LineTo(hDC, EndX, EndY);
					DeleteObject(hPen);
                }
                if(isEllipse) {
                    hPen = CreatePen(PS_SOLID, 1, colRef);
                    state = SendMessage(hwndCheckBox3, BM_GETCHECK, 0, 0);
                    if(state) {
                        hbr = CreateSolidBrush(colRef);
                    } else {
                        hbr = (HBRUSH)GetStockObject(NULL_BRUSH);
                    }
                    SelectObject(hDC, hbr);
                    SelectObject(hDC, hPen);
                    SetROP2(hDC, R2_NOTXORPEN);
                    Ellipse(hDC, StartX, StartY, EndX, EndY);
                    EndX = LOWORD(lParam);
                    EndY = HIWORD(lParam);
                    Ellipse(hDC, StartX, StartY, EndX, EndY);
                    DeleteObject(hbr);
                    DeleteObject(hPen);
                }
                if(isTriangle) {
                    hPen = CreatePen(PS_SOLID, 1, colRef);
                    state = SendMessage(hwndCheckBox5, BM_GETCHECK, 0, 0);
                    if (state){
                        hbr = CreateSolidBrush(colRef);
                    } else {
                        hbr = (HBRUSH)GetStockObject(NULL_BRUSH);
                    }
                    SelectObject(hDC, hbr);
                    SelectObject(hDC, hPen);
                    SetROP2(hDC, R2_NOTXORPEN);
                    pt[0].x = StartX;  pt[0].y = EndY;
                    pt[1].x = (EndX + StartX) / 2; pt[1].y = StartY;
                    pt[2].x = EndX; pt[2].y = EndY;
                    Triangle(hDC, pt);
                    EndX = LOWORD(lParam);
                    EndY = HIWORD(lParam);
                    pt[0].x = StartX;  pt[0].y = EndY;
                    pt[1].x = (EndX + StartX) / 2; pt[1].y = StartY;
                    pt[2].x = EndX ; pt[2].y = EndY;
                    Triangle(hDC, pt);
                    DeleteObject(hPen);
                    DeleteObject(hbr);
                }
                if (isRectangle) {
                    hPen = CreatePen(PS_SOLID, 1, colRef);
                    state = SendMessage(hwndCheckBox6, BM_GETCHECK, 0, 0);
                    hPen = CreatePen(PS_SOLID, 1, colRef);
                    if(state) {
                        hbr = CreateSolidBrush(colRef);
                        SelectObject(hDC, hbr);
                    } else {
                        hbr = (HBRUSH)GetStockObject(NULL_BRUSH);
                        SelectObject(hDC, hbr);
                    }
                    SelectObject(hDC, hPen);
                    SetROP2(hDC, R2_NOTXORPEN);
                    pt[0].x = StartX ;  pt[0].y = StartY;
                    pt[1].x = StartX; pt[1].y = EndY ;
                    pt[2].x = EndX ; pt[2].y = EndY ;
                    pt[3].x = EndX ; pt[3].y = StartY ;
                    Rectangle(hDC, pt);
                    EndX = LOWORD(lParam);
                    EndY = HIWORD(lParam);
                    pt[0].x = StartX;  pt[0].y = StartY;
                    pt[1].x = StartX; pt[1].y = EndY;
                    pt[2].x = EndX; pt[2].y = EndY;
                    pt[3].x = EndX; pt[3].y = StartY;
                    Rectangle(hDC, pt);
                    DeleteObject(hPen);
                    DeleteObject(hbr);
                }
                if (isEraser) {
                    SetROP2(hDC, R2_NOTXORPEN);
                    rect.left = StartX - 5;
                    rect.right = StartX + 5;
                    rect.top = StartY - 5;
                    rect.bottom = StartY + 5 ;
                    InvalidateRect(hwnd, &rect, FALSE);
                    SendMessage(hwnd, WM_PAINT, 0, 0);
                    ValidateRect(hwnd, &rect);
                    EndX = LOWORD(lParam);
                    EndY = HIWORD(lParam);
                    rect.left = EndX - 5;
                    rect.right = EndX + 5;
                    rect.top = EndY - 5;
                    rect.bottom = EndY + 5 ;
                    InvalidateRect(hwnd, &rect, FALSE);
                    SendMessage(hwnd, WM_PAINT, 0, 0);
                    ValidateRect(hwnd, &rect);

                }
            }
            ReleaseDC(hwnd, hDC);
            break;
        case WM_LBUTTONUP:

            hDC = GetDC(hwnd);
            EndX = LOWORD(lParam);
            EndY = HIWORD(lParam);
            SetROP2(hDC, R2_XORPEN);
            MoveToEx(hDC, StartX, StartY, NULL);
            LineTo(hDC, EndX, EndY);
            IsDrawing = FALSE;
            ReleaseDC(hwnd, hDC);
            break;
        case WM_SIZE:
            cxClient = LOWORD (lParam);
            cyClient = HIWORD (lParam);
            return 0;
        case WM_COMMAND :
            switch (LOWORD(wParam)){
                case IDB_BUTTON1:
                    isEraser = false;
                    isRectangle = false;
                    isLine = true;
                    isFreeHand = false;
                    isEllipse = false;
                    isTriangle = false;
                    break;
                case IDB_BUTTON3:
                    isEraser = false;
                    isRectangle = false;
                    isLine = false;
                    isFreeHand = false;
                    isEllipse = true;
                    isTriangle = false;
                    break;
                case IDB_BUTTON4:
                    isEraser = false;
                    isRectangle = false;
                    isLine = false;
                    isFreeHand = true;
                    isEllipse = false;
                    isTriangle = false;
                    break;
                case IDB_BUTTON5:
                    isEraser = false;
                    isRectangle = false;
                    isTriangle = true;
                    isLine = false;
                    isFreeHand = false;
                    isEllipse = false;
                    break;
                case IDB_BUTTON6:
                    isEraser = false;
                    isRectangle = true;
                    isTriangle = false;
                    isLine = false;
                    isFreeHand = false;
                    isEllipse = false;
                    break;
                case IDB_BUTTON7:
                    isEraser = true;
                    isRectangle = false;
                    isTriangle = false;
                    isLine = false;
                    isFreeHand = false;
                    isEllipse = false;
                    break;
            }
            GetWindowRect (hwnd, &rc);
            return 0;
        case WM_PAINT:
            /*draw the header*/
            hdc = BeginPaint (hwnd, &ps);
            hdcMem = CreateCompatibleDC (hdc);
            SelectObject (hdcMem, hBitmap);
            for (y = 0 ; y < cySource ; y += cySource)
                for (x = 0 ; x < cxSource ; x += cxSource)
                    BitBlt (hdc, x, y, cxSource, cySource, hdcMem, 0, 0, SRCCOPY);
            DeleteDC (hdcMem) ;
            updateColorPreview(hdc, colRef, 15, 350);
            rectTemp.top = 400;
            rectTemp.bottom = 550;
            rectTemp.left =15;
            rectTemp.right =90;

            for(int l = 0; l < 150; l++) {
                int r;
                r = l * 255 / 150;
                rectTemp.top = 400 + l;
                rectTemp.bottom = 400 + l + 1;
                hBrush = CreateSolidBrush(RGB(r, r, r));
                FillRect(hdc, &rectTemp, hBrush);
                DeleteObject(hBrush);
            }

            EndPaint (hwnd, &ps) ;
            return 0;
        case WM_DESTROY:
            DeleteObject (hBitmap) ;
            PostQuitMessage (0);                                                /* send a WM_QUIT to the message queue */
            break;
        default:                                                                /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);
    }
    return 0;
}