Single Document Interface 600459– Visual Programming Anna University lab manual download fourth semester - Computer Programming

Latest

C C++ Java Python Perl Programs Examples with Output -useful for Schools & College Students

Saturday, January 29, 2011

Single Document Interface 600459– Visual Programming Anna University lab manual download fourth semester


Aim:

          To create a SDI (Application Wizard) and to draw an ellipse inside the view window using Device Context.

Logical Description:

            Using wizards create a single document interface

Algorithm:

  1. File – New – Projects tab – MFC Appwizard (exe) – Give the location            name and the project name – ok

2.      Select single Document option.
3.      Accept the defaults in the next four screens.
4.      Click the finish button – ok button.
[ProgramnameView.cpp and ProgramnameView.h files define the     CprogramnameView class, which is central to the application ]
5.      In the .cpp file , write the following code in the OnDraw function  
      void CprogramnameView :: OnDraw(CDC *pDC)
                                PDC à TextOut(0,0, “Hello World “);
            PDC à SelectStockObject(GRAY_BRUSH);
            PDC à Ellipse(CRect(0,20,100,120));
 These 3 are the member functions of the  application framework’s device context  class CDC.
  1. Build and execute the Application.

Source Code:

// sdiView.cpp : implementation of the CSdiView class
//

#include "stdafx.h"
#include "sdi.h"

#include "sdiDoc.h"
#include "sdiView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSdiView

IMPLEMENT_DYNCREATE(CSdiView, CView)

BEGIN_MESSAGE_MAP(CSdiView, CView)
            //{{AFX_MSG_MAP(CSdiView)
                        // NOTE - the ClassWizard will add and remove mapping macros here.
                        //    DO NOT EDIT what you see in these blocks of generated code!
            //}}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()

/////////////////////////////////////////////////////////////////////////////
// CSdiView construction/destruction

CSdiView::CSdiView()
{
            // TODO: add construction code here

}

CSdiView::~CSdiView()
{
}

BOOL CSdiView::PreCreateWindow(CREATESTRUCT& cs)
{
            // TODO: Modify the Window class or styles here by modifying
            //  the CREATESTRUCT cs

            return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CSdiView drawing

void CSdiView::OnDraw(CDC* pDC)
{
            CSdiDoc* pDoc = GetDocument();
            ASSERT_VALID(pDoc);
            pDC->TextOut(0,0,"Hello world");
            pDC->SelectStockObject(GRAY_BRUSH);
            pDC->Ellipse(CRect(0,20,100,120));

}

/////////////////////////////////////////////////////////////////////////////
// CSdiView printing

BOOL CSdiView::OnPreparePrinting(CPrintInfo* pInfo)
{
            // default preparation
            return DoPreparePrinting(pInfo);
}

void CSdiView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
            // TODO: add extra initialization before printing
}

void CSdiView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
            // TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CSdiView diagnostics

#ifdef _DEBUG
void CSdiView::AssertValid() const
{
            CView::AssertValid();
}

void CSdiView::Dump(CDumpContext& dc) const
{
            CView::Dump(dc);
}

CSdiDoc* CSdiView::GetDocument() // non-debug version is inline
{
            ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSdiDoc)));
            return (CSdiDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CSdiView message handlers


No comments:

Post a Comment