Creep2DJ Creep2DJ - 1 year ago 94
C++ Question

Create a block of color in WINAPI

How would I create a block of color in a program? I have looked through the MSDN documentation for an answer, but it doesn't seem to be there. I just need to be able to create blocks of color in places for now. (I already know how

works and how to implement things in

Answer Source

you can create a brush with a custom color then create a rectangle or any shape then fill it: this example is just to show you how.

** put this code in your window procedure

    case WM_PAINT:

        PAINTSTRUCT ps;
        HDC hDc = BeginPaint(hWnd, &ps);
        HBRUSH hBrush = CreateSolidBrush(RGB(90, 50, 120));

        RECT rct = {100, 100, 300, 200};

        FillRect(hDc, &rct, hBrush);

        EndPaint(hWnd, &ps);
        DeleteObject(hBrush);    // freeing resource to avoid memory leak
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download