home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / inole2 / chap10 / cocosmo / cocosmo.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  6.7 KB  |  250 lines

  1. /*
  2.  * COCOSMO.H
  3.  * Component Cosmo Chapter 10
  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.  
  15.  
  16. #ifndef _COCOSMO_H_
  17. #define _COCOSMO_H_
  18.  
  19. #define INC_CLASSLIB
  20. #define INC_CONTROLS
  21. #define INC_OLE2
  22. //CHAPTER10MOD
  23. #define CHAPTER10
  24. #include <inole.h>
  25. #include <ipoly10.h>
  26. //End CHAPTER10MOD
  27. #include "resource.h"
  28.  
  29. //COCOSMO.CPP:  Frame object that creates a main window
  30.  
  31. class CCosmoFrame : public CFrame
  32.     {
  33.     private:
  34.         HBITMAP         m_hBmpLines[5];     //Menu item bitmaps
  35.         UINT            m_uIDCurLine;       //Current line selection
  36.         BOOL            m_fInitialized;     //CoInitialize work?
  37.  
  38.     protected:
  39.         //Overridable for creating a CClient for this frame
  40.         virtual PCClient  CreateCClient(void);
  41.  
  42.         virtual BOOL      RegisterAllClasses(void);
  43.         virtual BOOL      PreShowInit(void);
  44.         virtual UINT      CreateToolbar(void);
  45.  
  46.         virtual LRESULT   OnCommand(HWND, WPARAM, LPARAM);
  47.         virtual void      OnDocumentDataChange(PCDocument);
  48.         virtual void      OnDocumentActivate(PCDocument);
  49.  
  50.         //New for this class
  51.         virtual void      CreateLineMenu(void);
  52.  
  53.     public:
  54.         CCosmoFrame(HINSTANCE, HINSTANCE, LPSTR, int);
  55.         virtual ~CCosmoFrame(void);
  56.  
  57.         //Overrides
  58.         virtual BOOL      Init(PFRAMEINIT);
  59.         virtual void      UpdateMenus(HMENU, UINT);
  60.         virtual void      UpdateToolbar(void);
  61.  
  62.         //New for this class
  63.         virtual void      CheckLineSelection(UINT);
  64.     };
  65.  
  66.  
  67. typedef CCosmoFrame *PCCosmoFrame;
  68.  
  69.  
  70.  
  71.  
  72.  
  73. //CLIENT.CPP
  74.  
  75. /*
  76.  * The only reason we have a derived class here is to override
  77.  * CreateCDocument so we can create our own type as well as
  78.  * overriding NewDocument to perform one other piece of work once
  79.  * the document's been created.
  80.  */
  81.  
  82. class CCosmoClient : public CClient
  83.     {
  84.     protected:
  85.         //Overridable for creating a new CDocument
  86.         virtual PCDocument CreateCDocument(void);
  87.  
  88.     public:
  89.         CCosmoClient(HINSTANCE, PCFrame);
  90.         virtual ~CCosmoClient(void);
  91.  
  92.         virtual PCDocument NewDocument(BOOL);
  93.     };
  94.  
  95.  
  96. typedef CCosmoClient *PCCosmoClient;
  97.  
  98.  
  99.  
  100.  
  101. //DOCUMENT.CPP
  102.  
  103. class CCosmoDoc;
  104. typedef CCosmoDoc *PCCosmoDoc;
  105.  
  106. //CHAPTER10MOD
  107. class CPolylineAdviseSink : public IPolylineAdviseSink10
  108. //End CHAPTER10MOD
  109.     {
  110.     private:
  111.         PCCosmoDoc  m_pDoc;         //Backpointer to document
  112.         ULONG       m_cRef;
  113.  
  114.     public:
  115.         CPolylineAdviseSink(PCCosmoDoc);
  116.         ~CPolylineAdviseSink(void);
  117.  
  118.         //IUnknown members
  119.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  120.         STDMETHODIMP_(ULONG) AddRef(void);
  121.         STDMETHODIMP_(ULONG) Release(void);
  122.  
  123.         //Advise members.
  124.         STDMETHODIMP_(void) OnPointChange(void);
  125.         STDMETHODIMP_(void) OnSizeChange(void);
  126.         STDMETHODIMP_(void) OnColorChange(void);
  127.         STDMETHODIMP_(void) OnLineStyleChange(void);
  128.         //CHAPTER10MOD
  129.         //OnDataChange removed to IAdviseSink
  130.         //End CHAPTER10MOD
  131.     };
  132.  
  133. typedef CPolylineAdviseSink *PCPolylineAdviseSink;
  134.  
  135.  
  136. //CHAPTER10MOD
  137. /*
  138.  * The generic advisory interface.  This object controls it's own
  139.  * lifetime and the document becomes a user of the object with
  140.  * the last reference count.
  141.  */
  142.  
  143. class CImpIAdviseSink : public IAdviseSink
  144.     {
  145.     protected:
  146.         ULONG               m_cRef;
  147.         LPVOID              m_pObj;
  148.         LPUNKNOWN           m_pUnkOuter;
  149.  
  150.     public:
  151.         CImpIAdviseSink(LPVOID, LPUNKNOWN);
  152.         ~CImpIAdviseSink(void);
  153.  
  154.         STDMETHODIMP QueryInterface(REFIID, PPVOID);
  155.         STDMETHODIMP_(ULONG) AddRef(void);
  156.         STDMETHODIMP_(ULONG) Release(void);
  157.  
  158.         STDMETHODIMP_(void)  OnDataChange(LPFORMATETC, LPSTGMEDIUM);
  159.         STDMETHODIMP_(void)  OnViewChange(DWORD, LONG);
  160.         STDMETHODIMP_(void)  OnRename(LPMONIKER);
  161.         STDMETHODIMP_(void)  OnSave(void);
  162.         STDMETHODIMP_(void)  OnClose(void);
  163.     };
  164.  
  165. typedef CImpIAdviseSink *PCImpIAdviseSink;
  166. //End CHAPTER10MOD
  167.  
  168.  
  169.  
  170. //Constant ID for the window polyline that lives in a document
  171. #define ID_POLYLINE         10
  172.  
  173. //Stream name to open with IPersistStream[Init]
  174. #define SZSTREAM                    OLETEXT("CONTENTS")
  175.  
  176.  
  177. //CHAPTER10MOD
  178. class CCosmoDoc : public CDocument, public IUnknown
  179. //End CHAPTER10MOD
  180.     {
  181.     friend class CPolylineAdviseSink;
  182.     //CHAPTER10MOD
  183.     friend class CImpIAdviseSink;
  184.     //End CHAPTER10MOD
  185.  
  186.     protected:
  187.         UINT                    m_uPrevSize;    //Last WM_SIZE wParam
  188.  
  189.         //CHAPTER10MOD
  190.         IPolyline10            *m_pPL;          //Polyline object
  191.         IPolylineAdviseSink10  *m_pPLAdv;
  192.         //End CHAPTER8MOD
  193.  
  194.         IConnectionPoint       *m_pIConnectPt;
  195.         DWORD                   m_dwCookie;     //Connection key
  196.         IStorage               *m_pIStorage;    //Doc storage
  197.         PERSISTPOINTER          m_pp;
  198.  
  199.         //CHAPTER10MOD
  200.         PCImpIAdviseSink        m_pImpIAdviseSink;
  201.  
  202.         DWORD                   m_dwConn;       //Advisory connection
  203.         ULONG                   m_cRef;         //Document ref count
  204.         //EndCHAPTER10MOD
  205.  
  206.     protected:
  207.         virtual BOOL     FMessageHook(HWND, UINT, WPARAM, LPARAM
  208.             , LRESULT *);
  209.  
  210.     public:
  211.         CCosmoDoc(HINSTANCE, PCFrame, PCDocumentAdviseSink);
  212.         virtual ~CCosmoDoc(void);
  213.  
  214.         //CHAPTER10MOD
  215.         //Need a controlling unknown for our interfaces
  216.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  217.         STDMETHODIMP_(ULONG) AddRef(void);
  218.         STDMETHODIMP_(ULONG) Release(void);
  219.         //End CHAPTER10MOD
  220.  
  221.         virtual BOOL     Init(PDOCUMENTINIT);
  222.         virtual void     Clear(void);
  223.  
  224.         virtual UINT     Load(BOOL, LPTSTR);
  225.         virtual UINT     Save(UINT, LPTSTR);
  226.  
  227.         virtual void     Undo(void);
  228.         virtual BOOL     Clip(HWND, BOOL);
  229.         virtual HGLOBAL  RenderFormat(UINT);
  230.         virtual BOOL     FQueryPaste(void);
  231.         virtual BOOL     Paste(HWND);
  232.  
  233.         virtual COLORREF ColorSet(UINT, COLORREF);
  234.         virtual COLORREF ColorGet(UINT);
  235.  
  236.         virtual UINT     LineStyleSet(UINT);
  237.         virtual UINT     LineStyleGet(void);
  238.     };
  239.  
  240. typedef CCosmoDoc *PCCosmoDoc;
  241.  
  242.  
  243. //These color indices wrap the polyline definitions
  244. #define DOCCOLOR_BACKGROUND             POLYLINECOLOR_BACKGROUND
  245. #define DOCCOLOR_LINE                   POLYLINECOLOR_LINE
  246.  
  247.  
  248.  
  249. #endif //_COCOSMO_H_
  250.