Click here to Skip to main content
Click here to Skip to main content

Magnifying Cursor

By , 27 Jan 2003
 

Introduction

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) 
{
    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);
}
//

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.

History

  • First update :- 27/01/2003 (Monday)

License

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
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionWhy the put-downs?memberpensioner3065 Oct '04 - 23:35 
Good idea but it only works once?
Is there no reset by right mouse click?
Or no mouse drag?
I am interested in having a developer work on this sort of app.
Cool | :cool:
 
pensioner306
GeneralMemory Leak !memberMattthe cooldude24 Jan '04 - 17:01 
Hi,
all works fine until you quite the app and you get memory
leaks.
 
Detected memory leaks!
Dumping objects ->
C:\Mag\BitmapDC.cpp(136) : {248} client block at 0x00473260, subtype 0, 8 bytes long.
a CBitmap object at $00473260, 8 bytes long
 
Any help with that ?
thanks
MattUnsure | :~
GeneralYou might enjoy this implementation...memberMarc Clifton28 Jan '03 - 1:22 
http://www.codeproject.com/dialog/magnifyglass.asp[^]
 
Marc
 
Help! I'm an AI running around in someone's f*cked up universe simulator.
Sensitivity and ethnic diversity means celebrating difference, not hiding from it. - Christian Graus
Every line of code is a liability - Taka Muraoka

GeneralRe: You might enjoy this implementation...sussYour worst nightmare31 Jan '03 - 5:41 
Useless creature! Mind your own bussiness and stop interfering in others program. Son of a bitch!Frown | :(
GeneralRe: You might enjoy this implementation...memberMarc Clifton31 Jan '03 - 10:57 
Gee, and I thought I was being helpful. Oh well.
 
Marc
 
Help! I'm an AI running around in someone's f*cked up universe simulator.
Sensitivity and ethnic diversity means celebrating difference, not hiding from it. - Christian Graus
Every line of code is a liability - Taka Muraoka

GeneralRe: You might enjoy this implementation...sussPixiGreg4 Feb '03 - 8:07 
Slang words are not the way to get good appreciations and better ratings, anyway...
 
p i x i g r e g
GeneralRe: You might enjoy this implementation...sussAnonymous10 Mar '03 - 19:26 
Did I ask you a darn thing you! you rotten oversized pumpkin!;P
GeneralRe: You might enjoy this implementation...memberYour worst nightmare20 Dec '03 - 20:13 
Die! Die! DieMad | :mad: Mad | :mad: Mad | :mad: Mad | :mad: Mad | :mad: Mad | :mad:
GeneralRe: You might enjoy this implementation...editorNishant S17 Jul '03 - 15:47 
Marc Clifton wrote:
Gee, and I thought I was being helpful. Oh well.
 
LOL Marc. I guess some authors find it annoying when people link to other related/similar articles on their article forum Smile | :)
 
Nish
 

"I'm a bit bored at the moment so I'm thinking about writing a new programming language" - Colin Davies
 
My book :- Summer Love and Some more Cricket [New Win]
Review by Shog9 Click here for review[NW]

GeneralRe: You might enjoy this implementation...editorMarc Clifton17 Jul '03 - 16:45 
Nishant S wrote:
I guess some authors find it annoying when people link to other related/similar articles on their article forum
 
Hah. I just passed it off as a yet another aka Bill Sergio post.
 
Marc
 
Every line of code is a liability - Taka Muraoka
A doable project is one that is small enough to be done quickly and big enough to be interesting - Ken Orr

CPP Script Framework Design Page
Latest AAL Article
AAL blog


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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 28 Jan 2003
Article Copyright 2003 by Aniket Nayak
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid