A Rectangle With Zooming Facility: Project Name: Zoom

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 5

A rectangle with zooming facility

PROJECT NAME : zoom

Workspace ---> Resource View ---> Menu ---> IDR_MAINFRAME ---> Add a new
menu “Zoom”

MAIN MENU SUB MENU ID OF SUB MENU


Zoom Zoom In ID_ZOOM_IN
Zoom Zoom Out ID_ZOOM_OUT

Workspace ---> Resource View ---> Accelerator ---> IDR_MAINFRAME

ID KEY TYPE
ID_ZOOM_IN VK_ADD Virtkey
ID_ZOOM_OUT VK_SUBTRACT Virtkey

Workspace ---> Resource View ---> Toolbar ---> IDR_MAINFRAME ---> Add 2
toolbar buttons and give an ID for them

View ---> Class wizard ---> Message maps ---> Add the following message handlers
for the class CzoomView

1) WM_KEYDOWN

2) WM_MOUSEWHEEL

Add command messages for ID_ZOOM_IN and ID_ZOOM_OUT as onZoomIn


and onZoomOut respectively.
In zoomView.h

// Attributes
public:
int clix,cliy;
CRect rect;
POINT point;
int color;
In zoomView.cpp

#include "zoomView.h"

CZoomView::CZoomView() // Constructor
{
color=BLACK_BRUSH;
MessageBox(" USE MOUSE WHEEL TO ZOOM IN & ZOOM OUT (or)\n\n USE
MENU BAR OPTION (or)\n\n PRESS 'Z' TO ZOOM OUT & 'A' TO ZOOM
IN","INFO",MB_OK);
}

// OnDraw function

void CZoomView::OnDraw(CDC* pDC)


{
CZoomDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
GetClientRect(&rect);
clix=(rect.right - rect.left)/2;
cliy=(rect.bottom - rect.top)/2;
pDC->SelectStockObject(color);
pDC->SetViewportOrg(clix,cliy);
pDC->Rectangle(-20,-10,20,10);
}
// CZoomView message handlers

BOOL CZoomView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)


{
if(zDelta<0)
{
CZoomView::OnKeyDown('Z',NULL,NULL);
}
else
{
CZoomView::OnKeyDown('A',NULL,NULL);
}
return CView::OnMouseWheel(nFlags, zDelta, pt);
}

void CZoomView::OnZoomIn()
{
CZoomView::OnKeyDown('Z',NULL,NULL);
}

void CZoomView::OnZoomOut()
{
CZoomView::OnKeyDown('A',NULL,NULL);
}
void CZoomView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
static int a=16,b=7;
static int i=0;
const int no_of_times=30;
static int left=-20;
static int top=-10;
static int right=20;
static int bottom=10;
if(nChar=='A')
{
CDC* pDC=GetDC();
GetClientRect(&rect);
clix=(rect.right - rect.left)/2;
cliy=(rect.bottom - rect.top)/2;
pDC->SelectStockObject(color);
pDC->SetViewportOrg(clix,cliy);

if(i < no_of_times)


{
Invalidate();
UpdateWindow();

SetRect(&rect,left,top,right,bottom);
left=-a+rect.left;
top=-b+rect.top;
right=a+rect.right;
bottom=b+rect.bottom;
pDC->Rectangle(left,top,right,bottom);

i++;
ReleaseDC(pDC);
}
}

if(nChar=='Z')
{
CDC* pDC=GetDC();
GetClientRect(&rect);
clix=(rect.right - rect.left)/2;
cliy=(rect.bottom - rect.top)/2;
pDC->SelectStockObject(color);
pDC->SetViewportOrg(clix,cliy);

Invalidate();
UpdateWindow();

if(i>=1)
{
SetRect(&rect,left,top,right,bottom);
left=a+rect.left;
top=b+rect.top;
right=-a+rect.right;
bottom=-b+rect.bottom;

pDC->Rectangle(left,top,right,bottom);

I - -;
ReleaseDC(pDC);

} } }

You might also like