MSegment.h
资源名称:DELTA_PLC.rar [点击查看]
上传用户:hailongwei
上传日期:2020-11-29
资源大小:5839k
文件大小:5k
源码类别:
单片机开发
开发平台:
Visual C++
- // MSegment.h : CMSegment 的声明
- #pragma once
- #include "resource.h" // 主符号
- #include <atlctl.h>
- #include "DELTAPLC.h"
- #include "_IMSegmentEvents_CP.h"
- #include "cnComm.h"
- #define WM_MYSELF WM_USER + 619 // WPARAM 端口号
- // CMSegment
- class ATL_NO_VTABLE CMSegment :
- public CComObjectRootEx<CComSingleThreadModel>,
- public CStockPropImpl<CMSegment, IMSegment>,
- public IPersistStreamInitImpl<CMSegment>,
- public IOleControlImpl<CMSegment>,
- public IOleObjectImpl<CMSegment>,
- public IOleInPlaceActiveObjectImpl<CMSegment>,
- public IViewObjectExImpl<CMSegment>,
- public IOleInPlaceObjectWindowlessImpl<CMSegment>,
- public ISupportErrorInfo,
- public IConnectionPointContainerImpl<CMSegment>,
- public CProxy_IMSegmentEvents<CMSegment>,
- public IPersistStorageImpl<CMSegment>,
- public ISpecifyPropertyPagesImpl<CMSegment>,
- public IQuickActivateImpl<CMSegment>,
- public IDataObjectImpl<CMSegment>,
- public IProvideClassInfo2Impl<&CLSID_MSegment, &__uuidof(_IMSegmentEvents), &LIBID_DELTAPLCLib>,
- public CComCoClass<CMSegment, &CLSID_MSegment>,
- public CComControl<CMSegment>
- {
- public:
- CMSegment()
- {
- m_bWindowOnly = true;
- // Don't allow a resize
- m_bAutoSize = true;
- // Set the initial size
- SIZEL size = {32, 32};
- AtlPixelToHiMetric( &size, &m_sizeExtent );
- // Make sure the natural extent is the correct size too
- m_sizeNatural = m_sizeExtent;
- //
- for ( int i = 0; i < 256; i++ )
- {
- m_notify[i] = false;
- }
- //
- doinit();
- }
- DECLARE_OLEMISC_STATUS(OLEMISC_RECOMPOSEONRESIZE |
- OLEMISC_CANTLINKINSIDE |
- OLEMISC_INSIDEOUT |
- OLEMISC_ACTIVATEWHENVISIBLE |
- OLEMISC_SETCLIENTSITEFIRST
- )
- DECLARE_REGISTRY_RESOURCEID(IDR_MSEGMENT)
- BEGIN_COM_MAP(CMSegment)
- COM_INTERFACE_ENTRY(IMSegment)
- COM_INTERFACE_ENTRY(IDispatch)
- COM_INTERFACE_ENTRY(IViewObjectEx)
- COM_INTERFACE_ENTRY(IViewObject2)
- COM_INTERFACE_ENTRY(IViewObject)
- COM_INTERFACE_ENTRY(IOleInPlaceObjectWindowless)
- COM_INTERFACE_ENTRY(IOleInPlaceObject)
- COM_INTERFACE_ENTRY2(IOleWindow, IOleInPlaceObjectWindowless)
- COM_INTERFACE_ENTRY(IOleInPlaceActiveObject)
- COM_INTERFACE_ENTRY(IOleControl)
- COM_INTERFACE_ENTRY(IOleObject)
- COM_INTERFACE_ENTRY(IPersistStreamInit)
- COM_INTERFACE_ENTRY2(IPersist, IPersistStreamInit)
- COM_INTERFACE_ENTRY(ISupportErrorInfo)
- COM_INTERFACE_ENTRY(IConnectionPointContainer)
- COM_INTERFACE_ENTRY(ISpecifyPropertyPages)
- COM_INTERFACE_ENTRY(IQuickActivate)
- COM_INTERFACE_ENTRY(IPersistStorage)
- COM_INTERFACE_ENTRY(IDataObject)
- COM_INTERFACE_ENTRY(IProvideClassInfo)
- COM_INTERFACE_ENTRY(IProvideClassInfo2)
- END_COM_MAP()
- BEGIN_PROP_MAP(CMSegment)
- PROP_DATA_ENTRY("_cx", m_sizeExtent.cx, VT_UI4)
- PROP_DATA_ENTRY("_cy", m_sizeExtent.cy, VT_UI4)
- // 示例项
- // PROP_ENTRY("Property Description", dispid, clsid)
- // PROP_PAGE(CLSID_StockColorPage)
- END_PROP_MAP()
- BEGIN_CONNECTION_POINT_MAP(CMSegment)
- CONNECTION_POINT_ENTRY(__uuidof(_IMSegmentEvents))
- END_CONNECTION_POINT_MAP()
- BEGIN_MSG_MAP(CMSegment)
- MESSAGE_HANDLER(ON_COM_RECEIVE, OnReceivedData)
- MESSAGE_HANDLER(WM_TIMER, OnTimer)
- MESSAGE_HANDLER(WM_MYSELF, OnMySelf)
- CHAIN_MSG_MAP(CComControl<CMSegment>)
- DEFAULT_REFLECTION_HANDLER()
- END_MSG_MAP()
- // 处理程序原型:
- // LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
- // LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
- // LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
- // ISupportsErrorInfo
- STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid)
- {
- static const IID* arr[] =
- {
- &IID_IMSegment,
- };
- for (int i=0; i<sizeof(arr)/sizeof(arr[0]); i++)
- {
- if (InlineIsEqualGUID(*arr[i], riid))
- return S_OK;
- }
- return S_FALSE;
- }
- // IViewObjectEx
- DECLARE_VIEW_STATUS(VIEWSTATUS_SOLIDBKGND | VIEWSTATUS_OPAQUE)
- // IMSegment
- public:
- HRESULT OnDraw(ATL_DRAWINFO& di)
- {
- HBITMAP bitmap = LoadBitmap( ATL::_AtlBaseModule.GetResourceInstance(), MAKEINTRESOURCE( IDB_MSEGMENT ) );
- HDC hdc = di.hdcDraw;
- HDC hMemDC = ::CreateCompatibleDC( hdc );
- SelectObject(hMemDC,bitmap);
- ::BitBlt( hdc, 0, 0, 32, 32, hMemDC, 0, 0, SRCCOPY );
- ::DeleteObject( bitmap );
- ::DeleteDC( hMemDC );
- return S_OK;
- }
- DECLARE_PROTECT_FINAL_CONSTRUCT()
- HRESULT FinalConstruct()
- {
- return S_OK;
- }
- void FinalRelease()
- {
- }
- private:
- //变量
- cnComm comm;//串口操作对象
- bool data[256];
- bool m_data[256];
- bool m_notify[256];
- int bz;
- char m_Char1[300];//数据标识符
- int m_index;
- bool m_DataReceived;
- bool m_link;
- bool m_allowsend;
- long m_NoneInterval;
- //函数
- void doPraseString(char* ps);
- bool doWaitOpenLink( void );
- void doinit(void);
- long doChartToLong(char s);
- void doDelay(long TimeSpan);
- public:
- LRESULT OnReceivedData(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
- LRESULT OnTimer(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
- LRESULT OnMySelf(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
- STDMETHOD(OpenLink)(LONG Comport, BSTR CommString);
- STDMETHOD(CloseLink)(void);
- STDMETHOD(GetLink)(VARIANT_BOOL* pVal);
- STDMETHOD(GetBit)(LONG Addr, VARIANT_BOOL* pVal);
- STDMETHOD(PutBit)(LONG Addr, VARIANT_BOOL OnOff);
- STDMETHOD(SetNotify)(LONG Addr, VARIANT_BOOL AllowNotify);
- STDMETHOD(Delay)(LONG TimeSpan);
- };
- OBJECT_ENTRY_AUTO(__uuidof(MSegment), CMSegment)