win32-使用FillRect绘制具有渐变颜色的客户区域背景

Posted strive-sun

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了win32-使用FillRect绘制具有渐变颜色的客户区域背景相关的知识,希望对你有一定的参考价值。

void OnEraseBkGnd(HWND hwnd)
{
    /* Vars */
    HDC dc; /* Standard Device Context; used to do the painting */

    /* rect = Client Rect of the window;
    Temp = Temparory rect tangle for the color bands */
    RECT rect, temp;
    HBRUSH color; /* A brush to do the painting with */

    /* Get the dc for the wnd */
    dc = GetDC(hwnd);

    /* Get the client rect */
    GetClientRect(hwnd, &rect);

    /* Start color; Change the R,G,B values
    to the color of your choice */
    int r1 = 255, g1 = 0, b1 = 0;

    /* End Color; Change the R,G,B values
    to the color of your choice */
    int r2 = 255, g2 = 255, b2 = 0;

    /* loop to create the gradient */
    for (int i = 0; i < rect.right; i++)
    {
        /* Color ref. for the gradient */
        int r, g, b;
        /* Determine the colors */
        r = r1 + (i * (r2 - r1) / rect.right);
        g = g1 + (i * (g2 - g1) / rect.right);
        b = b1 + (i * (b2 - b1) / rect.right);

        /* Fill in the rectangle information */

        /* The uper left point of the rectangle
        being painted; uses i as the starting point*/
        temp.left = i;
        /* Upeer Y cord. Always start at the top */
        temp.top = 0;
        /* Okay heres the key part,
        create a rectangle thats 1 pixel wide */
        temp.right = i + 1;
        /* Height of the rectangle */
        temp.bottom = rect.bottom;

        /* Create a brush to draw with;
        these colors are randomized */
        color = CreateSolidBrush(RGB(r, g, b));

        /* Finally fill in the rectangle */
        FillRect(dc, &temp, color);
    }
}

将OnEraseBkGnd()放到WM_ERASEBKGND事件中。

以上是关于win32-使用FillRect绘制具有渐变颜色的客户区域背景的主要内容,如果未能解决你的问题,请参考以下文章

Plotly:如何在 Plotly 中绘制具有渐变颜色的矩形?

在 OpenCV 中用渐变颜色绘制一条线

如何在 PHP 中绘制渐变矩形? [关闭]

iOS 绘制颜色渐变圆环

win32day07-图形绘制/GDI绘图对象-画笔/画刷

两个 UIButton 形成一个具有渐变颜色,另一个具有边框和圆角