AIM:
To write a Visual C++ Program for the Implementation of Tool Bar and Menu Bar in CS1255 - Visual Programming Lab.
To write a Visual C++ Program for the Implementation of Tool Bar and Menu Bar in CS1255 - Visual Programming Lab.
SOURCE CODE:
MenuToolView.cpp: implementation of the CMenuToolView class
#include "stdafx.h"
#include "MenuTool.h"
#include "MenuToolDoc.h"
#include "MenuToolView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMenuToolView
IMPLEMENT_DYNCREATE(CMenuToolView, CView)
BEGIN_MESSAGE_MAP(CMenuToolView, CView)
//{{AFX_MSG_MAP(CMenuToolView)
ON_COMMAND(ID_draw_circle, Ondrawcircle)
ON_UPDATE_COMMAND_UI(ID_draw_circle,
OnUpdatedrawcircle)
ON_COMMAND(ID_draw_pattern, Ondrawpattern)
ON_UPDATE_COMMAND_UI(ID_draw_pattern, OnUpdatedrawpattern)
ON_COMMAND(ID_draw_square, Ondrawsquare)
ON_UPDATE_COMMAND_UI(ID_draw_square, OnUpdatedrawsquare)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMenuToolView construction/destruction
CMenuToolView::CMenuToolView():m_rect(0, 0, 100, 100){m_bCircle = TRUE;m_bPattern = FALSE;}
CMenuToolView::~CMenuToolView()
{
}
BOOL CMenuToolView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMenuToolView drawing
void CMenuToolView::OnDraw(CDC* pDC)
{
CMenuToolDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CBrush brush(HS_BDIAGONAL, 0L); // brush with diagonal pattern
if (m_bPattern)
{
pDC->SelectObject(&brush);
}
else{
pDC->SelectStockObject(WHITE_BRUSH);
}
if (m_bCircle){pDC->Ellipse(m_rect);}else{pDC->Rectangle(m_rect);}pDC->SelectStockObject(WHITE_BRUSH);pDC->TextOut(200,200,"Jebastin");}
/////////////////////////////////////////////////////////////////////////////
// CMenuToolView printing
BOOL CMenuToolView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CMenuToolView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CMenuToolView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CMenuToolView diagnostics
#ifdef _DEBUG
void CMenuToolView::AssertValid() const
{
CView::AssertValid();
}
void CMenuToolView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMenuToolDoc* CMenuToolView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMenuToolDoc)));
return (CMenuToolDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMenuToolView message handlers
void CMenuToolView::Ondrawcircle(){m_bCircle = TRUE;m_rect += CPoint(25, 25);InvalidateRect(m_rect);}
void CMenuToolView::OnUpdatedrawcircle(CCmdUI* pCmdUI){pCmdUI->Enable(!m_bCircle);}
void CMenuToolView::Ondrawpattern(){// TODO: Add your command handler code herem_bPattern ^= 1;}void CMenuToolView::OnUpdatedrawpattern(CCmdUI* pCmdUI){// TODO: Add your command update UI handler code herepCmdUI->SetCheck(m_bPattern);}
void CMenuToolView::Ondrawsquare(){// TODO: Add your command handler code herem_bCircle = FALSE;m_rect += CPoint(25, 25);InvalidateRect(m_rect);
}
void CMenuToolView::OnUpdatedrawsquare(CCmdUI* pCmdUI){// TODO: Add your command update UI handler code herepCmdUI->Enable(m_bCircle);}
MenuToolView.h: interface of the CMenuToolView class
//
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_MENUTOOLVIEW_H__4C26492D_A50C_4214_ADC6_FC0EFDCE768C__INCLUDED_)
#define AFX_MENUTOOLVIEW_H__4C26492D_A50C_4214_ADC6_FC0EFDCE768C__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CMenuToolView : public CView
{
protected: // create from serialization only
CMenuToolView();
DECLARE_DYNCREATE(CMenuToolView)
// Attributes
public:
CMenuToolDoc* GetDocument();
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMenuToolView)
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CMenuToolView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
//{{AFX_MSG(CMenuToolView)
afx_msg void Ondrawcircle();
afx_msg void OnUpdatedrawcircle(CCmdUI* pCmdUI);
afx_msg void Ondrawpattern();
afx_msg void OnUpdatedrawpattern(CCmdUI* pCmdUI);
afx_msg void Ondrawsquare();
afx_msg void OnUpdatedrawsquare(CCmdUI* pCmdUI);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:CRect m_rect;BOOL m_bCircle;BOOL m_bPattern;};
#ifndef _DEBUG // debug version in MenuToolView.cpp
inline CMenuToolDoc* CMenuToolView::GetDocument()
{ return (CMenuToolDoc*)m_pDocument; }
#endif
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_MENUTOOLVIEW_H__4C26492D_A50C_4214_ADC6_FC0EFDCE768C__INCLUDED_)
OUTPUT:
EmoticonEmoticon