Click here to Skip to main content
11,805,035 members (56,556 online)
Click here to Skip to main content


, 7 Oct 2004 Eclipse 159K 6K 65
Rate this:
Please Sign up or sign in to vote.
A class that provides "zoom" feature


This class handles zooming feature based on CScrollView. It provides functions to set the scale of the application easily.

Using the code

Create a Doc/View application by using application wizard. Change your CView class to inherit from CZoomView instead of CView or CScrollView. And that's it, your application has zoom feature. When you want to set the scale of your application, you just call SetZoomScale() method.

void CDemoZoomView::OnViewZoomin() 
    SetZoomScale(m_zoomFactor + 1.0f);

void CDemoZoomView::OnViewZoomout() 
    SetZoomScale(m_zoomFactor - 1.0f);

Points of Interest

When I started to develop the application that wanted zoom feature, I see other guys have to create scale variable and multiply this variable in all drawing functions. It is not easy to use. So, I tried to find how to set scale in one place and that applies to all drawing code. Fortunately, there are some mapping modes that can set ratio between viewport and window area. And MM_ISOTROPIC is the answer. We can set the ratio by calling SetWindowExt() and SetViewPortExt().

int CZoomView::SetMapMode(CDC* pDC)
    int previousMode = pDC->SetMapMode(MM_ISOTROPIC);
    return previousMode;

SetWindowExt() and SetViewPortExt() are the functions of the CDC class. If we want them easy to use, the user should not know what we do with the instance of the CDC class. So, my CZoomView has the instance of CDC class. This instance will be sent through OnDraw() function. The user will call normal drawing functions and the zoom feature will apply automatically.

Logical point and Device point

Because CZoomView is based on CScrollView, so there are logical points and device points to concern. CZoomView provides DPtoLP and LPtoDP functions. User can use it as usual with CDC instance.

void CDemoZoomView::OnLButtonDown(UINT nFlags, CPoint point) 
    if (m_bSelectMode == FALSE) 
        m_bSelectMode = TRUE;
        m_ptStart = point;
        m_rubberBand.SetRect(m_ptStart, m_ptStart);
    CZoomView::OnLButtonDown(nFlags, point);


  • 30 July 2004
    • Reduce unnecessary bitmap allocation in flicker-free handling.
  • 5 June 2004
    • Added CZoomView that you may used instead of CScrollView class.


This article, along with any associated source code and files, is licensed under The Eclipse Public License 1.0


About the Author

Roonglit Chareonsupkul
Web Developer
Thailand Thailand
Roonglit is a senior analyst programmer at DST International (Thailand) Ltd. He graduated from Chulalongkorn University. He's been programming since 2000. His programming experience includes C/C++, OpenGL, DirectX, Java, MFC, ASP.NET, PHP. He has worked on both Windows and Linux Platform.

You may also be interested in...

Comments and Discussions

Questionhow to set the origin to center of view? Pin
bootflag1-Sep-15 16:43
memberbootflag1-Sep-15 16:43 
AnswerRe: how to set the origin to center of view? Pin
Roonglit Chareonsupkul1-Sep-15 18:15
memberRoonglit Chareonsupkul1-Sep-15 18:15 
QuestionOnPaint Problem Pin
Carl Banks14-Aug-14 21:10
memberCarl Banks14-Aug-14 21:10 
AnswerRe: OnPaint Problem Pin
Roonglit Chareonsupkul15-Aug-14 3:54
memberRoonglit Chareonsupkul15-Aug-14 3:54 
GeneralOnSize Problem Pin
MFCPlus3-Jan-11 20:10
memberMFCPlus3-Jan-11 20:10 
GeneralRe: OnSize Problem Pin
Carl Banks30-Aug-14 18:53
memberCarl Banks30-Aug-14 18:53 
GeneralCZoomView and drawing problem Pin
HillClimer2-Sep-09 19:44
memberHillClimer2-Sep-09 19:44 
GeneralThanks for your source Pin
Jongsun Kim20-Mar-07 10:10
memberJongsun Kim20-Mar-07 10:10 
QuestionHow to streatch the image? Pin
Zeus 19811-Nov-06 0:17
memberZeus 19811-Nov-06 0:17 
AnswerRe: How to streatch the image? Pin
Roongrit Charoensupkul1-Nov-06 2:16
memberRoongrit Charoensupkul1-Nov-06 2:16 
GeneralRe: How to streatch the image? Pin
Zeus 19811-Nov-06 23:23
memberZeus 19811-Nov-06 23:23 
GeneralRe: How to streatch the image? Pin
Roongrit Charoensupkul2-Nov-06 2:02
memberRoongrit Charoensupkul2-Nov-06 2:02 
GeneralRe: How to streatch the image? Pin
Zeus 19812-Nov-06 13:27
memberZeus 19812-Nov-06 13:27 
GeneralProblems with Zooming out an image because of LPtoDP Pin
ShwethaBR27-Jul-06 0:05
memberShwethaBR27-Jul-06 0:05 
GeneralZooming a picture Pin
Cosescu Bogdan17-Apr-06 1:52
memberCosescu Bogdan17-Apr-06 1:52 
GeneralNice work,but.. Pin
ucc80126-Jan-06 3:15
memberucc80126-Jan-06 3:15 
QuestionHow to Zoom Pin
jayaseela24-Jan-06 19:07
memberjayaseela24-Jan-06 19:07 
GeneralPrinting the view Pin
Alberto_Canabal9-Jan-06 4:45
memberAlberto_Canabal9-Jan-06 4:45 
GeneralRe: Printing the view Pin
Roongrit Charoensupkul10-Jan-06 3:59
memberRoongrit Charoensupkul10-Jan-06 3:59 
GeneralRe: Printing the view Pin
Alberto_Canabal10-Jan-06 6:15
memberAlberto_Canabal10-Jan-06 6:15 
GeneralRe: Printing the view (ouch) Pin
Alberto_Canabal19-Jan-06 0:32
memberAlberto_Canabal19-Jan-06 0:32 
GeneralZooming Centering not perfect Pin
vipinasda8-Jan-06 10:40
membervipinasda8-Jan-06 10:40 
GeneralRe: Zooming Centering not perfect Pin
vipinasda8-Jan-06 10:52
membervipinasda8-Jan-06 10:52 
GeneralRe: Zooming Centering not perfect Pin
Roongrit Charoensupkul10-Jan-06 3:56
memberRoongrit Charoensupkul10-Jan-06 3:56 
GeneralRe: Zooming Centering not perfect Pin
Vipin Aravind13-Jan-06 10:40
memberVipin Aravind13-Jan-06 10:40 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151002.1 | Last Updated 8 Oct 2004
Article Copyright 2004 by Roonglit Chareonsupkul
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid