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事件中。

原文链接: https://www.cnblogs.com/strive-sun/p/13098891.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;

也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬

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

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/404894

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年4月25日 下午4:47
下一篇 2023年4月25日 下午4:47

相关推荐