Brief Full Advanced Search Search Tips
|  |  | To access the contents, click the chapter and section titles. Fast Track Visual C++ 6.0 Programming (Publisher: John Wiley & Sons, Inc.) Author(s): Steve Holzner ISBN: 0471312908 Publication Date: 09/01/98 Search this book:
Previous | Table of Contents | Next
Listing 10.2 DoublerView.h and DoublerView.cpp
    // DoublerView.h : interface of the CDoublerView class
    //
    /////////////////////////////////////////////////////////////////////////////

    #if
    !defined(AFX_DOUBLERVIEW_H__A45E4A61_A79A_11D1_887F_D42B07C10710__INCLUDED_)
    #define AFX_DOUBLERVIEW_H__A45E4A61_A79A_11D1_887F_D42B07C10710__INCLUDED_

    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000

    class CDoublerView : public CView
    {
    protected: // create from serialization only
        CDoublerView();
        DECLARE_DYNCREATE(CDoublerView)

    // Attributes
    public:
        CDoublerDoc* GetDocument();

    // Operations
    public:

    // Overrides
        // ClassWizard generated virtual function overrides
        //{{AFX_VIRTUAL(CDoublerView)
        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 ~CDoublerView();
    #ifdef _DEBUG
        virtual void AssertValid() const;
        virtual void Dump(CDumpContext& dc) const;
    #endif

    protected:

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

    #ifndef _DEBUG  // debug version in DoublerView.cpp
    inline CDoublerDoc* CDoublerView::GetDocument()
       { return (CDoublerDoc*)m_pDocument; }
    #endif

    /////////////////////////////////////////////////////////////////////////////

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

    #endif // !defined(AFX_DOUBLERVIEW_H__A45E4A61_A79A_11D1_887F_D42B07C10710__INCLUDED_)

    // DoublerView.cpp : implementation of the CDoublerView class
    //

    #include “stdafx.h”
    #include “Doubler.h”

    #include “DoublerDoc.h”
    #include “DoublerView.h”
    #include “DoublerDLL.h”

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

    /////////////////////////////////////////////////////////////////////////////
    // CDoublerView

    IMPLEMENT_DYNCREATE(CDoublerView, CView)

    BEGIN_MESSAGE_MAP(CDoublerView, CView)
        //{{AFX_MSG_MAP(CDoublerView)
        ON_COMMAND(ID_FILE_DOUBLETHEVALUES, OnFileDoublethevalues)
        //}}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()

    /////////////////////////////////////////////////////////////////////////////
    // CDoublerView construction/destruction

    CDoublerView::CDoublerView()

    {
        // TODO: add construction code here

    }

    CDoublerView::~CDoublerView()
    {
    }

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

        return CView::PreCreateWindow(cs);
    }

    /////////////////////////////////////////////////////////////////////////////
    // CDoublerView drawing

    void CDoublerView::OnDraw(CDC* pDC)
    {
        CDoublerDoc* pDoc = GetDocument();
        ASSERT_VALID(pDoc);

        pDC->TextOut(0, 0, pDoc->text);
        // TODO: add draw code for native data here
    }

    /////////////////////////////////////////////////////////////////////////////
    // CDoublerView printing

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

    void CDoublerView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
    {

        // TODO: add extra initialization before printing
    }

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

    /////////////////////////////////////////////////////////////////////////////
    // CDoublerView diagnostics

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

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

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

    /////////////////////////////////////////////////////////////////////////////
    // CDoublerView message handlers

    void CDoublerView::OnFileDoublethevalues()
    {
        // TODO: Add your command handler code here
        int value1 = 1;
        int value2 = 2;

        int result1 = MultiplyByTwo(value1);
        int result2 = MultiplyByTwo(value2);

        char FormattedString[80];
        wsprintf(FormattedString, “2 times %d is %d, 2 times %d is %d.”, value1,
    result1, value2, result2);

        CDoublerDoc* pDoc = GetDocument();
        ASSERT_VALID(pDoc);
        pDoc->text = FormattedString;

        Invalidate();
    }
Now that we’ve learned the basics of DLLs, we continue by seeing how to share memory between DLLs. ### Shared Memory in DLLs: The Counter DLL Another popular use of DLLs is to coordinate data between processes, because you can easily set up shared memory using DLLs. We’ve already seen how to set up memory mapped files, and the process with DLLs is similar, but even easier. In this example, Counter, we let the user select a menu item—Increment counter—to increment a counter variable stored in a DLL. Users can open other copies of the Counter program. When they select the Increment counter item, the same counter is incremented, not a new copy of the counter. In this way, we can share the counter variable between several processes. We create a DLL, CounterDLL.dll, to support the counter function IncrementCounter(), and a new MDI application, Counter, to call that function. Let’s create the DLL now.
Previous | Table of Contents | Next

| Products | Contact Us | About Us | Privacy | Ad Info | Home Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.