Visual C++ Program for the Implementation of Mini Server | CS1255 - Visual Programming Laboratory

AIM:
To write a Visual C++ Program for the Implementation of Mini Server in CS1255 - Visual Programming Lab.

SOURCE CODE:
MINISERVERDoc.h: interface of the CMINISERVERDoc class
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_MINIDOC_H__ADD2E3CA_0D2A_4947_92ED_D65580AD86F5__INCLUDED_)
#define AFX_MINIDOC_H__ADD2E3CA_0D2A_4947_92ED_D65580AD86F5__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CMINISERVERSrvrItem;
class CMINISERVERDoc : public COleServerDoc
{
protected: // create from serialization only
    CMINISERVERDoc();
    DECLARE_DYNCREATE(CMINISERVERDoc)
// Attributes
public:
    CMINISERVERSrvrItem* GetEmbeddedItem()
        { return (CMINISERVERSrvrItem*)COleServerDoc::GetEmbeddedItem(); }
// Operations
public:
    CString m_strText;

public:
// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CMINISERVERDoc)
    protected:
    virtual COleServerItem* OnGetEmbeddedItem();
    public:
    virtual BOOL OnNewDocument();
    virtual void Serialize(CArchive& ar);
    //}}AFX_VIRTUAL

// Implementation
public:
    virtual ~CMINISERVERDoc();
#ifdef _DEBUG
    virtual void AssertValid() const;
    virtual void Dump(CDumpContext& dc) const;
#endif

protected:
// Generated message map functions
protected:
    //{{AFX_MSG(CMINISERVERDoc)
    afx_msg void OnModify();
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_MINIDOC_H__ADD2E3CA_0D2A_4947_92ED_D65580AD86F5__INCLUDED_)

MINISERVERDoc.cpp: implementation of the CMINISERVERDoc class
#include "stdafx.h"
#include "MINISERVER.h"
#include "TextDialog.h"
#include "MINISERVERDoc.h"
#include "SrvrItem.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMINISERVERDo
IMPLEMENT_DYNCREATE(CMINISERVERDoc, COleServerDoc)
BEGIN_MESSAGE_MAP(CMINISERVERDoc, COleServerDoc)
    //{{AFX_MSG_MAP(CMINISERVERDoc)
    ON_COMMAND(ID_MODIFY, OnModify)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMINISERVERDoc construction/destruction

CMINISERVERDoc::CMINISERVERDoc()
{
    // Use OLE compound files
    EnableCompoundFile();
    // TODO: add one-time construction code here
}

CMINISERVERDoc::~CMINISERVERDoc()
{
}

BOOL CMINISERVERDoc::OnNewDocument()
{
    if (!COleServerDoc::OnNewDocument())
        return FALSE;
    // TODO: add reinitialization code here
    // (SDI documents will reuse this document)
    return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMINISERVERDoc server implementation

COleServerItem* CMINISERVERDoc::OnGetEmbeddedItem()
{
    // OnGetEmbeddedItem is called by the framework to get the COleServerItem
    //  that is associated with the document.  It is only called when necessary.
    CMINISERVERSrvrItem* pItem = new CMINISERVERSrvrItem(this);
    ASSERT_VALID(pItem);
    return pItem;
}

/////////////////////////////////////////////////////////////////////////////
// CMINISERVERDoc serialization

void CMINISERVERDoc::Serialize(CArchive& ar)
{
    if (ar.IsStoring())
    {
        // TODO: add storing code here
    }
    else
    {
        // TODO: add loading code here
    }
}

// CMINISERVERDoc diagnostics
#ifdef _DEBUG
void CMINISERVERDoc::AssertValid() const
{COleServerDoc::AssertValid();
}
void CMINISERVERDoc::Dump(CDumpContext& dc) const
{
    COleServerDoc::Dump(dc);
}
#endif //_DEBUG

// CMINISERVERDoc commands

void CMINISERVERDoc::OnModify()
{
    // TODO: Add your command handler code here
    CTextDialog dlg;
    dlg.m_strText=m_strText;
    if(dlg.DoModal()==IDOK)
    {
                m_strText=dlg.m_strText;
        UpdateAllViews(NULL);
                UpdateAllItems(NULL);
        SetModifiedFlag();
    }
}

MINISERVERView.cpp: implementation of the CMINISERVERView class
#include "stdafx.h"
#include "MINISERVER.h"
#include "MINISERVERDoc.h"
#include "MINISERVERView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMINISERVERView
IMPLEMENT_DYNCREATE(CMINISERVERView, CView)
BEGIN_MESSAGE_MAP(CMINISERVERView, CView)
    //{{AFX_MSG_MAP(CMINISERVERView)
        // NOTE - the ClassWizard will add and remove mapping macros here.
        //    DO NOT EDIT what you see in these blocks of generated code!
    ON_COMMAND(ID_CANCEL_EDIT_SRVR, OnCancelEditSrvr)
    //}}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()

/////////////////////////////////////////////////////////////////////////////
// CMINISERVERView construction/destruction

CMINISERVERView::CMINISERVERView()
{
    // TODO: add construction code here
}

CMINISERVERView::~CMINISERVERView()
{
}

BOOL CMINISERVERView::PreCreateWindow(CREATESTRUCT& cs)
{
    // TODO: Modify the Window class or styles here by modifying
    //  the CREATESTRUCT cs
    return CView::PreCreateWindow(cs);
}

// CMINISERVERView drawing
void CMINISERVERView::OnDraw(CDC* pDC)
{
    CMINISERVERDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    // TODO: add draw code for native data here
    CFont font;   font.CreateFont(-500,0,0,0,400,FALSE,FALSE,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,
        DEFAULT_QUALITY,DEFAULT_PITCH|FF_SWISS,"Arial");
    CFont* pFont=pDC->SelectObject(&font);
    CRect rectClient;
    GetClientRect(rectClient);
    CSize sizeClient= rectClient.Size();
    pDC->DPtoHIMETRIC(&sizeClient);
    CRect rectEllipse(sizeClient.cx/2 - 1000,
        -sizeClient.cy/2 + 1000,
        sizeClient.cx/2 + 1000,
        -sizeClient.cy/2 - 1000);
    pDC->Ellipse(rectEllipse);
    pDC->TextOut(0,0,pDoc->m_strText);
    pDC->SelectObject(pFont);
}

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

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

void CMINISERVERView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
    // TODO: add cleanup after printing
}
// OLE Server support
// The following command handler provides the standard keyboard
//  user interface to cancel an in-place editing session.  Here,
//  the server (not the container) causes the deactivation.
void CMINISERVERView::OnCancelEditSrvr()
{
    GetDocument()->OnDeactivateUI(FALSE);
}
// CMINISERVERView diagnostics

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

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

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

