Click here to Skip to main content
15,896,153 members
Articles / Desktop Programming / ATL

A Beginner's Tutorial for Connection Points Using VC++ and ATL

Rate me:
Please Sign up or sign in to vote.
4.64/5 (17 votes)
10 Apr 20025 min read 172.7K   1.5K   62  
A tutorial on how to create connection points using VC++ and ATL
// ConnCtl.h : Declaration of the CConnCtl

#ifndef __CONNCTL_H_
#define __CONNCTL_H_

#include "resource.h"       // main symbols
#include <atlctl.h>
#include "ConnectionCP.h"


/////////////////////////////////////////////////////////////////////////////
// CConnCtl
class ATL_NO_VTABLE CConnCtl : 
	public CComObjectRootEx<CComSingleThreadModel>,
	public IDispatchImpl<IConnCtl, &IID_IConnCtl, &LIBID_CONNECTIONLib>,
	public CComCompositeControl<CConnCtl>,
	public IPersistStreamInitImpl<CConnCtl>,
	public IOleControlImpl<CConnCtl>,
	public IOleObjectImpl<CConnCtl>,
	public IOleInPlaceActiveObjectImpl<CConnCtl>,
	public IViewObjectExImpl<CConnCtl>,
	public IOleInPlaceObjectWindowlessImpl<CConnCtl>,
	public IConnectionPointContainerImpl<CConnCtl>,
	public IPersistStorageImpl<CConnCtl>,
	public ISpecifyPropertyPagesImpl<CConnCtl>,
	public IQuickActivateImpl<CConnCtl>,
	public IDataObjectImpl<CConnCtl>,
	public IProvideClassInfo2Impl<&CLSID_ConnCtl, &DIID__IConnCtlEvents, &LIBID_CONNECTIONLib>,
	public IPropertyNotifySinkCP<CConnCtl>,
	public CComCoClass<CConnCtl, &CLSID_ConnCtl>,
	public CProxy_IConnCtlEvents< CConnCtl >
{
	public:
		CConnCtl();

DECLARE_REGISTRY_RESOURCEID(IDR_CONNCTL)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CConnCtl)
	COM_INTERFACE_ENTRY(IConnCtl)
	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(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)
	COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
END_COM_MAP()

BEGIN_PROP_MAP(CConnCtl)
	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)
END_PROP_MAP()

BEGIN_CONNECTION_POINT_MAP(CConnCtl)
	CONNECTION_POINT_ENTRY(IID_IPropertyNotifySink)
	CONNECTION_POINT_ENTRY(DIID__IConnCtlEvents)
END_CONNECTION_POINT_MAP()

BEGIN_MSG_MAP(CConnCtl)
	CHAIN_MSG_MAP(CComCompositeControl<CConnCtl>)
	COMMAND_HANDLER(IDC_BUTTON1, BN_CLICKED, OnClickedButton)
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);

BEGIN_SINK_MAP(CConnCtl)
	//Make sure the Event Handlers have __stdcall calling convention
END_SINK_MAP()

	STDMETHOD(OnAmbientPropertyChange)(DISPID dispid)
	{
		if (dispid == DISPID_AMBIENT_BACKCOLOR)
		{
			SetBackgroundColorFromAmbient();
			FireViewChange();
		}
		return IOleControlImpl<CConnCtl>::OnAmbientPropertyChange(dispid);
	}

// IViewObjectEx
	DECLARE_VIEW_STATUS(0)

// IConnCtl
	public:
		enum { IDD = IDD_CONNCTL };
		LRESULT OnClickedButton(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
	private:
		int		_clickCount;

		void ClickCounter();
};

#endif //__CONNCTL_H_

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions