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

Windows编程

开发平台:

Visual C++

  1. /*
  2.  * BEEPER.H
  3.  * Beeper Object #6 with Property Pages Chapter 16
  4.  *
  5.  * Classes that implement the Beeper object for supporting
  6.  * property pages.
  7.  *
  8.  * Copyright (c)1993-1995 Microsoft Corporation, All Right Reserved
  9.  *
  10.  * Kraig Brockschmidt, Microsoft
  11.  * Internet  :  kraigb@microsoft.com
  12.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  13.  */
  14. #ifndef _BEEPER_H_
  15. #define _BEEPER_H_
  16. /*
  17.  * This #define tells <bookguid.h> to not define GUIDs that will
  18.  * be defined in MKTYPLIB-generated header files, like ibeeper.h.
  19.  */
  20. #define GUIDS_FROM_TYPELIB
  21. #define INC_AUTOMATION
  22. //CHAPTER16MOD
  23. #define INC_CONTROLS
  24. #define CHAPTER16
  25. //End CHAPTER16MOD
  26. #include <inole.h>
  27. #include <malloc.h>
  28. //This file is generated from MKTYPLIB
  29. #include "ibeeper.h"
  30. //Help context ID for exceptions
  31. #define HID_SOUND_PROPERTY_LIMITATIONS  0x1E100
  32. //English exception strings
  33. #define IDS_0_MIN                   16
  34. #define IDS_0_EXCEPTIONSOURCE       (IDS_0_MIN)
  35. #define IDS_0_EXCEPTIONINVALIDSOUND (IDS_0_MIN+1)
  36. //German exception strings
  37. #define IDS_7_MIN                   32
  38. #define IDS_7_EXCEPTIONSOURCE       (IDS_7_MIN)
  39. #define IDS_7_EXCEPTIONINVALIDSOUND (IDS_7_MIN+1)
  40. //Forward class declarations for friend statements
  41. class CImpIDispatch;
  42. typedef CImpIDispatch *PCImpIDispatch;
  43. //CHAPTER16MOD
  44. class CImpISpecifyPP;
  45. typedef CImpISpecifyPP *PCImpISpecifyPP;
  46. class CImpIConnPtCont;
  47. typedef CImpIConnPtCont *PCImpIConnPtCont;
  48. class CConnectionPoint;
  49. typedef CConnectionPoint *PCConnectionPoint;
  50. //Number of property pages we support
  51. #define CPROPPAGES      1
  52. //End CHAPTER16MOD
  53. class CBeeper : public IBeeper
  54.     {
  55.     friend CImpIDispatch;
  56.     //CHAPTER16MOD
  57.     friend CImpISpecifyPP;
  58.     friend CImpIConnPtCont;
  59.     friend CConnectionPoint;
  60.     //End CHAPTER16MOD
  61.     protected:
  62.         ULONG           m_cRef;             //Object reference count
  63.         LPUNKNOWN       m_pUnkOuter;        //Controlling unknown
  64.         PFNDESTROYED    m_pfnDestroy;       //To call on closure
  65.         long            m_lSound;
  66.         PCImpIDispatch  m_pImpIDispatch;    //Our IDispatch
  67.         //CHAPTER16MOD
  68.         PCImpISpecifyPP  m_pImpISpecifyPP;   //Our ISpecifyPropertyPages
  69.         PCImpIConnPtCont m_pImpIConnPtCont;  //Our IConnectionPointContainer
  70.         IPropertyNotifySink *m_pIPropNotifySink;    //Client's
  71.         PCConnectionPoint    m_pConnPt;             //Ours
  72.         //End CHAPTER16MOD
  73.     public:
  74.         CBeeper(LPUNKNOWN, PFNDESTROYED);
  75.         ~CBeeper(void);
  76.         BOOL         Init(void);
  77.         //Non-delegating object IUnknown
  78.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  79.         STDMETHODIMP_(ULONG) AddRef(void);
  80.         STDMETHODIMP_(ULONG) Release(void);
  81.         //IBeeper functions
  82.         STDMETHODIMP_(long)  get_Sound(void);
  83.         STDMETHODIMP_(void)  put_Sound(long);
  84.         STDMETHODIMP_(long)  Beep(void);
  85.     };
  86. typedef CBeeper *PCBeeper;
  87. //DISPIDs for our dispinterface
  88. enum
  89.     {
  90.     PROPERTY_SOUND=0,
  91.     METHOD_BEEP
  92.     };
  93. /*
  94.  * IDispatch interface implementations for the Beeper.
  95.  */
  96. class CImpIDispatch : public IDispatch
  97.     {
  98.     public:
  99.         ULONG           m_cRef;     //For debugging
  100.     private:
  101.         PCBeeper        m_pObj;
  102.         LPUNKNOWN       m_pUnkOuter;
  103.         WORD            m_wException;
  104.         ITypeInfo      *m_pITINeutral;      //Type information
  105.         ITypeInfo      *m_pITIGerman;
  106.     public:
  107.         CImpIDispatch(PCBeeper, LPUNKNOWN);
  108.         ~CImpIDispatch(void);
  109.         /*
  110.          * This function is called from CBeeper functions that
  111.          * are called from within DispInvoke to set an exception.
  112.          * This is because the CBeeper functions have no way to
  113.          * tell DispInvoke of such exceptions, so we have to
  114.          * tell our IDispatch::Invoke implementation directly.
  115.          */
  116.         void Exception(WORD);
  117.         //IUnknown members that delegate to m_pUnkOuter.
  118.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  119.         STDMETHODIMP_(ULONG) AddRef(void);
  120.         STDMETHODIMP_(ULONG) Release(void);
  121.         //IDispatch members
  122.         STDMETHODIMP GetTypeInfoCount(UINT *);
  123.         STDMETHODIMP GetTypeInfo(UINT, LCID, ITypeInfo **);
  124.         STDMETHODIMP GetIDsOfNames(REFIID, OLECHAR **, UINT, LCID
  125.             , DISPID *);
  126.         STDMETHODIMP Invoke(DISPID, REFIID, LCID, WORD
  127.             , DISPPARAMS *, VARIANT *, EXCEPINFO *, UINT *);
  128.     };
  129. //Exceptions we can throw from IDispatch::Invoke
  130. enum
  131.     {
  132.     EXCEPTION_NONE=0,
  133.     EXCEPTION_INVALIDSOUND=1000
  134.     };
  135. //Exception filling function for the EXCEPINFO structure.
  136. HRESULT STDAPICALLTYPE FillException(EXCEPINFO *);
  137. //CHAPTER16MOD
  138. class CImpISpecifyPP : public ISpecifyPropertyPages
  139.     {
  140.     protected:
  141.         ULONG           m_cRef;      //Interface reference count
  142.         PCBeeper        m_pObj;      //Backpointer to the object
  143.         LPUNKNOWN       m_pUnkOuter; //For delegation
  144.     public:
  145.         CImpISpecifyPP(PCBeeper, LPUNKNOWN);
  146.         ~CImpISpecifyPP(void);
  147.         STDMETHODIMP QueryInterface(REFIID, LPVOID *);
  148.         STDMETHODIMP_(ULONG) AddRef(void);
  149.         STDMETHODIMP_(ULONG) Release(void);
  150.         STDMETHODIMP GetPages(CAUUID *);
  151.     };
  152. //CONNPT.CPP
  153. class CImpIConnPtCont : public IConnectionPointContainer
  154.     {
  155.     private:
  156.         ULONG               m_cRef;      //Interface ref count
  157.         PCBeeper            m_pObj;      //Backpointer to object
  158.         LPUNKNOWN           m_pUnkOuter; //Controlling unknown
  159.     public:
  160.         CImpIConnPtCont(PCBeeper, LPUNKNOWN);
  161.         ~CImpIConnPtCont(void);
  162.         //IUnknown members
  163.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  164.         STDMETHODIMP_(DWORD) AddRef(void);
  165.         STDMETHODIMP_(DWORD) Release(void);
  166.         //IConnectionPointContainer members
  167.         STDMETHODIMP EnumConnectionPoints(IEnumConnectionPoints **);
  168.     STDMETHODIMP FindConnectionPoint(REFIID, IConnectionPoint **);
  169.     };
  170. //This object only supports one connection per point
  171. #define CCONNMAX    1
  172. #define ADVISEKEY   72388       //Arbitrary
  173. class CConnectionPoint : public IConnectionPoint
  174.     {
  175.     private:
  176.         ULONG           m_cRef;     //Object reference count
  177.         PCBeeper        m_pObj;     //Containing object.
  178.     public:
  179.         CConnectionPoint(PCBeeper);
  180.         ~CConnectionPoint(void);
  181.         //IUnknown members
  182.         STDMETHODIMP         QueryInterface(REFIID, LPVOID *);
  183.         STDMETHODIMP_(ULONG) AddRef(void);
  184.         STDMETHODIMP_(ULONG) Release(void);
  185.         //IConnectionPoint members
  186.         STDMETHODIMP GetConnectionInterface(IID *);
  187.         STDMETHODIMP GetConnectionPointContainer
  188.             (IConnectionPointContainer **);
  189.         STDMETHODIMP Advise(LPUNKNOWN, DWORD *);
  190.         STDMETHODIMP Unadvise(DWORD);
  191.         STDMETHODIMP EnumConnections(IEnumConnections **);
  192.     };
  193. //End CHAPTER16MOD
  194. #endif //_BEEPER_H_