COCOSMO.H
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:6k
源码类别:

Windows编程

开发平台:

Visual C++

  1. /*
  2.  * COCOSMO.H
  3.  * Component Cosmo Chapter 12
  4.  *
  5.  * Single include file that pulls in everything needed for other
  6.  * source files in the Cosmo application.
  7.  *
  8.  * Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  9.  *
  10.  * Kraig Brockschmidt, Microsoft
  11.  * Internet  :  kraigb@microsoft.com
  12.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  13.  */
  14. #ifndef _COCOSMO_H_
  15. #define _COCOSMO_H_
  16. #define INC_CLASSLIB
  17. #define INC_CONTROLS
  18. #define INC_OLE2
  19. //CHAPTER12MOD
  20. #define CHAPTER12
  21. //CHAPTER12MOD
  22. #include <inole.h>
  23. #include <ipoly10.h>
  24. #include "resource.h"
  25. //COCOSMO.CPP:  Frame object that creates a main window
  26. class CCosmoFrame : public CFrame
  27.     {
  28.     private:
  29.         HBITMAP         m_hBmpLines[5];     //Menu item bitmaps
  30.         UINT            m_uIDCurLine;       //Current line selection
  31.         BOOL            m_fInitialized;     //OleInitialize work?
  32.     protected:
  33.         //Overridable for creating a CClient for this frame
  34.         virtual PCClient  CreateCClient(void);
  35.         virtual BOOL      RegisterAllClasses(void);
  36.         virtual BOOL      PreShowInit(void);
  37.         virtual UINT      CreateToolbar(void);
  38.         virtual LRESULT   OnCommand(HWND, WPARAM, LPARAM);
  39.         virtual void      OnDocumentDataChange(PCDocument);
  40.         virtual void      OnDocumentActivate(PCDocument);
  41.         //New for this class
  42.         virtual void      CreateLineMenu(void);
  43.     public:
  44.         CCosmoFrame(HINSTANCE, HINSTANCE, LPSTR, int);
  45.         virtual ~CCosmoFrame(void);
  46.         //Overrides
  47.         virtual BOOL      Init(PFRAMEINIT);
  48.         virtual void      UpdateMenus(HMENU, UINT);
  49.         virtual void      UpdateToolbar(void);
  50.         //New for this class
  51.         virtual void      CheckLineSelection(UINT);
  52.     };
  53. typedef CCosmoFrame *PCCosmoFrame;
  54. //CLIENT.CPP
  55. /*
  56.  * The only reason we have a derived class here is to override
  57.  * CreateCDocument so we can create our own type as well as
  58.  * overriding NewDocument to perform one other piece of work once
  59.  * the document's been created.
  60.  */
  61. class CCosmoClient : public CClient
  62.     {
  63.     protected:
  64.         //Overridable for creating a new CDocument
  65.         virtual PCDocument CreateCDocument(void);
  66.     public:
  67.         CCosmoClient(HINSTANCE, PCFrame);
  68.         virtual ~CCosmoClient(void);
  69.         virtual PCDocument NewDocument(BOOL);
  70.     };
  71. typedef CCosmoClient *PCCosmoClient;
  72. //DOCUMENT.CPP
  73. class CCosmoDoc;
  74. typedef CCosmoDoc *PCCosmoDoc;
  75. class CPolylineAdviseSink : public IPolylineAdviseSink10
  76.     {
  77.     private:
  78.         PCCosmoDoc  m_pDoc;         //Backpointer to document
  79.         ULONG       m_cRef;
  80.     public:
  81.         CPolylineAdviseSink(PCCosmoDoc);
  82.         ~CPolylineAdviseSink(void);
  83.         //IUnknown members
  84.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  85.         STDMETHODIMP_(ULONG) AddRef(void);
  86.         STDMETHODIMP_(ULONG) Release(void);
  87.         //Advise members.
  88.         STDMETHODIMP_(void) OnPointChange(void);
  89.         STDMETHODIMP_(void) OnSizeChange(void);
  90.         STDMETHODIMP_(void) OnColorChange(void);
  91.         STDMETHODIMP_(void) OnLineStyleChange(void);
  92.     };
  93. typedef CPolylineAdviseSink *PCPolylineAdviseSink;
  94. /*
  95.  * The generic advisory interface.  This object controls it's own
  96.  * lifetime and the document becomes a user of the object with
  97.  * the last reference count.
  98.  */
  99. class CImpIAdviseSink : public IAdviseSink
  100.     {
  101.     protected:
  102.         ULONG               m_cRef;
  103.         LPVOID              m_pObj;
  104.         LPUNKNOWN           m_pUnkOuter;
  105.     public:
  106.         CImpIAdviseSink(LPVOID, LPUNKNOWN);
  107.         ~CImpIAdviseSink(void);
  108.         STDMETHODIMP QueryInterface(REFIID, PPVOID);
  109.         STDMETHODIMP_(ULONG) AddRef(void);
  110.         STDMETHODIMP_(ULONG) Release(void);
  111.         STDMETHODIMP_(void)  OnDataChange(LPFORMATETC, LPSTGMEDIUM);
  112.         STDMETHODIMP_(void)  OnViewChange(DWORD, LONG);
  113.         STDMETHODIMP_(void)  OnRename(LPMONIKER);
  114.         STDMETHODIMP_(void)  OnSave(void);
  115.         STDMETHODIMP_(void)  OnClose(void);
  116.     };
  117. typedef CImpIAdviseSink *PCImpIAdviseSink;
  118. //Constant ID for the window polyline that lives in a document
  119. #define ID_POLYLINE         10
  120. //Stream name to open with IPersistStream[Init]
  121. #define SZSTREAM                    OLETEXT("CONTENTS")
  122. class CCosmoDoc : public CDocument, public IUnknown
  123.     {
  124.     friend class CPolylineAdviseSink;
  125.     friend class CImpIAdviseSink;
  126.     protected:
  127.         UINT                    m_uPrevSize;    //Last WM_SIZE wParam
  128.         IPolyline10            *m_pPL;          //Polyline object
  129.         IPolylineAdviseSink10  *m_pPLAdv;
  130.         IConnectionPoint       *m_pIConnectPt;
  131.         DWORD                   m_dwCookie;     //Connection key
  132.         IStorage               *m_pIStorage;    //Doc storage
  133.         PERSISTPOINTER          m_pp;
  134.         PCImpIAdviseSink        m_pImpIAdviseSink;
  135.         DWORD                   m_dwConn;       //Advisory connection
  136.         ULONG                   m_cRef;         //Document ref count
  137.         //CHAPTER12MOD
  138.         LPDATAOBJECT            m_pIDataClip;   //Clipboard object
  139.         //End CHAPTER12MOD
  140.     protected:
  141.         virtual BOOL     FMessageHook(HWND, UINT, WPARAM, LPARAM
  142.             , LRESULT *);
  143.     public:
  144.         CCosmoDoc(HINSTANCE, PCFrame, PCDocumentAdviseSink);
  145.         virtual ~CCosmoDoc(void);
  146.         //Need a controlling unknown for our interfaces
  147.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  148.         STDMETHODIMP_(ULONG) AddRef(void);
  149.         STDMETHODIMP_(ULONG) Release(void);
  150.         virtual BOOL     Init(PDOCUMENTINIT);
  151.         virtual void     Clear(void);
  152.         virtual UINT     Load(BOOL, LPTSTR);
  153.         virtual UINT     Save(UINT, LPTSTR);
  154.         virtual void     Undo(void);
  155.         virtual BOOL     Clip(HWND, BOOL);
  156.         //CHAPTER12MOD
  157.         //RenderFormat no longer necessary.
  158.         //End CHAPTER12MOD
  159.         virtual BOOL     FQueryPaste(void);
  160.         virtual BOOL     Paste(HWND);
  161.         virtual COLORREF ColorSet(UINT, COLORREF);
  162.         virtual COLORREF ColorGet(UINT);
  163.         virtual UINT     LineStyleSet(UINT);
  164.         virtual UINT     LineStyleGet(void);
  165.     };
  166. typedef CCosmoDoc *PCCosmoDoc;
  167. //These color indices wrap the polyline definitions
  168. #define DOCCOLOR_BACKGROUND             POLYLINECOLOR_BACKGROUND
  169. #define DOCCOLOR_LINE                   POLYLINECOLOR_LINE
  170. #endif //_COCOSMO_H_