C++语言 线条的渐变

void CSelRectDlg::OnPaint() 
{
    if (IsIconic())
    {
        CPaintDC dc(this); // device context for painting

        SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

        // Center icon in client rectangle
        int cxIcon = GetSystemMetrics(SM_CXICON);
        int cyIcon = GetSystemMetrics(SM_CYICON);
        CRect rect;
        GetClientRect(&rect);
        int x = (rect.Width() - cxIcon + 1) / 2;
        int y = (rect.Height() - cyIcon + 1) / 2;

        // Draw the icon
        dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
        CPaintDC dc(this);
        CRect rc;
        this->GetWindowRect(rc);
        int y = rc.Height()/4;
        CPen pen, *oldpen;
        oldpen = dc.SelectObject(&pen);
        dc.MoveTo(0, y);
        dc.LineTo(0, y);
        for(int i=1;i<255;i++)
        {
            pen.DeleteObject();
            pen.CreatePen(PS_SOLID, 2, RGB(255, i, 0));
            dc.SelectObject(&pen);
            dc.LineTo(i, y);
        }
        dc.MoveTo(0, y*2);
        dc.LineTo(0, y*2);
        for(int m=1;m<255;m++)
        {
            pen.DeleteObject();
            pen.CreatePen(PS_SOLID, 2, RGB(0, 255,m));
            dc.SelectObject(&pen);
            dc.LineTo(m, y*2);

        }
        dc.MoveTo(0, y*3);
        dc.LineTo(0, y*3);
        for(int n=1;n<255;n++)
        {
            pen.DeleteObject();
            pen.CreatePen(PS_SOLID, 2, RGB(n, 0, 255));
            dc.SelectObject(&pen);
            dc.LineTo(n, y*3);

        }
        pen.DeleteObject();
        dc.SelectObject(oldpen);

        CDialog::OnPaint();
    }
}

转载于:https://www.cnblogs.com/pythonschool/archive/2012/11/23/2781126.html

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值