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

Windows编程

开发平台:

Visual C++

  1. // CDInfo1.h : Declaration of the CCDInfo
  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 <commctrl.h>
  13. #include "resource.h"       // main symbols
  14. #include "CCDInfo.h"
  15. #include "CPCDInfo.h"
  16. #define PI 3.14159265358979
  17. #define BORDER 5
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CCDInfo
  20. class CCDInfo :
  21. public CComObjectRoot,
  22. public CComCoClass<CCDInfo, &CLSID_CCDInfo>,
  23. public CComControl<CCDInfo>,
  24. public IDispatchImpl<ICDInfo, &IID_ICDInfo, &LIBID_CDINFOLib>,
  25. public IProvideClassInfo2Impl<&CLSID_CCDInfo, &DIID_CDEvents, &LIBID_CDINFOLib>,
  26. public IPersistStreamInitImpl<CCDInfo>,
  27. public IPersistStorageImpl<CCDInfo>,
  28. public IQuickActivateImpl<CCDInfo>,
  29. public IOleControlImpl<CCDInfo>,
  30. public IOleObjectImpl<CCDInfo>,
  31. public IOleInPlaceActiveObjectImpl<CCDInfo>,
  32. public IViewObjectExImpl<CCDInfo>,
  33. public IOleInPlaceObjectWindowlessImpl<CCDInfo>,
  34. public IDataObjectImpl<CCDInfo>,
  35. public IPropertyNotifySinkCP<CCDInfo>,
  36. public IRunnableObjectImpl<CCDInfo>,
  37. public IPerPropertyBrowsingImpl<CCDInfo>,
  38. public IConnectionPointContainerImpl<CCDInfo>,
  39. public CProxyCDEvents<CCDInfo>,
  40. public IOleLinkImpl<CCDInfo>
  41. {
  42. public:
  43. CCDInfo()
  44. {
  45. ZeroMemory(&m_rcEllipse, sizeof(RECT));
  46. m_hPalette = NULL;
  47. m_wndToolTip.m_hWnd = NULL;
  48. }
  49. CWindow m_wndToolTip;
  50. DECLARE_REGISTRY_RESOURCEID(IDR_CDInfo)
  51. BEGIN_COM_MAP(CCDInfo)
  52. COM_INTERFACE_ENTRY(ICDInfo)
  53. COM_INTERFACE_ENTRY(IDispatch)
  54. COM_INTERFACE_ENTRY_IMPL(IViewObjectEx)
  55. COM_INTERFACE_ENTRY_IMPL_IID(IID_IViewObject2, IViewObjectEx)
  56. COM_INTERFACE_ENTRY_IMPL_IID(IID_IViewObject, IViewObjectEx)
  57. COM_INTERFACE_ENTRY_IMPL(IOleInPlaceObjectWindowless)
  58. COM_INTERFACE_ENTRY_IMPL_IID(IID_IOleInPlaceObject, IOleInPlaceObjectWindowless)
  59. COM_INTERFACE_ENTRY_IMPL_IID(IID_IOleWindow, IOleInPlaceObjectWindowless)
  60. COM_INTERFACE_ENTRY_IMPL(IOleInPlaceActiveObject)
  61. COM_INTERFACE_ENTRY_IMPL(IOleControl)
  62. COM_INTERFACE_ENTRY_IMPL(IOleObject)
  63. COM_INTERFACE_ENTRY_IMPL(IQuickActivate)
  64. COM_INTERFACE_ENTRY_IMPL(IPersistStorage)
  65. COM_INTERFACE_ENTRY_IMPL(IPersistStreamInit)
  66. COM_INTERFACE_ENTRY_IMPL(IDataObject)
  67. COM_INTERFACE_ENTRY(IProvideClassInfo)
  68. COM_INTERFACE_ENTRY(IProvideClassInfo2)
  69. COM_INTERFACE_ENTRY_IMPL(IRunnableObject)
  70. COM_INTERFACE_ENTRY_IMPL(IPerPropertyBrowsing)
  71. COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
  72. COM_INTERFACE_ENTRY_IMPL(IOleLink)
  73. END_COM_MAP()
  74. BEGIN_PROPERTY_MAP(CCDInfo)
  75. // PROP_ENTRY(OLESTR("Description"), dispid, clsid)
  76. // PROP_PAGE(clsid)
  77. END_PROPERTY_MAP()
  78. BEGIN_CONNECTION_POINT_MAP(CCDInfo)
  79. CONNECTION_POINT_ENTRY(IID_IPropertyNotifySink)
  80. CONNECTION_POINT_ENTRY(DIID_CDEvents)
  81. END_CONNECTION_POINT_MAP()
  82. BEGIN_MSG_MAP(CCDInfo)
  83. MESSAGE_HANDLER(WM_PAINT         , OnPaint)
  84. MESSAGE_HANDLER(WM_ERASEBKGND , OnEraseBkgnd)
  85. MESSAGE_HANDLER(WM_MOUSEMOVE     , OnMouseMove)
  86. MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
  87. MESSAGE_HANDLER(WM_LBUTTONUP  , RelayEvent)
  88. MESSAGE_HANDLER(WM_RBUTTONDOWN, RelayEvent)
  89. MESSAGE_HANDLER(WM_RBUTTONUP  , RelayEvent)
  90. MESSAGE_HANDLER(WM_MBUTTONDOWN, RelayEvent)
  91. MESSAGE_HANDLER(WM_MBUTTONUP  , RelayEvent)
  92. END_MSG_MAP()
  93. LRESULT OnEraseBkgnd(UINT /* uMsg */, WPARAM /* wParam */, LPARAM /* lParam */, BOOL& /* bHandled */)
  94. {
  95. // We don't paint the background here as it is done in the OnDraw function.
  96. // This is to stop flickering when a tooltip is displayed.
  97. return 1;
  98. }
  99. HRESULT OnDraw(ATL_DRAWINFO& di);
  100. LRESULT OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  101. LRESULT OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  102. LRESULT RelayEvent(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /* bHandled */)
  103. {
  104. if (m_wndToolTip.m_hWnd)
  105. {
  106. MSG msg;
  107. msg.lParam  = lParam;
  108. msg.wParam  = wParam;
  109. msg.message = uMsg;
  110. msg.hwnd    = m_hTheWnd;
  111. ::SendMessage(m_wndToolTip.m_hWnd, TTM_RELAYEVENT, 0, (LPARAM)&msg);
  112. }
  113. return 0;
  114. }
  115. HRESULT InPlaceActivate(LONG iVerb, const RECT* prcPosRect=NULL)
  116. {
  117. HRESULT hr;
  118. hr = CComControlBase::InPlaceActivate(iVerb, prcPosRect);
  119. if (m_wndToolTip.m_hWnd == NULL)
  120. {
  121. GetTheWindow();
  122. CreateTooltipWindow();
  123. }
  124. return hr;
  125. }
  126. STDMETHOD(InPlaceDeactivate)(void)
  127. {
  128. if (m_wndToolTip.m_hWnd)
  129. m_wndToolTip.DestroyWindow();
  130. return IOleInPlaceObjectWindowlessImpl<CCDInfo>::InPlaceDeactivate();
  131. }
  132. STDMETHOD(QuickActivate)(QACONTAINER *pqacontainer, QACONTROL *pqacontrol)
  133. {
  134. m_hPalette = pqacontainer->hpal;
  135. return IQuickActivateImpl<CCDInfo>::QuickActivate(pqacontainer, pqacontrol);
  136. }
  137. // ICDInfo
  138. STDMETHOD(get_Tracks)(short* pTracks)
  139. {
  140. *pTracks = m_cd.GetNumberOfTracks();
  141. return S_OK;
  142. }
  143. STDMETHOD(put_Tracks)(short nTracks)
  144. {
  145. m_dblCurrentAngle = 3 * PI / 2; // Reset the drawing angle
  146. m_cd.SetNumberOfTracks(nTracks);
  147. return S_OK;
  148. }
  149. STDMETHOD(get_Length)(short nTrack, short* pLength)
  150. {
  151. *pLength = m_cd.GetTrackLength(nTrack);
  152. return S_OK;
  153. }
  154. STDMETHOD(put_Length)(short nTrack, short nLength)
  155. {
  156. m_cd.SetTrackLength(nTrack, nLength);
  157. return S_OK;
  158. }
  159. STDMETHOD(get_TotalLength)(short* pLength)
  160. {
  161. *pLength = m_cd.GetTotalLength();
  162. return S_OK;
  163. }
  164. STDMETHOD(Read)(short* pTracks)
  165. {
  166. m_dblCurrentAngle = 3 * PI / 2; // Reset the drawing angle
  167. *pTracks = m_cd.Read();
  168. Redraw();
  169. return S_OK;
  170. }
  171. STDMETHOD(Redraw)()
  172. {
  173. if (m_bWndLess)
  174. m_spInPlaceSite->InvalidateRect(NULL, TRUE);
  175. else if (m_hWnd)
  176. InvalidateRect(NULL, TRUE);
  177. return S_OK;
  178. }
  179. STDMETHOD(Play)(short nTrack)
  180. {
  181. DrawToTrack(nTrack);
  182. m_cd.Play(nTrack);
  183. return S_OK;
  184. }
  185. // We override the next couple of methods to trap when our size changes
  186. // so we can set our m_rcEllipse accordingly
  187. STDMETHOD(SetExtent)(DWORD  dwDrawAspect, SIZEL *psizel)
  188. {
  189. HRESULT hr = IOleObjectImpl<CCDInfo>::SetExtent(dwDrawAspect, psizel);
  190. m_rcEllipse = m_rcPos;
  191. ReduceRect(&m_rcEllipse);
  192. if (!m_bWndLess)
  193. OffsetRect(&m_rcEllipse, -m_rcEllipse.left+BORDER, -m_rcEllipse.top+BORDER);
  194. return hr;
  195. }
  196. STDMETHOD(SetObjectRects)(LPCRECT prcPos,LPCRECT prcClip)
  197. {
  198. HRESULT hr = IOleInPlaceObjectWindowlessImpl<CCDInfo>::SetObjectRects(prcPos, prcClip);
  199. m_rcEllipse = m_rcPos;
  200. ReduceRect(&m_rcEllipse);
  201. if (!m_bWndLess)
  202. OffsetRect(&m_rcEllipse, -m_rcEllipse.left+BORDER, -m_rcEllipse.top+BORDER);
  203. return hr;
  204. }
  205. void ReduceRect(RECT* pRect)
  206. {
  207. InflateRect(pRect, BORDER * ((pRect->left < pRect->right) ? -1 : 1),
  208. BORDER * ((pRect->top < pRect->bottom) ? -1 : 1));
  209. }
  210. HWND        m_hTheWnd;
  211. private:
  212. void        CreateTooltipWindow();
  213. void        GetTheWindow();
  214. void        DrawOffScreen(HDC hdc, RECT rc);
  215. void        DrawCD(HDC hdc, RECT rc);
  216. POINT       CalcPoint(POINT ptCenter, double dwRadius, double fAngle);
  217. double      CalcAngle(POINT ptCenter, POINT point);
  218. short       GetTrackFromPoint(const POINT& pt);
  219. BOOL        InEllipse(RECT& rect, POINT point);
  220. double      GetTrackAngle(short nWantedTrack);
  221. void        DrawToTrack(short nTrack);
  222. short       m_nCurrentTrack;
  223. short       m_nMouseTrack;
  224. CDInfo      m_cd;
  225. RECT        m_rcEllipse;
  226. HPALETTE    m_hPalette;
  227. double      m_dblCurrentAngle;
  228. static COLORREF     m_colSegment[];
  229. };