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

  1. /*
  2.  * COCOSMO.H
  3.  * Component Cosmo Chapter 5
  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. //CHAPTER5MOD
  20. #define INC_CLASSLIB
  21. #define INC_CONTROLS
  22. #define INC_OLE2
  23. #define CHAPTER5
  24. #include <inole.h>
  25. #include <ipoly5.h>
  26. #include "resource.h"
  27. //End CHAPTER5MOD
  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.         //CHAPTER5MOD
  37.         BOOL            m_fInitialized;     //CoInitialize work?
  38.         //End CHAPTER5MOD
  39.  
  40.     protected:
  41.         //Overridable for creating a CClient for this frame
  42.         virtual PCClient  CreateCClient(void);
  43.  
  44.         virtual BOOL      RegisterAllClasses(void);
  45.         virtual BOOL      PreShowInit(void);
  46.         virtual UINT      CreateToolbar(void);
  47.  
  48.         virtual LRESULT   OnCommand(HWND, WPARAM, LPARAM);
  49.         virtual void      OnDocumentDataChange(PCDocument);
  50.         virtual void      OnDocumentActivate(PCDocument);
  51.  
  52.         //New for this class
  53.         virtual void      CreateLineMenu(void);
  54.  
  55.     public:
  56.         CCosmoFrame(HINSTANCE, HINSTANCE, LPSTR, int);
  57.         virtual ~CCosmoFrame(void);
  58.  
  59.         //Overrides
  60.         //CHAPTER5MOD
  61.         virtual BOOL      Init(PFRAMEINIT);
  62.         //End CHAPTER5MOD
  63.         virtual void      UpdateMenus(HMENU, UINT);
  64.         virtual void      UpdateToolbar(void);
  65.  
  66.         //New for this class
  67.         virtual void      CheckLineSelection(UINT);
  68.     };
  69.  
  70.  
  71. typedef CCosmoFrame *PCCosmoFrame;
  72.  
  73.  
  74.  
  75.  
  76.  
  77. //CLIENT.CPP
  78.  
  79. /*
  80.  * The only reason we have a derived class here is to override
  81.  * CreateCDocument so we can create our own type as well as
  82.  * overriding NewDocument to perform one other piece of work once
  83.  * the document's been created.
  84.  */
  85.  
  86. class CCosmoClient : public CClient
  87.     {
  88.     protected:
  89.         //Overridable for creating a new CDocument
  90.         virtual PCDocument CreateCDocument(void);
  91.  
  92.     public:
  93.         CCosmoClient(HINSTANCE, PCFrame);
  94.         virtual ~CCosmoClient(void);
  95.  
  96.         virtual PCDocument NewDocument(BOOL);
  97.     };
  98.  
  99.  
  100. typedef CCosmoClient *PCCosmoClient;
  101.  
  102.  
  103.  
  104.  
  105. //DOCUMENT.CPP
  106.  
  107. class CCosmoDoc;
  108. typedef CCosmoDoc *PCCosmoDoc;
  109.  
  110. //Explicit CPolyline moved into Polyline DLL and hidden from us.
  111. //CHAPTER5MOD
  112. class CPolylineAdviseSink : public IPolylineAdviseSink5
  113.     {
  114.     private:
  115.         //CHAPTER5MOD
  116.         PCCosmoDoc  m_pDoc;         //Backpointer to document
  117.         //End CHAPTER5MOD
  118.         ULONG       m_cRef;
  119.  
  120.     public:
  121.         //CHAPTER5MOD
  122.         CPolylineAdviseSink(PCCosmoDoc);
  123.         //End CHAPTER5MOD
  124.         ~CPolylineAdviseSink(void);
  125.  
  126.         //IUnknown members
  127.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  128.         STDMETHODIMP_(ULONG) AddRef(void);
  129.         STDMETHODIMP_(ULONG) Release(void);
  130.  
  131.         //Advise members.
  132.         STDMETHODIMP_(void) OnPointChange(void);
  133.         STDMETHODIMP_(void) OnSizeChange(void);
  134.         STDMETHODIMP_(void) OnDataChange(void);
  135.         STDMETHODIMP_(void) OnColorChange(void);
  136.         STDMETHODIMP_(void) OnLineStyleChange(void);
  137.     };
  138.  
  139. typedef CPolylineAdviseSink *PCPolylineAdviseSink;
  140. //End CHAPTER5MOD
  141.  
  142.  
  143.  
  144. //Constant ID for the window polyline that lives in a document
  145. #define ID_POLYLINE         10
  146.  
  147.  
  148. class CCosmoDoc : public CDocument
  149.     {
  150.     friend class CPolylineAdviseSink;
  151.  
  152.     protected:
  153.         UINT                    m_uPrevSize;    //Last WM_SIZE wParam
  154.  
  155.         //CHAPTER5MOD
  156.         IPolyline5             *m_pPL;          //Polyline object
  157.         IPolylineAdviseSink5   *m_pPLAdv;
  158.  
  159.         IConnectionPoint       *m_pIConnectPt;
  160.         DWORD                   m_dwCookie;     //Connection key
  161.         //End CHAPTER5MOD
  162.  
  163.     protected:
  164.         virtual BOOL     FMessageHook(HWND, UINT, WPARAM, LPARAM
  165.             , LRESULT *);
  166.  
  167.     public:
  168.         CCosmoDoc(HINSTANCE, PCFrame, PCDocumentAdviseSink);
  169.         virtual ~CCosmoDoc(void);
  170.  
  171.         virtual BOOL     Init(PDOCUMENTINIT);
  172.  
  173.         virtual void     Clear(void);
  174.  
  175.         virtual UINT     Load(BOOL, LPTSTR);
  176.         virtual UINT     Save(UINT, LPTSTR);
  177.  
  178.         virtual void     Undo(void);
  179.         virtual BOOL     Clip(HWND, BOOL);
  180.         virtual HGLOBAL  RenderFormat(UINT);
  181.         virtual BOOL     FQueryPaste(void);
  182.         virtual BOOL     Paste(HWND);
  183.  
  184.         virtual COLORREF ColorSet(UINT, COLORREF);
  185.         virtual COLORREF ColorGet(UINT);
  186.  
  187.         virtual UINT     LineStyleSet(UINT);
  188.         virtual UINT     LineStyleGet(void);
  189.     };
  190.  
  191.  
  192.  
  193. //These color indices wrap the polyline definitions
  194. #define DOCCOLOR_BACKGROUND             POLYLINECOLOR_BACKGROUND
  195. #define DOCCOLOR_LINE                   POLYLINECOLOR_LINE
  196.  
  197.  
  198.  
  199. #endif //_COCOSMO_H_
  200.