void CMINISERVERView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
    // TODO: Add your specialized code here and/or call the base class
 pDC->SetMapMode(MM_HIMETRIC);   
CView::OnPrepareDC(pDC, pInfo);
}

SrvrItem.cpp: implementation of the CMINISERVERSrvrItem class
#include "stdafx.h"
#include "MINISERVER.h"
#include "MINISERVERDoc.h"
#include "SrvrItem.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMINISERVERSrvrItem implementation

IMPLEMENT_DYNAMIC(CMINISERVERSrvrItem, COleServerItem)

CMINISERVERSrvrItem::CMINISERVERSrvrItem(CMINISERVERDoc* pContainerDoc)
    : COleServerItem(pContainerDoc, TRUE)
{
    // TODO: add one-time construction code here
    //  (eg, adding additional clipboard formats to the item's data source)
}

CMINISERVERSrvrItem::~CMINISERVERSrvrItem()
{
    // TODO: add cleanup code here
}

void CMINISERVERSrvrItem::Serialize(CArchive& ar)
{
    // CMINISERVERSrvrItem::Serialize will be called by the framework if
    //  the item is copied to the clipboard.  This can happen automatically
    //  through the OLE callback OnGetClipboardData.  A good default for
    //  the embedded item is simply to delegate to the document's Serialize
    //  function.  If you support links, then you will want to serialize
    //  just a portion of the document.
   if (!IsLinkedItem())
    {
        CMINISERVERDoc* pDoc = GetDocument();
        ASSERT_VALID(pDoc);
        pDoc->Serialize(ar);
    }
}

BOOL CMINISERVERSrvrItem::OnGetExtent(DVASPECT dwDrawAspect, CSize& rSize)
{
    // Most applications, like this one, only handle drawing the content
    //  aspect of the item.  If you wish to support other aspects, such
    //  as DVASPECT_THUMBNAIL (by overriding OnDrawEx), then this
    //  implementation of OnGetExtent should be modified to handle the
    //  additional aspect(s).
    if (dwDrawAspect != DVASPECT_CONTENT)
        return COleServerItem::OnGetExtent(dwDrawAspect, rSize);
    // CMINISERVERSrvrItem::OnGetExtent is called to get the extent in
    //  HIMETRIC units of the entire item.  The default implementation
    //  here simply returns a hard-coded number of units.
    CMINISERVERDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    // TODO: replace this arbitrary size
    rSize = CSize(3000, 3000);   // 3000 x 3000 HIMETRIC units
    return TRUE;
}

BOOL CMINISERVERSrvrItem::OnDraw(CDC* pDC, CSize& rSize)
{
    // Remove this if you use rSize
    UNREFERENCED_PARAMETER(rSize);
    CMINISERVERDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    // TODO: set mapping mode and extent
    //  (The extent is usually the same as the size returned from OnGetExtent)
    pDC->SetMapMode(MM_ANISOTROPIC);
    pDC->SetWindowOrg(0,0);
    pDC->SetWindowExt(3000, 3000);
    CFont font;
    font.CreateFont(-  500,0,0,0,400,FALSE,FALSE,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_SWISS,"Arial");
    CFont* pFont=pDC->SelectObject(&font);
    CRect rectEllipse(CRect(500,-500,2500,-2500));
    pDC->Ellipse(rectEllipse);
    pDC->TextOut(0,0,pDoc->m_strText);
    pDC->SelectObject(pFont);
    return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMINISERVERSrvrItem diagnostics
#ifdef _DEBUG
void CMINISERVERSrvrItem::AssertValid() const
{
    COleServerItem::AssertValid();
}

void CMINISERVERSrvrItem::Dump(CDumpContext& dc) const
{
    COleServerItem::Dump(dc);
}
#endif

OUTPUT:
Previous
Next Post »

If you still didn't find what you're looking for, you can search this website below: