home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / atl / circ / circctl.h < prev    next >
C/C++ Source or Header  |  1998-03-26  |  6KB  |  191 lines

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