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

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