HCOSMO.H
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:8k
源码类别:

Windows编程

开发平台:

Visual C++

  1. /*
  2.  * HCOSMO.H
  3.  * Cosmo Handler Chapter 19
  4.  *
  5.  * Definitions and function prototypes for the Cosmo Handler.
  6.  *
  7.  * Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  8.  *
  9.  * Kraig Brockschmidt, Microsoft
  10.  * Internet  :  kraigb@microsoft.com
  11.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  12.  */
  13. #ifndef _HCOSMO_H_
  14. #define _HCOSMO_H_
  15. #define CHAPTER19
  16. #include <inole.h>
  17. #include <ipoly10.h>      //For POLYLINEDATA definitions
  18. #define HIMETRIC_PER_INCH           2540
  19. //Stream name in the object storage
  20. #define SZSTREAM                    OLETEXT("CONTENTS")
  21. //HCOSMO.CPP
  22. class CFigureClassFactory : public IClassFactory
  23.     {
  24.     protected:
  25.         ULONG           m_cRef;         //Reference count on object
  26.     public:
  27.         CFigureClassFactory(void);
  28.         ~CFigureClassFactory(void);
  29.         //IUnknown members
  30.         STDMETHODIMP QueryInterface(REFIID, PPVOID);
  31.         STDMETHODIMP_(ULONG) AddRef(void);
  32.         STDMETHODIMP_(ULONG) Release(void);
  33.         //IClassFactory members
  34.         STDMETHODIMP    CreateInstance(LPUNKNOWN, REFIID, PPVOID);
  35.         STDMETHODIMP    LockServer(BOOL);
  36.     };
  37. typedef CFigureClassFactory *PCFigureClassFactory;
  38. //Magic number to add to aspects returned from IViewObject::Freeze
  39. #define FREEZE_KEY_OFFSET       0x0723
  40. //Forward class references
  41. class CImpIOleObject;
  42. typedef class CImpIOleObject *PCImpIOleObject;
  43. class CImpIViewObject2;
  44. typedef class CImpIViewObject2 *PCImpIViewObject2;
  45. class CImpIPersistStorage;
  46. typedef class CImpIPersistStorage *PCImpIPersistStorage;
  47. class CImpIAdviseSink;
  48. typedef class CImpIAdviseSink *PCImpIAdviseSink;
  49. //HCOSMO.CPP
  50. class CFigure : public IUnknown
  51.     {
  52.     friend class CImpIOleObject;
  53.     friend class CImpIViewObject2;
  54.     friend class CImpIPersistStorage;
  55.     friend class CImpIAdviseSink;
  56.     protected:
  57.         ULONG                m_cRef;
  58.         LPUNKNOWN            m_pUnkOuter;
  59.         PFNDESTROYED         m_pfnDestroy;
  60.         POLYLINEDATA         m_pl;          //Our actual data.
  61.         UINT                 m_cf;          //Obj clipboard format.
  62.         CLSID                m_clsID;       //Current CLSID
  63.         //These are default handler interfaces we use
  64.         LPUNKNOWN            m_pDefIUnknown;
  65.         LPOLEOBJECT          m_pDefIOleObject;
  66.         LPVIEWOBJECT2        m_pDefIViewObject2;
  67.         LPPERSISTSTORAGE     m_pDefIPersistStorage;
  68.         LPDATAOBJECT         m_pDefIDataObject;
  69.         //Implemented interfaces
  70.         PCImpIOleObject      m_pImpIOleObject;
  71.         PCImpIViewObject2    m_pImpIViewObject2;
  72.         PCImpIPersistStorage m_pImpIPersistStorage;
  73.         PCImpIAdviseSink     m_pImpIAdviseSink;
  74.         //Advise sink we get in IViewObject
  75.         LPADVISESINK         m_pIAdvSinkView;
  76.         DWORD                m_dwAdviseFlags;
  77.         DWORD                m_dwAdviseAspects;
  78.         DWORD                m_dwFrozenAspects;
  79.         //Copies of frozen aspects
  80.         POLYLINEDATA         m_plContent;
  81.         POLYLINEDATA         m_plThumbnail;
  82.     protected:
  83.         void      Draw(HDC, LPRECT, DWORD, DVTARGETDEVICE *
  84.                       , HDC, PPOLYLINEDATA);
  85.         void      PointScale(LPRECT, LPPOINTS, BOOL);
  86.     public:
  87.         CFigure(LPUNKNOWN, PFNDESTROYED, HINSTANCE);
  88.         ~CFigure(void);
  89.         BOOL      Init(void);
  90.         //Non-delegating object IUnknown
  91.         STDMETHODIMP QueryInterface(REFIID, PPVOID);
  92.         STDMETHODIMP_(ULONG) AddRef(void);
  93.         STDMETHODIMP_(ULONG) Release(void);
  94.     };
  95. typedef CFigure *PCFigure;
  96. class CImpIPersistStorage : public IPersistStorage
  97.     {
  98.     protected:
  99.         ULONG               m_cRef;
  100.         PCFigure            m_pObj;
  101.         LPUNKNOWN           m_pUnkOuter;
  102.         PSSTATE             m_psState;   //Storage state
  103.         BOOL                m_fConvert;  //Are we Converting?
  104.     public:
  105.         CImpIPersistStorage(PCFigure, LPUNKNOWN);
  106.         ~CImpIPersistStorage(void);
  107.         STDMETHODIMP QueryInterface(REFIID, PPVOID);
  108.         STDMETHODIMP_(ULONG) AddRef(void);
  109.         STDMETHODIMP_(ULONG) Release(void);
  110.         STDMETHODIMP GetClassID(LPCLSID);
  111.         STDMETHODIMP IsDirty(void);
  112.         STDMETHODIMP InitNew(LPSTORAGE);
  113.         STDMETHODIMP Load(LPSTORAGE);
  114.         STDMETHODIMP Save(LPSTORAGE, BOOL);
  115.         STDMETHODIMP SaveCompleted(LPSTORAGE);
  116.         STDMETHODIMP HandsOffStorage(void);
  117.     };
  118. class CImpIOleObject : public IOleObject
  119.     {
  120.     private:
  121.         ULONG           m_cRef;
  122.         PCFigure        m_pObj;
  123.         LPUNKNOWN       m_pUnkOuter;
  124.     public:
  125.         CImpIOleObject(PCFigure, LPUNKNOWN);
  126.         ~CImpIOleObject(void);
  127.         //IUnknown members that delegate to m_pUnkOuter.
  128.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  129.         STDMETHODIMP_(ULONG) AddRef(void);
  130.         STDMETHODIMP_(ULONG) Release(void);
  131.         //IOleObject members
  132.         STDMETHODIMP SetClientSite(LPOLECLIENTSITE);
  133.         STDMETHODIMP GetClientSite(LPOLECLIENTSITE *);
  134.         STDMETHODIMP SetHostNames(LPCOLESTR, LPCOLESTR);
  135.         STDMETHODIMP Close(DWORD);
  136.         STDMETHODIMP SetMoniker(DWORD, LPMONIKER);
  137.         STDMETHODIMP GetMoniker(DWORD, DWORD, LPMONIKER *);
  138.         STDMETHODIMP InitFromData(LPDATAOBJECT, BOOL, DWORD);
  139.         STDMETHODIMP GetClipboardData(DWORD, LPDATAOBJECT *);
  140.         STDMETHODIMP DoVerb(LONG, LPMSG, LPOLECLIENTSITE, LONG
  141.                          , HWND, LPCRECT);
  142.         STDMETHODIMP EnumVerbs(LPENUMOLEVERB *);
  143.         STDMETHODIMP Update(void);
  144.         STDMETHODIMP IsUpToDate(void);
  145.         STDMETHODIMP GetUserClassID(CLSID *);
  146.         STDMETHODIMP GetUserType(DWORD, LPOLESTR *);
  147.         STDMETHODIMP SetExtent(DWORD, LPSIZEL);
  148.         STDMETHODIMP GetExtent(DWORD, LPSIZEL);
  149.         STDMETHODIMP Advise(LPADVISESINK, DWORD *);
  150.         STDMETHODIMP Unadvise(DWORD);
  151.         STDMETHODIMP EnumAdvise(LPENUMSTATDATA *);
  152.         STDMETHODIMP GetMiscStatus(DWORD, DWORD *);
  153.         STDMETHODIMP SetColorScheme(LPLOGPALETTE);
  154.     };
  155. class CImpIViewObject2 : public IViewObject2
  156.     {
  157.     private:
  158.         ULONG           m_cRef;
  159.         PCFigure        m_pObj;
  160.         LPUNKNOWN       m_pUnkOuter;
  161.     public:
  162.         CImpIViewObject2(PCFigure, LPUNKNOWN);
  163.         ~CImpIViewObject2(void);
  164.         //IUnknown members that delegate to m_pUnkOuter.
  165.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  166.         STDMETHODIMP_(ULONG) AddRef(void);
  167.         STDMETHODIMP_(ULONG) Release(void);
  168.         //IViewObject2 members
  169.         STDMETHODIMP Draw(DWORD, LONG, LPVOID, DVTARGETDEVICE *
  170.             , HDC, HDC, LPCRECTL, LPCRECTL
  171.             , BOOL (CALLBACK *)(DWORD), DWORD);
  172.         STDMETHODIMP GetColorSet(DWORD, LONG, LPVOID
  173.             , DVTARGETDEVICE *, HDC, LPLOGPALETTE *);
  174.         STDMETHODIMP Freeze(DWORD, LONG, LPVOID, LPDWORD);
  175.         STDMETHODIMP Unfreeze(DWORD);
  176.         STDMETHODIMP SetAdvise(DWORD, DWORD, LPADVISESINK);
  177.         STDMETHODIMP GetAdvise(LPDWORD, LPDWORD, LPADVISESINK *);
  178.         STDMETHODIMP GetExtent(DWORD, LONG, DVTARGETDEVICE *
  179.             , LPSIZEL);
  180.     };
  181. class CImpIAdviseSink : public IAdviseSink
  182.     {
  183.     protected:
  184.         ULONG           m_cRef;
  185.         PCFigure        m_pObj;
  186.         LPUNKNOWN       m_pUnkOuter;
  187.     public:
  188.         CImpIAdviseSink(PCFigure, LPUNKNOWN);
  189.         ~CImpIAdviseSink(void);
  190.         STDMETHODIMP QueryInterface(REFIID, PPVOID);
  191.         STDMETHODIMP_(ULONG) AddRef(void);
  192.         STDMETHODIMP_(ULONG) Release(void);
  193.         STDMETHODIMP_(void)  OnDataChange(LPFORMATETC, LPSTGMEDIUM);
  194.         STDMETHODIMP_(void)  OnViewChange(DWORD, LONG);
  195.         STDMETHODIMP_(void)  OnRename(LPMONIKER);
  196.         STDMETHODIMP_(void)  OnSave(void);
  197.         STDMETHODIMP_(void)  OnClose(void);
  198.     };
  199. #endif  //_HCOSMO_H_