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 / chap12 / cocosmo / cocosmo.h < prev    next >
C/C++ Source or Header  |  1995-05-03  |  7KB  |  240 lines

  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.  
  15.  
  16. #ifndef _COCOSMO_H_
  17. #define _COCOSMO_H_
  18.  
  19. #define INC_CLASSLIB
  20. #define INC_CONTROLS
  21. #define INC_OLE2
  22. //CHAPTER12MOD
  23. #define CHAPTER12
  24. //CHAPTER12MOD
  25. #include <inole.h>
  26. #include <ipoly10.h>
  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;     //OleInitialize 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. class CPolylineAdviseSink : public IPolylineAdviseSink10
  107.     {
  108.     private:
  109.         PCCosmoDoc  m_pDoc;         //Backpointer to document
  110.         ULONG       m_cRef;
  111.  
  112.     public:
  113.         CPolylineAdviseSink(PCCosmoDoc);
  114.         ~CPolylineAdviseSink(void);
  115.  
  116.         //IUnknown members
  117.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  118.         STDMETHODIMP_(ULONG) AddRef(void);
  119.         STDMETHODIMP_(ULONG) Release(void);
  120.  
  121.         //Advise members.
  122.         STDMETHODIMP_(void) OnPointChange(void);
  123.         STDMETHODIMP_(void) OnSizeChange(void);
  124.         STDMETHODIMP_(void) OnColorChange(void);
  125.         STDMETHODIMP_(void) OnLineStyleChange(void);
  126.     };
  127.  
  128. typedef CPolylineAdviseSink *PCPolylineAdviseSink;
  129.  
  130.  
  131. /*
  132.  * The generic advisory interface.  This object controls it's own
  133.  * lifetime and the document becomes a user of the object with
  134.  * the last reference count.
  135.  */
  136.  
  137. class CImpIAdviseSink : public IAdviseSink
  138.     {
  139.     protected:
  140.         ULONG               m_cRef;
  141.         LPVOID              m_pObj;
  142.         LPUNKNOWN           m_pUnkOuter;
  143.  
  144.     public:
  145.         CImpIAdviseSink(LPVOID, LPUNKNOWN);
  146.         ~CImpIAdviseSink(void);
  147.  
  148.         STDMETHODIMP QueryInterface(REFIID, PPVOID);
  149.         STDMETHODIMP_(ULONG) AddRef(void);
  150.         STDMETHODIMP_(ULONG) Release(void);
  151.  
  152.         STDMETHODIMP_(void)  OnDataChange(LPFORMATETC, LPSTGMEDIUM);
  153.         STDMETHODIMP_(void)  OnViewChange(DWORD, LONG);
  154.         STDMETHODIMP_(void)  OnRename(LPMONIKER);
  155.         STDMETHODIMP_(void)  OnSave(void);
  156.         STDMETHODIMP_(void)  OnClose(void);
  157.     };
  158.  
  159. typedef CImpIAdviseSink *PCImpIAdviseSink;
  160.  
  161.  
  162.  
  163.  
  164. //Constant ID for the window polyline that lives in a document
  165. #define ID_POLYLINE         10
  166.  
  167. //Stream name to open with IPersistStream[Init]
  168. #define SZSTREAM                    OLETEXT("CONTENTS")
  169.  
  170.  
  171. class CCosmoDoc : public CDocument, public IUnknown
  172.     {
  173.     friend class CPolylineAdviseSink;
  174.     friend class CImpIAdviseSink;
  175.  
  176.     protected:
  177.         UINT                    m_uPrevSize;    //Last WM_SIZE wParam
  178.  
  179.         IPolyline10            *m_pPL;          //Polyline object
  180.         IPolylineAdviseSink10  *m_pPLAdv;
  181.  
  182.         IConnectionPoint       *m_pIConnectPt;
  183.         DWORD                   m_dwCookie;     //Connection key
  184.         IStorage               *m_pIStorage;    //Doc storage
  185.         PERSISTPOINTER          m_pp;
  186.  
  187.         PCImpIAdviseSink        m_pImpIAdviseSink;
  188.  
  189.         DWORD                   m_dwConn;       //Advisory connection
  190.         ULONG                   m_cRef;         //Document ref count
  191.  
  192.         //CHAPTER12MOD
  193.         LPDATAOBJECT            m_pIDataClip;   //Clipboard object
  194.         //End CHAPTER12MOD
  195.  
  196.     protected:
  197.         virtual BOOL     FMessageHook(HWND, UINT, WPARAM, LPARAM
  198.             , LRESULT *);
  199.  
  200.     public:
  201.         CCosmoDoc(HINSTANCE, PCFrame, PCDocumentAdviseSink);
  202.         virtual ~CCosmoDoc(void);
  203.  
  204.         //Need a controlling unknown for our interfaces
  205.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  206.         STDMETHODIMP_(ULONG) AddRef(void);
  207.         STDMETHODIMP_(ULONG) Release(void);
  208.  
  209.         virtual BOOL     Init(PDOCUMENTINIT);
  210.         virtual void     Clear(void);
  211.  
  212.         virtual UINT     Load(BOOL, LPTSTR);
  213.         virtual UINT     Save(UINT, LPTSTR);
  214.  
  215.         virtual void     Undo(void);
  216.         virtual BOOL     Clip(HWND, BOOL);
  217.  
  218.         //CHAPTER12MOD
  219.         //RenderFormat no longer necessary.
  220.         //End CHAPTER12MOD
  221.  
  222.         virtual BOOL     FQueryPaste(void);
  223.         virtual BOOL     Paste(HWND);
  224.  
  225.         virtual COLORREF ColorSet(UINT, COLORREF);
  226.         virtual COLORREF ColorGet(UINT);
  227.  
  228.         virtual UINT     LineStyleSet(UINT);
  229.         virtual UINT     LineStyleGet(void);
  230.     };
  231.  
  232. typedef CCosmoDoc *PCCosmoDoc;
  233.  
  234.  
  235. //These color indices wrap the polyline definitions
  236. #define DOCCOLOR_BACKGROUND             POLYLINECOLOR_BACKGROUND
  237. #define DOCCOLOR_LINE                   POLYLINECOLOR_LINE
  238.  
  239. #endif //_COCOSMO_H_
  240.