MSegment.h
上传用户:hailongwei
上传日期:2020-11-29
资源大小:5839k
文件大小:5k
源码类别:

单片机开发

开发平台:

Visual C++

  1. // MSegment.h : CMSegment 的声明
  2. #pragma once
  3. #include "resource.h"       // 主符号
  4. #include <atlctl.h>
  5. #include "DELTAPLC.h"
  6. #include "_IMSegmentEvents_CP.h"
  7. #include "cnComm.h"
  8. #define WM_MYSELF WM_USER + 619  //  WPARAM 端口号
  9. // CMSegment
  10. class ATL_NO_VTABLE CMSegment : 
  11. public CComObjectRootEx<CComSingleThreadModel>,
  12. public CStockPropImpl<CMSegment, IMSegment>,
  13. public IPersistStreamInitImpl<CMSegment>,
  14. public IOleControlImpl<CMSegment>,
  15. public IOleObjectImpl<CMSegment>,
  16. public IOleInPlaceActiveObjectImpl<CMSegment>,
  17. public IViewObjectExImpl<CMSegment>,
  18. public IOleInPlaceObjectWindowlessImpl<CMSegment>,
  19. public ISupportErrorInfo,
  20. public IConnectionPointContainerImpl<CMSegment>,
  21. public CProxy_IMSegmentEvents<CMSegment>, 
  22. public IPersistStorageImpl<CMSegment>,
  23. public ISpecifyPropertyPagesImpl<CMSegment>,
  24. public IQuickActivateImpl<CMSegment>,
  25. public IDataObjectImpl<CMSegment>,
  26. public IProvideClassInfo2Impl<&CLSID_MSegment, &__uuidof(_IMSegmentEvents), &LIBID_DELTAPLCLib>,
  27. public CComCoClass<CMSegment, &CLSID_MSegment>,
  28. public CComControl<CMSegment>
  29. {
  30. public:
  31. CMSegment()
  32. {
  33. m_bWindowOnly = true;
  34. // Don't allow a resize
  35. m_bAutoSize = true;
  36. // Set the initial size
  37. SIZEL size = {32, 32};
  38. AtlPixelToHiMetric( &size, &m_sizeExtent );
  39. // Make sure the natural extent is the correct size too
  40. m_sizeNatural = m_sizeExtent;
  41. //
  42. for ( int i = 0; i < 256; i++ )
  43. {
  44. m_notify[i] = false;
  45. }
  46. //
  47. doinit();
  48. }
  49. DECLARE_OLEMISC_STATUS(OLEMISC_RECOMPOSEONRESIZE | 
  50. OLEMISC_CANTLINKINSIDE | 
  51. OLEMISC_INSIDEOUT | 
  52. OLEMISC_ACTIVATEWHENVISIBLE | 
  53. OLEMISC_SETCLIENTSITEFIRST
  54. )
  55. DECLARE_REGISTRY_RESOURCEID(IDR_MSEGMENT)
  56. BEGIN_COM_MAP(CMSegment)
  57. COM_INTERFACE_ENTRY(IMSegment)
  58. COM_INTERFACE_ENTRY(IDispatch)
  59. COM_INTERFACE_ENTRY(IViewObjectEx)
  60. COM_INTERFACE_ENTRY(IViewObject2)
  61. COM_INTERFACE_ENTRY(IViewObject)
  62. COM_INTERFACE_ENTRY(IOleInPlaceObjectWindowless)
  63. COM_INTERFACE_ENTRY(IOleInPlaceObject)
  64. COM_INTERFACE_ENTRY2(IOleWindow, IOleInPlaceObjectWindowless)
  65. COM_INTERFACE_ENTRY(IOleInPlaceActiveObject)
  66. COM_INTERFACE_ENTRY(IOleControl)
  67. COM_INTERFACE_ENTRY(IOleObject)
  68. COM_INTERFACE_ENTRY(IPersistStreamInit)
  69. COM_INTERFACE_ENTRY2(IPersist, IPersistStreamInit)
  70. COM_INTERFACE_ENTRY(ISupportErrorInfo)
  71. COM_INTERFACE_ENTRY(IConnectionPointContainer)
  72. COM_INTERFACE_ENTRY(ISpecifyPropertyPages)
  73. COM_INTERFACE_ENTRY(IQuickActivate)
  74. COM_INTERFACE_ENTRY(IPersistStorage)
  75. COM_INTERFACE_ENTRY(IDataObject)
  76. COM_INTERFACE_ENTRY(IProvideClassInfo)
  77. COM_INTERFACE_ENTRY(IProvideClassInfo2)
  78. END_COM_MAP()
  79. BEGIN_PROP_MAP(CMSegment)
  80. PROP_DATA_ENTRY("_cx", m_sizeExtent.cx, VT_UI4)
  81. PROP_DATA_ENTRY("_cy", m_sizeExtent.cy, VT_UI4)
  82. // 示例项
  83. // PROP_ENTRY("Property Description", dispid, clsid)
  84. // PROP_PAGE(CLSID_StockColorPage)
  85. END_PROP_MAP()
  86. BEGIN_CONNECTION_POINT_MAP(CMSegment)
  87. CONNECTION_POINT_ENTRY(__uuidof(_IMSegmentEvents))
  88. END_CONNECTION_POINT_MAP()
  89. BEGIN_MSG_MAP(CMSegment)
  90. MESSAGE_HANDLER(ON_COM_RECEIVE, OnReceivedData)
  91. MESSAGE_HANDLER(WM_TIMER, OnTimer)
  92. MESSAGE_HANDLER(WM_MYSELF, OnMySelf)
  93. CHAIN_MSG_MAP(CComControl<CMSegment>)
  94. DEFAULT_REFLECTION_HANDLER()
  95. END_MSG_MAP()
  96. // 处理程序原型: 
  97. //  LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  98. //  LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
  99. //  LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
  100. // ISupportsErrorInfo
  101. STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid)
  102. {
  103. static const IID* arr[] = 
  104. {
  105. &IID_IMSegment,
  106. };
  107. for (int i=0; i<sizeof(arr)/sizeof(arr[0]); i++)
  108. {
  109. if (InlineIsEqualGUID(*arr[i], riid))
  110. return S_OK;
  111. }
  112. return S_FALSE;
  113. }
  114. // IViewObjectEx
  115. DECLARE_VIEW_STATUS(VIEWSTATUS_SOLIDBKGND | VIEWSTATUS_OPAQUE)
  116. // IMSegment
  117. public:
  118. HRESULT OnDraw(ATL_DRAWINFO& di)
  119. {
  120. HBITMAP bitmap = LoadBitmap( ATL::_AtlBaseModule.GetResourceInstance(), MAKEINTRESOURCE( IDB_MSEGMENT ) );
  121. HDC hdc = di.hdcDraw; 
  122. HDC hMemDC = ::CreateCompatibleDC( hdc );
  123. SelectObject(hMemDC,bitmap);
  124. ::BitBlt( hdc, 0, 0, 32, 32, hMemDC, 0, 0, SRCCOPY );
  125. ::DeleteObject( bitmap );
  126. ::DeleteDC( hMemDC );
  127. return S_OK;
  128. }
  129. DECLARE_PROTECT_FINAL_CONSTRUCT()
  130. HRESULT FinalConstruct()
  131. {
  132. return S_OK;
  133. }
  134. void FinalRelease() 
  135. {
  136. }
  137. private:
  138. //变量
  139. cnComm comm;//串口操作对象
  140. bool data[256];
  141. bool m_data[256];
  142. bool m_notify[256];
  143. int bz;
  144. char m_Char1[300];//数据标识符
  145. int m_index;
  146. bool m_DataReceived;
  147. bool m_link;
  148. bool m_allowsend;
  149. long m_NoneInterval;
  150. //函数
  151. void doPraseString(char* ps);
  152. bool doWaitOpenLink( void );
  153. void doinit(void);
  154. long doChartToLong(char s);
  155. void doDelay(long TimeSpan);
  156. public:
  157. LRESULT OnReceivedData(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  158. LRESULT OnTimer(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
  159. LRESULT OnMySelf(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  160. STDMETHOD(OpenLink)(LONG Comport, BSTR CommString);
  161. STDMETHOD(CloseLink)(void);
  162. STDMETHOD(GetLink)(VARIANT_BOOL* pVal);
  163. STDMETHOD(GetBit)(LONG Addr, VARIANT_BOOL* pVal);
  164. STDMETHOD(PutBit)(LONG Addr, VARIANT_BOOL OnOff);
  165. STDMETHOD(SetNotify)(LONG Addr,  VARIANT_BOOL AllowNotify);
  166. STDMETHOD(Delay)(LONG TimeSpan);
  167. };
  168. OBJECT_ENTRY_AUTO(__uuidof(MSegment), CMSegment)