A Rectangle With Zooming Facility: Project Name: Zoom
A Rectangle With Zooming Facility: Project Name: Zoom
A Rectangle With Zooming Facility: Project Name: Zoom
Workspace ---> Resource View ---> Menu ---> IDR_MAINFRAME ---> Add a new
menu “Zoom”
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
// 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::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);
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);
} } }