65.9K
CodeProject 正在变化。 阅读更多。
Home

放大光标

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.53/5 (16投票s)

2003年1月28日

1分钟阅读

viewsIcon

94185

downloadIcon

2753

这个光标可以放大...

引言

这个程序生成一个可以放大鼠标悬停区域的光标。
我编写这个程序是为了帮助我制作一个小型图像编辑器。使用这段代码使我的程序变得非常特别。请试用一下。

Using the Code

这个程序将设备上下文的一部分复制到位图上,然后将其拉伸并显示更大的尺寸。

这个程序使用了三个类

  • CDib:这个类可以从文件和资源加载DIB,也可以将DIB保存到磁盘。
  • CBitmapDC:这个类是从CDC派生的。这个类从给定的设备上下文中创建一个位图。
  • CMaskedBitmap:这个类可以在不显示特定颜色的情况下绘制位图。
//
void CMagnifierView::OnMouseMove(UINT nFlags, CPoint point) 
{
    SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR1));
    CPoint p = GetScrollPosition();
    CClientDC pdc(this);
    CMemDC dc(&pdc);
    m_dib.Draw(&dc, CPoint(-p.x, -p.y), m_dib.GetDimensions());
    CRect rect1(CPoint(0, 0), m_dib.GetDimensions());
    CRect sel;
    CMaskedBitmap* bitm;
    CMaskedBitmap* bit;
    if(rect1.PtInRect(point))
    {
        CRgn rgn1, rgn2;
        sel = CRect(point.x-(20*1), point.y-(20*1), 
                     point.x+(20*1), point.y+(20*1));
        CBitmapDC bitmap(40*1, 40*1, &dc);
        CBitmapDC bitmap2(120*1, 120*1, &dc);
        rgn1.CreateEllipticRgn(0, 0, 120, 120);
        rgn2.CreateRectRgn(0, 0, 120, 120);
        rgn1.CombineRgn(&rgn2, &rgn1, RGN_DIFF);
        int y = sel.top, x = sel.left;
        for(int i = y; i<y+(40*1);i++)
        {
            for(int j = x; j<x+(40*1); j++)
            {
                COLORREF color = dc.GetPixel(j, i);
                int red = GetRValue(color);
                int green = GetGValue(color);
                int blue = GetBValue(color);
                bitmap.SetPixel(j-x, i-y, color);
            }
        }
        bitm = bitmap.Close();
        CDC dcMem;
        dcMem.CreateCompatibleDC(&dc);
        dcMem.SelectObject(bitm);
        bitmap2.StretchBlt(0, 0, 120*1, 120*1, &dcMem, 
                                     0, 0, 40, 40, SRCCOPY);
        bitmap2.FillRgn(&rgn1, &CBrush(RGB(255, 0, 254)));
        bit = bitmap2.Close();
        dc.SelectObject(&CPen(PS_SOLID, 1, RGB(0, 0, 0)));
        dc.SelectObject(&CBrush(NULL, RGB(0, 0, 0)));
        dc.Ellipse(point.x-(60*1)-1, point.y-(60*1)-1, 
                          point.x+(60*1), point.y+(60*1));
        bit->DrawTransparent(&dc, point.x-(60*1), 
                         point.y-(60*1), RGB(255, 0, 254));
        dc.MoveTo(point.x, point.y-(60*1)-1);
        dc.LineTo(point.x, point.y-(10*1)+1);
        dc.MoveTo(point.x, point.y+(10*1)-1);
        dc.LineTo(point.x, point.y+(60*1)+1);
        dc.MoveTo(point.x-(60*1)-1, point.y);
        dc.LineTo(point.x-(10*1)+1, point.y); 
        dc.MoveTo(point.x+(10*1)-1, point.y);
        dc.LineTo(point.x+(60*1)+1, point.y); 
    }
    CScrollView::OnMouseMove(nFlags, point);
}
//

关注点

我喜欢编程外观非常酷炫的应用程序。使用这个光标,程序的视觉效果得到了提升。即使是游戏编程,也可以通过一些改进来使用这种类型的光标。

历史

  • 2003年1月27日:首次更新

许可证

本文未附加明确的许可证,但可能在文章文本或下载文件本身中包含使用条款。如有疑问,请通过下面的讨论区联系作者。

作者可能使用的许可证列表可以在此处找到。

© . All rights reserved.