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 / chap18 / cosmo / cosmo.h < prev    next >
C/C++ Source or Header  |  1995-05-03  |  7KB  |  269 lines

  1. /*
  2.  * COSMO.H
  3.  * Cosmo Chapter 18
  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 _COSMO_H_
  17. #define _COSMO_H_
  18.  
  19. #define INC_CLASSLIB
  20. //CHAPTER18MOD
  21. #define INC_OLE2UI
  22. #define CHAPTER18
  23. //End CHAPTER18MOD
  24. #include <inole.h>
  25. #include "resource.h"
  26.  
  27.  
  28. //Get the editor window information.
  29. #include "polyline.h"
  30.  
  31.  
  32.  
  33. //COSMO.CPP:  Frame object that creates a main window
  34.  
  35. class CCosmoFrame : public CFrame
  36.     {
  37.     //CHAPTER18MOD
  38.     friend class CFigureClassFactory;
  39.     friend class CFigure;   //For UI purposes.
  40.     //End CHAPTER18MOD
  41.  
  42.     private:
  43.         HBITMAP         m_hBmpLines[5];     //Menu item bitmaps
  44.         UINT            m_uIDCurLine;       //Current line selection
  45.         BOOL            m_fInitialized;     //Did OleInitalize work?
  46.         LPCLASSFACTORY  m_pIClassDataTran;  //For locking
  47.  
  48.         //CHAPTER18MOD
  49.         BOOL            m_fEmbedding;       //-Embedding found?
  50.         DWORD           m_dwRegCO;          //Registration key
  51.         LPCLASSFACTORY  m_pIClassFactory;
  52.         //End CHAPTER18MOD
  53.  
  54.     protected:
  55.         //Overridable for creating a CClient for this frame
  56.         virtual PCClient  CreateCClient(void);
  57.  
  58.         virtual BOOL      RegisterAllClasses(void);
  59.         virtual BOOL      PreShowInit(void);
  60.         virtual UINT      CreateToolbar(void);
  61.  
  62.         virtual LRESULT   OnCommand(HWND, WPARAM, LPARAM);
  63.         virtual void      OnDocumentDataChange(PCDocument);
  64.         virtual void      OnDocumentActivate(PCDocument);
  65.  
  66.         //New for this class
  67.         virtual void      CreateLineMenu(void);
  68.  
  69.     public:
  70.         CCosmoFrame(HINSTANCE, HINSTANCE, LPSTR, int);
  71.         virtual ~CCosmoFrame(void);
  72.  
  73.         //Overrides
  74.         virtual BOOL      Init(PFRAMEINIT);
  75.         virtual void      UpdateMenus(HMENU, UINT);
  76.         virtual void      UpdateToolbar(void);
  77.  
  78.         //New for this class
  79.         virtual void      CheckLineSelection(UINT);
  80.  
  81.         //CHAPTER18MOD
  82.         virtual void      UpdateEmbeddingUI(BOOL, PCDocument
  83.                               , LPCTSTR, LPCTSTR);
  84.         //End CHAPTER18MOD
  85.     };
  86.  
  87.  
  88. typedef CCosmoFrame *PCCosmoFrame;
  89.  
  90.  
  91.  
  92.  
  93.  
  94. //CLIENT.CPP
  95.  
  96. /*
  97.  * The only reason we have a derived class here is to override
  98.  * CreateCDocument so we can create our own type as well as
  99.  * overriding NewDocument to perform one other piece of work once
  100.  * the document's been created.
  101.  */
  102.  
  103. class CCosmoClient : public CClient
  104.     {
  105.     protected:
  106.         //Overridable for creating a new CDocument
  107.         virtual PCDocument CreateCDocument(void);
  108.  
  109.     public:
  110.         CCosmoClient(HINSTANCE, PCFrame);
  111.         virtual ~CCosmoClient(void);
  112.  
  113.         virtual PCDocument NewDocument(BOOL);
  114.     };
  115.  
  116.  
  117. typedef CCosmoClient *PCCosmoClient;
  118.  
  119.  
  120.  
  121.  
  122. //DOCUMENT.CPP
  123.  
  124. //Constant ID for the window polyline that lives in a document
  125. #define ID_POLYLINE         10
  126.  
  127.  
  128. class CCosmoDoc : public CDocument
  129.     {
  130.     friend class CPolylineAdviseSink;
  131.  
  132.     //These need access to FQueryPasteFromData, PasteFromData
  133.     friend class CDropTarget;
  134.     friend class CDropSource;
  135.  
  136.     //CHAPTER18MOD
  137.     friend class CFigureClassFactory;
  138.     friend class CFigure;
  139.     //End CHAPTER18MOD
  140.  
  141.     protected:
  142.         UINT                    m_uPrevSize;    //Last WM_SIZE wParam
  143.         LONG                    m_lVer;         //Loaded Polyline ver
  144.  
  145.         PCPolyline              m_pPL;          //Polyline window here
  146.         PCPolylineAdviseSink    m_pPLAdv;       //Advises from Polyline
  147.  
  148.         class CDropTarget      *m_pDropTarget;  //Registered target
  149.         BOOL                    m_fDragSource;  //Source==target?
  150.  
  151.         //CHAPTER18MOD
  152.         UINT                    m_cfEmbedSource;
  153.         UINT                    m_cfObjectDescriptor;
  154.  
  155.         class CFigure          *m_pFigure;      //The object in us.
  156.         //End CHAPTER18MOD
  157.  
  158.     protected:
  159.         virtual BOOL     FMessageHook(HWND, UINT, WPARAM, LPARAM
  160.             , LRESULT *);
  161.  
  162.         void             DropSelectTargetWindow(void);
  163.  
  164.     public:
  165.         CCosmoDoc(HINSTANCE, PCFrame, PCDocumentAdviseSink);
  166.         virtual ~CCosmoDoc(void);
  167.  
  168.         virtual BOOL     Init(PDOCUMENTINIT);
  169.  
  170.         virtual void     Clear(void);
  171.  
  172.         //CHAPTER18MOD
  173.         virtual BOOL     FDirtySet(BOOL);
  174.         virtual BOOL     FDirtyGet(void);
  175.         //End CHAPTER18MOD
  176.  
  177.         virtual UINT     Load(BOOL, LPTSTR);
  178.         virtual UINT     Save(UINT, LPTSTR);
  179.  
  180.         virtual void     Undo(void);
  181.         virtual BOOL     Clip(HWND, BOOL);
  182.         virtual HGLOBAL  RenderFormat(UINT);
  183.         //CHAPTER18MOD
  184.         virtual BOOL     RenderMedium(UINT, LPSTGMEDIUM);
  185.         //End CHAPTER18MOD
  186.         virtual BOOL     FQueryPaste(void);
  187.         virtual BOOL     Paste(HWND);
  188.  
  189.         //CHAPTER18MOD
  190.         //These were protected.  Now for IOleObject, should be public.
  191.         virtual BOOL     FQueryPasteFromData(LPDATAOBJECT);
  192.         virtual BOOL     PasteFromData(LPDATAOBJECT);
  193.         LPDATAOBJECT     TransferObjectCreate(BOOL);
  194.         //End CHAPTER18MOD
  195.  
  196.         virtual COLORREF ColorSet(UINT, COLORREF);
  197.         virtual COLORREF ColorGet(UINT);
  198.  
  199.         virtual UINT     LineStyleSet(UINT);
  200.         virtual UINT     LineStyleGet(void);
  201.     };
  202.  
  203. typedef CCosmoDoc *PCCosmoDoc;
  204.  
  205.  
  206. //These color indices wrap the polyline definitions
  207. #define DOCCOLOR_BACKGROUND             POLYLINECOLOR_BACKGROUND
  208. #define DOCCOLOR_LINE                   POLYLINECOLOR_LINE
  209.  
  210.  
  211. //Drag-drop interfaces we need in the document
  212. class CDropTarget : public IDropTarget
  213.     {
  214.     protected:
  215.         ULONG               m_cRef;
  216.         PCCosmoDoc          m_pDoc;
  217.  
  218.         LPDATAOBJECT        m_pIDataObject;     //From DragEnter
  219.  
  220.     public:
  221.         CDropTarget(PCCosmoDoc);
  222.         ~CDropTarget(void);
  223.  
  224.         //IDropTarget interface members
  225.         STDMETHODIMP QueryInterface(REFIID, PPVOID);
  226.         STDMETHODIMP_(ULONG) AddRef(void);
  227.         STDMETHODIMP_(ULONG) Release(void);
  228.  
  229.         STDMETHODIMP DragEnter(LPDATAOBJECT, DWORD, POINTL, LPDWORD);
  230.         STDMETHODIMP DragOver(DWORD, POINTL, LPDWORD);
  231.         STDMETHODIMP DragLeave(void);
  232.         STDMETHODIMP Drop(LPDATAOBJECT, DWORD, POINTL, LPDWORD);
  233.     };
  234.  
  235.  
  236. typedef CDropTarget *PCDropTarget;
  237.  
  238.  
  239. class CDropSource : public IDropSource
  240.     {
  241.     protected:
  242.         ULONG               m_cRef;
  243.         PCCosmoDoc          m_pDoc;
  244.  
  245.     public:
  246.         CDropSource(PCCosmoDoc);
  247.         ~CDropSource(void);
  248.  
  249.         //IDropSource interface members
  250.         STDMETHODIMP QueryInterface(REFIID, PPVOID);
  251.         STDMETHODIMP_(ULONG) AddRef(void);
  252.         STDMETHODIMP_(ULONG) Release(void);
  253.  
  254.         STDMETHODIMP QueryContinueDrag(BOOL, DWORD);
  255.         STDMETHODIMP GiveFeedback(DWORD);
  256.     };
  257.  
  258.  
  259. typedef CDropSource *PCDropSource;
  260.  
  261. //CHAPTER18MOD
  262. //Include classes necessary to become an OLE Document server.
  263. #include "cosmole.h"
  264. //End CHAPTER18MOD
  265.  
  266.  
  267.  
  268. #endif //_COSMO_H_
  269.