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 / chap23 / cosmo / cosmo.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  7.6 KB  |  272 lines

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