Click here to Skip to main content
13,730,968 members
Click here to Skip to main content
Add your own
alternative version


32 bookmarked
Posted 27 Jan 2003

Magnifying Cursor

, 27 Jan 2003
Rate this:
Please Sign up or sign in to vote.
This cursor can magnify...


This program generates a cursor that can magnify the portion on which it hovers.
I wrote this program to help myself make a small image editor. Using this code has made my program a very special one. Try it out.

Using the Code

This program copies a part of the device context on to a bitmap. Stretches it and displays the bigger size.

This program uses three classes:

  • CDib: This class can load DIBs from file and from resource and also save DIB to disk.
  • CBitmapDC: This class is derived from CDC. This class creates a bitmap from a given device context.
  • CMaskedBitmap: This class can draw a bitmap without displaying one specific colour.
void CMagnifierView::OnMouseMove(UINT nFlags, CPoint point) 
    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;
        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 =, 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;
        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);

Points of interest

I like programming applications with very cool looks. Using this cursor, the looks of the programs have been enhanced. Even game programming can use this type of cursor with a bit of enhancement.


  • 27/01/2003: First update


This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below.

A list of licenses authors might use can be found here.


About the Author

Aniket Nayak
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionNewbie Pin
Surya Ravi29-Jan-15 22:01
memberSurya Ravi29-Jan-15 22:01 
QuestionWhy the put-downs? Pin
pensioner3065-Oct-04 23:35
memberpensioner3065-Oct-04 23:35 
GeneralMemory Leak ! Pin
Mattthe cooldude24-Jan-04 17:01
memberMattthe cooldude24-Jan-04 17:01 
GeneralYou might enjoy this implementation... Pin
Marc Clifton28-Jan-03 1:22
memberMarc Clifton28-Jan-03 1:22 
GeneralRe: You might enjoy this implementation... Pin
Your worst nightmare31-Jan-03 5:41
sussYour worst nightmare31-Jan-03 5:41 
GeneralRe: You might enjoy this implementation... Pin
Marc Clifton31-Jan-03 10:57
memberMarc Clifton31-Jan-03 10:57 
GeneralRe: You might enjoy this implementation... Pin
PixiGreg4-Feb-03 8:07
memberPixiGreg4-Feb-03 8:07 
GeneralRe: You might enjoy this implementation... Pin
Anonymous10-Mar-03 19:26
memberAnonymous10-Mar-03 19:26 
GeneralRe: You might enjoy this implementation... Pin
20-Dec-03 20:13
member20-Dec-03 20:13 
GeneralRe: You might enjoy this implementation... Pin
Nish Nishant17-Jul-03 15:47
editorNish Nishant17-Jul-03 15:47 
GeneralRe: You might enjoy this implementation... Pin
Marc Clifton17-Jul-03 16:45
editorMarc Clifton17-Jul-03 16:45 
GeneralRe: You might enjoy this implementation... Pin
20-Dec-03 20:06
member20-Dec-03 20:06 
GeneralRe: You might enjoy this implementation... Pin
Marc Clifton21-Dec-03 3:51
editorMarc Clifton21-Dec-03 3:51 
The email I received:


This message has been sent from an unattended email box. The actual reply address can be found below.

An answer has been posted to your message on the page 'Magnifying Cursor':

From: Solid Snake (

Stay out of this! Sucker!

This message was created by The Code Project

Since, by your email address, I assume you are the author of this article, it is beyond my understanding that you would degrade your article with stupid posts. Even if you are not the author, you certainly aren't showing any decency or respect.

This is a good article, a nice implementation, and yet most of the messages posted on it are rude. Why?

Dead | X|


Latest AAL Article
My blog
Join my forum!
GeneralRe: You might enjoy this implementation... Pin
20-Dec-03 20:09
member20-Dec-03 20:09 
GeneralRe: You might enjoy this implementation... Pin
Anders Molin21-Dec-03 4:25
memberAnders Molin21-Dec-03 4:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01-2016 | 2.8.180920.1 | Last Updated 28 Jan 2003
Article Copyright 2003 by Aniket Nayak
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid