When creating a DTC in Visual C++, you need to make changes to the control's header file, such as SinkDTC.h
. The following code shows the differences between the generic header file provided by the wizard and the additions made to create the ATLSample control. Additions appear in boldface below. Deletions appear as strikethrough text.
Tip If you paste code from help topics into your project file, be sure to copy the line above and below the entire code sample as well. Otherwise the text you paste loses the formatting it had while in the help topic. You can also copy code from the ATLSample project.
// SinkDTC.h : Declaration of the CSinkDTC #ifndef __SINKDTC_H_ #define __SINKDTC_H_ #include "resource.h" // main symbols #include <atlctl.h> ///////////// // CSinkDTC class ATL_NO_VTABLE CSinkDTC : public CComObjectRootEx<CComSingleThreadModel>, public IDispatchImpl<ISinkDTC, &IID_ISinkDTC, &LIBID_ATLSAMPLELib>, public CComControl<CSinkDTC>, public IPersistPropertyBagImpl<CSinkDTC>, public IOleControlImpl<CSinkDTC>, public IOleObjectImpl<CSinkDTC>, public IOleInPlaceActiveObjectImpl<CSinkDTC>, public IViewObjectExImpl<CSinkDTC>, public IOleInPlaceObjectWindowlessImpl<CSinkDTC>,
public IPersistStorageImpl<CSinkDTC>,
public IPersistPropertyBag<CSinkDTC>, public ISpecifyPropertyPagesImpl<CSinkDTC>, public IQuickActivateImpl<CSinkDTC>, public IDataObjectImpl<CSinkDTC>, public IProvideClassInfo2Impl<&CLSID_SinkDTC, NULL, &LIBID_ATLSAMPLELib>, public CComCoClass<CSinkDTC, &CLSID_SinkDTC>, public IDesignTimeControl, public IActiveDesigner { public: CSinkDTC();
{ }
DECLARE_REGISTRY_RESOURCEID(IDR_SINKDTC) DECLARE_PROTECT_FINAL_CONSTRUCT() BEGIN_COM_MAP(CSinkDTC) COM_INTERFACE_ENTRY(ISinkDTC) 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(IPersistPropertyBag) COM_INTERFACE_ENTRY2(IPersist, IPersistPropertyBag) COM_INTERFACE_ENTRY(ISpecifyPropertyPages) COM_INTERFACE_ENTRY(IQuickActivate) COM_INTERFACE_ENTRY(IPersistStorage) COM_INTERFACE_ENTRY(IDataObject) COM_INTERFACE_ENTRY(IProvideClassInfo) COM_INTERFACE_ENTRY(IProvideClassInfo2) COM_INTERFACE_ENTRY(IDesignTimeControl) COM_INTERFACE_ENTRY_IID(IID_IActiveDesigner, IActiveDesigner) END_COM_MAP() BEGIN_PROP_MAP(CSinkDTC) PROP_DATA_ENTRY("_cx", m_sizeExtent.cx, VT_UI4) PROP_DATA_ENTRY("_cy", m_sizeExtent.cy, VT_UI4) // Example entries // PROP_ENTRY("Property Description", dispid, clsid) // PROP_PAGE(CLSID_StockColorPage) PROP_ENTRY("SelectedFruit", 1, CLSID_NULL) END_PROP_MAP() BEGIN_MSG_MAP(CSinkDTC) CHAIN_MSG_MAP(CComControl<CSinkDTC>) DEFAULT_REFLECTION_HANDLER() END_MSG_MAP() //Handler prototypes: //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); //IViewObjectEx DECLARE_VIEW_STATUS(VIEWSTATUS_SOLIDBKGND | VIEWSTATUS_OPAQUE) // IDesignTimeControl Methods STDMETHOD(get_DesignTimeControlSite)(IDesignTimeControlSite ** DesignTimeControlSite); STDMETHOD(putref_DesignTimeControlSite)(IDesignTimeControlSite *DesignTimeControlSite); STDMETHOD(get_DesignTimeControlSet)(BSTR * DesignTimeControlSet); STDMETHOD(OnGetChoices)(Choices * Choices); STDMETHOD(OnRebind)(Choices * Choices); STDMETHOD(OnChoiceConflict)(Choice * Choice, VARIANT_BOOL Conflict); STDMETHOD(OnChoiceChange)(ChoiceSink * ChoiceSink, dtcChoiceChange Change); STDMETHOD(OnHostingChange)(dtcHostingChange change, VARIANT_BOOL * Cancel); // IActiveDesigner Methods STDMETHOD(GetRuntimeClassID)(CLSID *pclsid); STDMETHOD(GetRuntimeMiscStatusFlags)(DWORD *dwMiscFlags); STDMETHOD(QueryPersistenceInterface)(REFIID riid); STDMETHOD(SaveRuntimeState)(REFIID riidItf, REFIID riidObj, void *pObj); STDMETHOD(GetExtensibilityObject)(IDispatch **ppvObjOut); // ISinkDTC Methods public: STDMETHOD(get_SelectedFruit)(/*[out, retval]*/ BSTR *pVal); STDMETHOD(put_SelectedFruit)(/*[in]*/ BSTR newVal); HRESULT OnDraw(ATL_DRAWINFO& di);
{ RECT& rc = *(RECT*)di.prcBounds; Rectangle(di.hdcDraw, rc.left, rc.top, rc.right, rc.bottom); SetTextAlign(di.hdcDraw, TA_CENTER|TA_BASELINE); LPCTSTR pszText = _T("ATL 3.0 : CSinkDTC"); TextOut(di.hdcDraw, (rc.left + rc.right) / 2, (rc.top + rc.bottom) / 2, pszText, lstrlen(pszText)); return S_OK; } };
private: CComPtr<IDesignTimeControlSite> m_spSite; CComPtr<ChoiceSink> m_spChoiceSink; CComBSTR m_sSelectedFruit; }; #endif //__SINKDTC_H_