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

Windows编程

开发平台:

Visual C++

  1. // CircCtl.h : Declaration of the CCircCtl
  2. //
  3. // This is a part of the Active Template Library.
  4. // Copyright (C) 1996-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Active Template Library Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Active Template Library product.
  12. #include "resource.h"       // main symbols
  13. #include "CPEvent.h"        // connection point for events
  14. #include <atlctl.h>
  15. #include <olectl.h>
  16. extern const GUID CLSID_CCircProps;
  17. #define PRINTSIZE(theClass) 
  18. {
  19. TCHAR szBuf[255];
  20. wsprintf(szBuf, _T("sizeof(") _T(#theClass) _T(") = %dn"), sizeof(theClass));
  21. OutputDebugString(szBuf);
  22. }
  23. class ATL_NO_VTABLE CCircCtl :
  24. public CComObjectRoot,
  25. public CComCoClass<CCircCtl,&CLSID_CCircCtl>,
  26. public CComControl<CCircCtl>,
  27. public CStockPropImpl<CCircCtl, ICircCtl, &IID_ICircCtl, &LIBID_CIRCLib>,
  28. public IPersistStreamInitImpl<CCircCtl>,
  29. public IPersistStorageImpl<CCircCtl>,
  30. public IQuickActivateImpl<CCircCtl>,
  31. public IProvideClassInfo2Impl<&CLSID_CCircCtl, &DIID__CircEvents, &LIBID_CIRCLib>,
  32. public IOleControlImpl<CCircCtl>,
  33. public IOleObjectImpl<CCircCtl>,
  34. public IOleInPlaceActiveObjectImpl<CCircCtl>,
  35. public IViewObjectExImpl<CCircCtl>,
  36. public IOleInPlaceObjectWindowlessImpl<CCircCtl>,
  37. public IConnectionPointContainerImpl<CCircCtl>,
  38. public CProxy_CircEvents<CCircCtl>,
  39. public IDataObjectImpl<CCircCtl>,
  40. public ISpecifyPropertyPagesImpl<CCircCtl>,
  41. public IPropertyNotifySinkCP<CCircCtl, CComDynamicUnkArray >,
  42. public IPersistPropertyBagImpl<CCircCtl>,
  43. public IPerPropertyBrowsingImpl<CCircCtl>,
  44. public IOleLinkImpl<CCircCtl>,
  45. public IRunnableObjectImpl<CCircCtl>
  46. {
  47. public:
  48. CCircCtl()
  49. {
  50. m_bEnabled = TRUE;
  51. m_bstrCaption = _T("ATL 3.0 Rules");
  52. m_bRequiresSave = TRUE;
  53. m_hPalette = NULL;
  54. m_hWnd = NULL;
  55. m_clrForeColor = RGB(255, 0, 0);
  56. m_clrBackColor = RGB(0, 0, 255);
  57. }
  58. ~CCircCtl()
  59. {
  60. ATLTRACE(_T("I'm out of heren"));
  61. }
  62. static LPCTSTR GetWindowClassName() {return _T("CCircCtl");}
  63. //DECLARE_NOT_AGGREGATABLE(CCircCtl)
  64. DECLARE_REGISTRY_RESOURCEID(IDR_CircCtl)
  65. DECLARE_GET_CONTROLLING_UNKNOWN()
  66. BEGIN_COM_MAP(CCircCtl)
  67. COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
  68. COM_INTERFACE_ENTRY(ICircCtl)
  69. COM_INTERFACE_ENTRY(IDispatch)
  70. COM_INTERFACE_ENTRY_IID(IID_IViewObject, IViewObjectEx)
  71. COM_INTERFACE_ENTRY_IID(IID_IViewObject2, IViewObjectEx)
  72. COM_INTERFACE_ENTRY(IViewObjectEx)
  73. COM_INTERFACE_ENTRY(IDataObject)
  74. COM_INTERFACE_ENTRY_IID(IID_IOleWindow, IOleInPlaceObjectWindowless)
  75. COM_INTERFACE_ENTRY_IID(IID_IOleInPlaceObject, IOleInPlaceObjectWindowless)
  76. COM_INTERFACE_ENTRY(IOleInPlaceObjectWindowless)
  77. COM_INTERFACE_ENTRY(IOleInPlaceActiveObject)
  78. COM_INTERFACE_ENTRY(IOleControl)
  79. COM_INTERFACE_ENTRY(IOleObject)
  80. COM_INTERFACE_ENTRY(IQuickActivate)
  81. COM_INTERFACE_ENTRY(IPersistStorage)
  82. COM_INTERFACE_ENTRY(IPersistStreamInit)
  83. COM_INTERFACE_ENTRY(ISpecifyPropertyPages)
  84. COM_INTERFACE_ENTRY(IPersistPropertyBag)
  85. COM_INTERFACE_ENTRY(IPerPropertyBrowsing)
  86. COM_INTERFACE_ENTRY(IOleLink)
  87. COM_INTERFACE_ENTRY(IRunnableObject)
  88. COM_INTERFACE_ENTRY(IProvideClassInfo)
  89. COM_INTERFACE_ENTRY(IProvideClassInfo2)
  90. COM_INTERFACE_ENTRY_IID(IID_IPersist, IPersistPropertyBag)
  91. COM_INTERFACE_ENTRY(IConnectionPointContainer)
  92. //  COM_INTERFACE_ENTRY(ISupportErrorInfo)
  93. //  COM_INTERFACE_ENTRY(IPointerInactive)
  94. END_COM_MAP()
  95. BEGIN_CONNECTION_POINT_MAP(CCircCtl)
  96. CONNECTION_POINT_ENTRY(IID_IPropertyNotifySink)
  97. CONNECTION_POINT_ENTRY(DIID__CircEvents)
  98. END_CONNECTION_POINT_MAP()
  99. BEGIN_MSG_MAP(CCircCtl)
  100. MESSAGE_HANDLER(WM_PAINT, OnPaint)
  101. MESSAGE_HANDLER(WM_CHAR, OnChar)
  102. MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
  103. END_MSG_MAP()
  104. BEGIN_PROPERTY_MAP(CCircCtl)
  105. PROP_ENTRY("Caption", DISPID_CAPTION, CLSID_CCircProps)
  106. PROP_ENTRY("Enabled", DISPID_ENABLED, CLSID_CCircProps)
  107. PROP_ENTRY("ForeColor", DISPID_FORECOLOR, CLSID_StockColorPage)
  108. PROP_ENTRY("BackColor", DISPID_BACKCOLOR, CLSID_StockColorPage)
  109. PROP_ENTRY("Font", DISPID_FONT, CLSID_StockFontPage)
  110. END_PROPERTY_MAP()
  111. // ISupportsErrorInfo
  112. STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
  113. // Implementation
  114. public:
  115. HRESULT OnDraw(ATL_DRAWINFO& di);
  116. LRESULT OnChar(UINT, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  117. {
  118. Fire_KeyPress(static_cast<short>(wParam));
  119. return 0;
  120. }
  121. STDMETHOD(DoVerb)(LONG iVerb,LPMSG lpmsg, IOleClientSite *pActiveSite,
  122.    LONG lindex, HWND hwndParent, LPCRECT lprcPosRect)
  123. {
  124. if (iVerb == 1)
  125. return IOleObjectImpl<CCircCtl>::DoVerb(OLEIVERB_PROPERTIES, lpmsg, pActiveSite,
  126. lindex, hwndParent, lprcPosRect);
  127. if (iVerb == 2)
  128. return IOleObjectImpl<CCircCtl>::DoVerb(OLEIVERB_SHOW, lpmsg, pActiveSite,
  129. lindex, hwndParent, lprcPosRect);
  130. return IOleObjectImpl<CCircCtl>::DoVerb(iVerb, lpmsg, pActiveSite,
  131. lindex, hwndParent, lprcPosRect);
  132. }
  133. STDMETHOD(QueryHitPoint)(DWORD dwAspect, LPCRECT pRectBounds, POINT ptlLoc, LONG /* lCloseHint */, DWORD *pHitResult)
  134. {
  135. *pHitResult = HITRESULT_OUTSIDE;
  136. if (dwAspect == DVASPECT_CONTENT)
  137. {
  138. if (PtInRect(pRectBounds, ptlLoc))
  139. {
  140. HRGN hRgn = ::CreateEllipticRgn(pRectBounds->left, pRectBounds->top, pRectBounds->right + 1, pRectBounds->bottom + 1);
  141. if (PtInRegion(hRgn, ptlLoc.x, ptlLoc.y))
  142. *pHitResult = HITRESULT_HIT;
  143. DeleteObject(hRgn);
  144. }
  145. }
  146. return S_OK;
  147. }
  148. LRESULT OnLButtonDown(UINT, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  149. {
  150. Fire_Click();
  151. MessageBeep(MB_OK);
  152. //      FireDataChange();
  153. return 0;
  154. }
  155. LRESULT OnCreate(UINT, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  156. {
  157. // Won't be in here unless window based and active
  158. RECT rc;
  159. ::GetClientRect(m_hWnd, &rc);
  160. HRGN hRgn = ::CreateEllipticRgn(rc.left, rc.top, rc.right + 1, rc.bottom + 1);
  161. ::SetWindowRgn(m_hWnd, hRgn, FALSE);
  162. return 0;
  163. }
  164. STDMETHOD(QuickActivate)(QACONTAINER *pqacontainer, QACONTROL *pqacontrol)
  165. {
  166. m_hPalette = pqacontainer->hpal;
  167. return IQuickActivateImpl<CCircCtl>::QuickActivate(pqacontainer, pqacontrol);
  168. }
  169. public:
  170. BOOL m_bEnabled;
  171. HPALETTE m_hPalette;
  172. CComBSTR m_bstrCaption;
  173. OLE_COLOR m_clrBackColor;
  174. OLE_COLOR m_clrForeColor;
  175. CComPtr<IFontDisp> m_pFont;
  176. };