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

Windows编程

开发平台:

Visual C++

  1. /*+==========================================================================
  2.   File:      PAPER.H
  3.   Summary:   Include file for the connectable COPaper COM object class.
  4.              COPaper offers a main standard IUnknown interface (basic COM
  5.              object features), an implementation of the standard
  6.              IConnectionPointContainer interface (connectable object
  7.              features), and an implementation of the custom IPaper
  8.              interface (drawing Paper-related features). This multiple
  9.              interface COM Object Class is achieved via the technique of
  10.              nested classes.  The implementation of the
  11.              IConnectionPointContainer and IPaper interfaces are nested
  12.              inside of the COPaper Class.
  13.              APPUTIL's CThreaded OwnThis technology is used in COPaper to
  14.              ensure mutually exclusive access by contending multiple
  15.              client threads.
  16.              For a comprehensive tutorial code tour of this module's
  17.              contents and offerings see the tutorial STOSERVE.HTM file.
  18.              For more specific technical details on the internal workings
  19.              see the comments dispersed throughout the module's source code.
  20.   Functions: .
  21.   Classes:   COPaper.
  22.   Origin:    6-10-96: atrent - Editor-inheritance from BALL.H in
  23.              the CONSERVE Tutorial Code Sample.
  24. ----------------------------------------------------------------------------
  25.   This file is part of the Microsoft COM Tutorial Code Samples.
  26.   Copyright (C) Microsoft Corporation, 1997.  All rights reserved.
  27.   This source code is intended only as a supplement to Microsoft
  28.   Development Tools and/or on-line documentation.  See these other
  29.   materials for detailed information regarding Microsoft code samples.
  30.   THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  31.   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  32.   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  33.   PARTICULAR PURPOSE.
  34. ==========================================================================+*/
  35. #if !defined(PAPER_H)
  36. #define PAPER_H
  37. #ifdef __cplusplus
  38. // Current format version of Ink Data is 1.0. Thus, the format version
  39. // is a compile-time constant.
  40. #define INKDATA_VERSION10 MAKELONG(0,1)
  41. // InkData allocation sizes for the Dynamic InkData array.
  42. enum
  43. {
  44.   INKDATA_ALLOC_INIT = 3200,
  45.   INKDATA_ALLOC = 800
  46. };
  47. // The types of Ink Data.
  48. #define INKTYPE_NONE  0
  49. #define INKTYPE_START 1
  50. #define INKTYPE_DRAW  2
  51. #define INKTYPE_STOP  3
  52. // The Ink Data structure.
  53. typedef struct _INKDATA
  54. {
  55.   SHORT nType;            // Ink Type.
  56.   SHORT nX;               // X-coordinate of ink point.
  57.   SHORT nY;               // Y-coordinate of ink point.
  58.   SHORT nWidth;           // Ink line width.
  59.   COLORREF crColor;       // Ink color.
  60. } INKDATA;
  61. // Properties of our electronic paper.
  62. #define PAPER_TITLE_SIZE 64
  63. typedef struct _PAPER_PROPERTIES
  64. {
  65.   LONG lInkDataVersion;
  66.   LONG lInkArraySize;
  67.   COLORREF crWinColor;
  68.   RECT WinRect;
  69.   WCHAR wszTitle[PAPER_TITLE_SIZE];
  70.   WCHAR wszAuthor[PAPER_TITLE_SIZE];
  71.   WCHAR wszReserved1[PAPER_TITLE_SIZE];
  72.   WCHAR wszReserved2[PAPER_TITLE_SIZE];
  73. } PAPER_PROPERTIES;
  74. // Drawing Paper event constants.
  75. enum PAPER_EVENT
  76. {
  77.   PAPER_EVENT_NONE = 0,
  78.   PAPER_EVENT_LOCKED,
  79.   PAPER_EVENT_UNLOCKED,
  80.   PAPER_EVENT_LOADED,
  81.   PAPER_EVENT_SAVED,
  82.   PAPER_EVENT_INKSTART,
  83.   PAPER_EVENT_INKDRAW,
  84.   PAPER_EVENT_INKSTOP,
  85.   PAPER_EVENT_ERASED,
  86.   PAPER_EVENT_RESIZED
  87. };
  88. // Some strings used in file storage.
  89. #define STREAM_PAPERDATA_USTR L"PAPERDATA"
  90. #define CLIPBDFMT_STR "DllPaper1.0"
  91. /*O+O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O
  92.   ObjectClass: COPaper
  93.   Summary:     COM object class for COPaper COM objects.  COM objects of
  94.                this class offer custom IPaper interface features,
  95.                InitPaper, Lock, Unlock, Load, Save, InkStart, InkDraw,
  96.                InkStop, Erase, Resize, and Redraw. To make COPaper objects
  97.                connectable, the standard IConnectionPointContainer
  98.                interface features, FindConnectionPoint and
  99.                EnumConnectionPoints are also implemented. The mulitple
  100.                interfaces on this COM object are constructed via the
  101.                nested interface classes technique. COPaper is also derived
  102.                from APPUTIL's CThreaded to provide the OwnThis thread
  103.                safety mechanism.
  104.   Interfaces:  IUnknown
  105.                  Standard interface providing COM object features.
  106.                IConnectionPointContainer
  107.                  Standard Connection Point container features rendering
  108.                  COPaper objects connectable objects.
  109.                IPaper
  110.                  Custom interface providing basic electronic drawing paper
  111.                  features.
  112.   Aggregation: Yes, COPaper COM Objects are aggregatable by passing
  113.                a non-NULL pUnkOuter IUnknown pointer into the constructor.
  114. O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O-O*/
  115. class COPaper : public IUnknown, public CThreaded
  116. {
  117.   public:
  118.     // Main Object Constructor & Destructor.
  119.     COPaper(IUnknown* pUnkOuter, CServer* pServer);
  120.     ~COPaper(void);
  121.     // A general method for initializing this newly created object.
  122.     // Creates any subordinate arrays, structures, or objects.
  123.     HRESULT Init(void);
  124.     // IUnknown methods. Main object, non-delegating.
  125.     STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  126.     STDMETHODIMP_(ULONG) AddRef(void);
  127.     STDMETHODIMP_(ULONG) Release(void);
  128.   private:
  129.     // We declare nested class interface implementations here.
  130.     class CImpIConnectionPointContainer : public IConnectionPointContainer,
  131.                                           public CThreaded
  132.     {
  133.       public:
  134.         // Interface Implementation Constructor & Destructor.
  135.         CImpIConnectionPointContainer(COPaper* pBackObj, IUnknown* pUnkOuter);
  136.         ~CImpIConnectionPointContainer(void);
  137.         // IUnknown methods.
  138.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  139.         STDMETHODIMP_(ULONG) AddRef(void);
  140.         STDMETHODIMP_(ULONG) Release(void);
  141.         // IConnectionPointContainer methods.
  142.         STDMETHODIMP         FindConnectionPoint(REFIID, IConnectionPoint**);
  143.         STDMETHODIMP         EnumConnectionPoints(IEnumConnectionPoints**);
  144.       private:
  145.         // Data private to this interface implementation.
  146.         COPaper*      m_pBackObj;     // Parent Object back pointer.
  147.         IUnknown*     m_pUnkOuter;    // Outer unknown for Delegation.
  148.     };
  149.     class CImpIPaper : public IPaper, public CThreaded
  150.     {
  151.       public:
  152.         // Interface Implementation Constructor & Destructor.
  153.         CImpIPaper(COPaper* pBackObj, IUnknown* pUnkOuter);
  154.         ~CImpIPaper(void);
  155.         // IUnknown methods.
  156.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  157.         STDMETHODIMP_(ULONG) AddRef(void);
  158.         STDMETHODIMP_(ULONG) Release(void);
  159.         // IPaper methods.
  160.         STDMETHODIMP         InitPaper(RECT* pWinRect, BOOL* pbFirst);
  161.         STDMETHODIMP         Lock(SHORT* pnLockKey);
  162.         STDMETHODIMP         Unlock(SHORT nLockKey);
  163.         STDMETHODIMP         Load(SHORT nLockKey, IStorage* pIStorage);
  164.         STDMETHODIMP         Save(SHORT nLockKey, IStorage* pIStorage);
  165.         STDMETHODIMP         InkStart(
  166.                                SHORT nLockKey,
  167.                                SHORT nX,
  168.                                SHORT nY,
  169.                                SHORT nWidth,
  170.                                COLORREF crInkColor);
  171.         STDMETHODIMP         InkDraw(SHORT nLockKey, SHORT nX, SHORT nY);
  172.         STDMETHODIMP         InkStop(SHORT nLockKey, SHORT nX, SHORT nY);
  173.         STDMETHODIMP         Erase(SHORT nLockKey);
  174.         STDMETHODIMP         Resize(
  175.                                SHORT nLockKey,
  176.                                SHORT nWidth,
  177.                                SHORT nHeight);
  178.         STDMETHODIMP         Redraw(SHORT nLockKey);
  179.       private:
  180.         // Data private to this interface implementation of IPaper.
  181.         COPaper*      m_pBackObj;     // Parent Object back pointer.
  182.         IUnknown*     m_pUnkOuter;    // Outer unknown for Delegation.
  183.         // The following private data and methods constitute the working
  184.         // heart of COPaper as an actual application object.
  185.         PAPER_PROPERTIES m_PaperProperties; // For file storage.
  186.         UINT          m_ClipBdFmt;    // ClipBoard Format.
  187.         BOOL          m_bLocked;      // Paper lock state.
  188.         SHORT         m_cLockKey;     // Paper lock key counter.
  189.         RECT          m_WinRect;      // Current Window rectangle.
  190.         COLORREF      m_crWinColor;   // Current window background color.
  191.         COLORREF      m_crInkColor;   // Current ink color.
  192.         SHORT         m_nInkWidth;    // Current ink width.
  193.         LONG          m_lInkDataEnd;  // Current end of the ink data.
  194.         LONG          m_lInkDataMax;  // Current end of the ink data array.
  195.         INKDATA*      m_paInkData;    // Dynamic Ink data array pointer.
  196.         // Private utility methods of this interface implementation.
  197.         HRESULT NextSlot(void);
  198.     };
  199.     // Make the otherwise private and nested IPaper and
  200.     // IConnectionPointContainer interface implementations a friend to
  201.     // COM object instantiations of this COPaper COM object class.
  202.     friend CImpIConnectionPointContainer;
  203.     friend CImpIPaper;
  204.     // Private method of main connectable COPaper COM object to broadcast
  205.     // event notifications to all connected listening sinks.
  206.     HRESULT NotifySinks(
  207.               PAPER_EVENT PaperEvent,
  208.               SHORT nX,
  209.               SHORT nY,
  210.               SHORT nInkWidth,
  211.               COLORREF crInkColor);
  212.     // Private data of COPaper COM objects.
  213.     // Nested IPaper implementation instantiation.  This IPaper interface
  214.     // is instantiated inside this COPaper object as a native interface.
  215.     CImpIPaper        m_ImpIPaper;
  216.     // Nested IConnectionPointContainer implementation instantiation.
  217.     CImpIConnectionPointContainer m_ImpIConnectionPointContainer;
  218.     // Main Object reference count.
  219.     ULONG             m_cRefs;
  220.     // Outer unknown (aggregation & delegation).
  221.     IUnknown*         m_pUnkOuter;
  222.     // Pointer to this component server's control object.
  223.     CServer*          m_pServer;
  224.     // The array of connection points for this connectable COM object.
  225.     IConnectionPoint* m_aConnectionPoints[MAX_CONNECTION_POINTS];
  226. };
  227. typedef COPaper* PCOPaper;
  228. #endif // __cplusplus
  229. #endif // PAPER_H