home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / oleaut / spoly / cpoly.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-05  |  5.1 KB  |  211 lines

  1. /*** 
  2. *cpoly.h
  3. *
  4. *  This is a part of the Microsoft Source Code Samples.
  5. *
  6. *  Copyright (C) 1992-1997 Microsoft Corporation. All rights reserved.
  7. *
  8. *  This source code is only intended as a supplement to Microsoft Development
  9. *  Tools and/or WinHelp documentation.  See these sources for detailed
  10. *  information regarding the Microsoft samples programs.
  11. *
  12. *Purpose:
  13. *  Definition of the CPoly class.
  14. *
  15. *  The CPoly class defines a number of methods and exposes them for
  16. *  external programmability via IDispatch,
  17. *
  18. *  methods:
  19. *    DRAW        - draw the polygon
  20. *    RESET        - delete all points from the polygon
  21. *
  22. *    ADDPOINT(X, Y)    - add a point with coordinates (x,y) to the polygon
  23. *
  24. *    ENUMPOINTS        - return a collection of the polygon's points
  25. *
  26. *    GETXORIGIN        - get and set the X origin of the polygon
  27. *    SETXORIGIN
  28. *
  29. *    GETYORIGIN        - get and set the Y origin of the polygon
  30. *    SETYORIGIN
  31. *
  32. *    GETWIDTH        - get and set the line width of the polygon
  33. *    SETWIDTH
  34. *
  35. *  UNDONE: update description
  36. *
  37. *Implementation Notes:
  38. *
  39. *****************************************************************************/
  40.  
  41.  
  42. #ifndef    CLASS
  43. # ifdef    __TURBOC__
  44. #  define CLASS class huge
  45. # else
  46. #  define CLASS class FAR
  47. # endif
  48. #endif
  49.  
  50. class CPoint;
  51.  
  52. CLASS CPoly : public IDispatch
  53. {
  54. public:
  55.     static CPoly FAR* Create();
  56.  
  57.     /* IUnknown methods */
  58.     STDMETHOD(QueryInterface)(REFIID riid, void FAR* FAR* ppvObj);
  59.     STDMETHOD_(unsigned long, AddRef)(void);
  60.     STDMETHOD_(unsigned long, Release)(void);
  61.  
  62.     /* IDispatch methods */
  63.     STDMETHOD(GetTypeInfoCount)(unsigned int FAR* pcTypeInfo);
  64.  
  65.     STDMETHOD(GetTypeInfo)(
  66.       unsigned int iTypeInfo,
  67.       LCID lcid,
  68.       ITypeInfo FAR* FAR* ppTypeInfo);
  69.  
  70.     STDMETHOD(GetIDsOfNames)(
  71.       REFIID riid,
  72.       OLECHAR FAR* FAR* rgszNames,
  73.       unsigned int cNames,
  74.       LCID lcid,
  75.       DISPID FAR* rgdispid);
  76.  
  77.     STDMETHOD(Invoke)(
  78.       DISPID dispidMember,
  79.       REFIID riid,
  80.       LCID lcid,
  81.       unsigned short wFlags,
  82.       DISPPARAMS FAR* pdispparams,
  83.       VARIANT FAR* pvarResult,
  84.       EXCEPINFO FAR* pexcepinfo,
  85.       unsigned int FAR* puArgErr);
  86.  
  87.     /* Introduced methods */
  88.  
  89.     virtual void PASCAL Draw(void);
  90.     virtual void PASCAL Reset(void);
  91.  
  92.     // add a point with the given 'x' and 'y' coordinates
  93.     virtual HRESULT PASCAL AddPoint(short x, short y);
  94.  
  95.     // return a collection of the polygon's points
  96.     virtual HRESULT PASCAL EnumPoints(IEnumVARIANT FAR* FAR* ppenum);
  97.  
  98.     // get/set the polygon's X origin property
  99.     virtual short PASCAL GetXOrigin(void);
  100.     virtual void  PASCAL SetXOrigin(short x);
  101.  
  102.     // get/set the polygon's Y origin property
  103.     virtual short PASCAL GetYOrigin(void);
  104.     virtual void  PASCAL SetYOrigin(short y);
  105.  
  106.     virtual short PASCAL GetWidth(void);
  107.     virtual void  PASCAL SetWidth(short width);
  108.  
  109.     virtual short PASCAL get_red(void);
  110.     virtual void  PASCAL set_red(short red);
  111.  
  112.     virtual short PASCAL get_green(void);
  113.     virtual void  PASCAL set_green(short green);
  114.  
  115.     virtual short PASCAL get_blue(void);
  116.     virtual void  PASCAL set_blue(short blue);
  117.  
  118.     // Debug method
  119.     virtual void  PASCAL Dump(void);
  120.     virtual void  PASCAL Quit(void);
  121.  
  122. public: 
  123.  
  124.     // Draw all polygons.
  125.     static void PolyDraw(void);
  126.  
  127.     // Release all polygons.
  128.     static void PolyTerm(void);
  129.  
  130.     // Dump all polygons to dbwin.
  131.     static void PolyDump(void);
  132.  
  133.  
  134. private:
  135.     CPoly();
  136.  
  137.     short m_xorg;
  138.     short m_yorg;
  139.     short m_width;
  140.  
  141.     short m_red;
  142.     short m_green;
  143.     short m_blue;
  144.  
  145.     unsigned long m_refs;
  146.     unsigned int m_cPoints;
  147.  
  148.     POINTLINK FAR* m_ppointlink;
  149.     POINTLINK FAR* m_ppointlinkLast;
  150. };
  151.  
  152. // DISPIDs for the members and properties available via IDispatch.
  153. //
  154. enum IDMEMBER_CPOLY {
  155.     IDMEMBER_CPOLY_DRAW = 1,
  156.     IDMEMBER_CPOLY_RESET,
  157.     IDMEMBER_CPOLY_ADDPOINT,
  158.     IDMEMBER_CPOLY_ENUMPOINTS,
  159.     IDMEMBER_CPOLY_GETXORIGIN,
  160.     IDMEMBER_CPOLY_SETXORIGIN,
  161.     IDMEMBER_CPOLY_GETYORIGIN,
  162.     IDMEMBER_CPOLY_SETYORIGIN,
  163.     IDMEMBER_CPOLY_GETWIDTH,
  164.     IDMEMBER_CPOLY_SETWIDTH,
  165.     IDMEMBER_CPOLY_GETRED,
  166.     IDMEMBER_CPOLY_SETRED,
  167.     IDMEMBER_CPOLY_GETGREEN,
  168.     IDMEMBER_CPOLY_SETGREEN,
  169.     IDMEMBER_CPOLY_GETBLUE,
  170.     IDMEMBER_CPOLY_SETBLUE,
  171.     IDMEMBER_CPOLY_DUMP,
  172.     IDMEMBER_CPOLY_QUIT,
  173.     IDMEMBER_CPOLY_MAX
  174. };
  175.  
  176. // structure used to link together polygons
  177. //
  178. struct POLYLINK {
  179.     POLYLINK FAR* next;
  180.     CPoly FAR* ppoly;
  181. };
  182.  
  183.  
  184. // The CPoly class factory
  185. //
  186. CLASS CPolyCF : public IClassFactory
  187. {
  188. public:
  189.     static IClassFactory FAR* Create();
  190.  
  191.     /* IUnknown methods */
  192.     STDMETHOD(QueryInterface)(REFIID riid, void FAR* FAR* ppv);
  193.     STDMETHOD_(unsigned long, AddRef)(void);
  194.     STDMETHOD_(unsigned long, Release)(void);
  195.  
  196.     /* IClassFactory methods */
  197.     STDMETHOD(CreateInstance)(
  198.       IUnknown FAR* pUnkOuter, REFIID riid, void FAR* FAR* ppv);
  199. #ifdef _MAC
  200.     STDMETHOD(LockServer)(unsigned long fLock);
  201. #else
  202.     STDMETHOD(LockServer)(BOOL fLock);
  203. #endif
  204.  
  205. private:
  206.     CPolyCF();
  207.  
  208.     unsigned long m_refs;
  209. };
  210.  
  211.