zoukankan      html  css  js  c++  java
  • 用渐变色填充背景(二)


    void OnEraseBkGnd(HWND hwnd)
    {
        /* Vars */
        HDC dc; /* Standard Device Context; used to do the painting */
       
        /* rect = Client Rect of the window;
        Temp = Temparary 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 rectange */
            FillRect(dc, &temp, color);
        }
    }

    效果:


    参考文章:
    [1] http://www.codeproject.com/gdi/grad01.asp
    Using color gradients as backgrounds in your dialogs and views
    By Nishant S
    [2] http://www.codetools.com/gdi/win32_gradients.asp
    Using Color Gradients in Win32/SDK Programs
    By einst992
  • 相关阅读:
    spring日记(三)
    spring日记(二)
    spring框架日记(一)
    springMVC日记(四)
    springMVC日记(三),文件上传,拦截器,数据校验
    springMVC日记(二)
    springMVC日记(一)
    Mybatis总结
    优化Dalvik虚拟机的内存分配
    简单对App进行单元测试
  • 原文地址:https://www.cnblogs.com/huqingyu/p/44657.html
Copyright © 2011-2022 走看看