Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Building an Office2K COM addin with VC++/ATL

, 30 Apr 2003
This article shows how to program an Outlook2000/2K+ COM addin using a pure ATL COM object.
outlookaddin.zip
OutlookAddinps.mk
OutlookAddin.dsp
OutlookAddin.dsw
Addin.rgs
LitePage.rgs
Page.rgs
PropPage.rgs
OutlookAddin.tlb
bitmap1.bmp
litepage.bmp
proppage.bmp
OutlookAddin.def
OutlookAddinps.def
OutlookAddin.plg
////////////////////////////////////////////////////////////////////////////
//	Copyright : Amit Dey 2002
//
//	Email :amitdey@joymail.com
//
//	This code may be used in compiled form in any way you desire. This
//	file may be redistributed unmodified by any means PROVIDING it is 
//	not sold for profit without the authors written consent, and 
//	providing that this notice and the authors name is included.
//
//	This file is provided 'as is' with no expressed or implied warranty.
//	The author accepts no liability if it causes any damage to your computer.
//
//	Do expect bugs.
//	Please let me know of any bugs/mods/improvements.
//	and I will try to fix/incorporate them into this file.
//	Enjoy!
//
//	Description : Outlook2K Addin 
////////////////////////////////////////////////////////////////////////////

// PropPage.h : Declaration of the CPropPage

#ifndef __PROPPAGE_H_
#define __PROPPAGE_H_

#include "resource.h"       // main symbols
#include <atlctl.h>
#import "C:\Program Files\Microsoft Office\Office\msoutl9.olb" raw_interfaces_only
#include <atlcontrols.h>
using namespace ATLControls;
/////////////////////////////////////////////////////////////////////////////
// CPropPage
class ATL_NO_VTABLE CPropPage : 
	public CComObjectRootEx<CComSingleThreadModel>,
	public IDispatchImpl<IPropPage, &IID_IPropPage, &LIBID_OUTLOOKADDINLib>,
	public CComCompositeControl<CPropPage>,
	public IPersistStreamInitImpl<CPropPage>,
	public IOleControlImpl<CPropPage>,
	public IOleObjectImpl<CPropPage>,
	public IOleInPlaceActiveObjectImpl<CPropPage>,
	public IViewObjectExImpl<CPropPage>,
	public IOleInPlaceObjectWindowlessImpl<CPropPage>,
	public IPersistStorageImpl<CPropPage>,
	public ISpecifyPropertyPagesImpl<CPropPage>,
	public IQuickActivateImpl<CPropPage>,
	public IDataObjectImpl<CPropPage>,
	public IProvideClassInfo2Impl<&CLSID_PropPage, NULL, &LIBID_OUTLOOKADDINLib>,
	public CComCoClass<CPropPage, &CLSID_PropPage>,
	public IPersistPropertyBagImpl<CPropPage>,
    public IDispatchImpl<PropertyPage,&__uuidof(PropertyPage),&LIBID_OUTLOOKADDINLib>
{
public:
	CPropPage()
	{
		m_bWindowOnly = TRUE;
		CalcExtent(m_sizeExtent);
	}

DECLARE_REGISTRY_RESOURCEID(IDR_PROPPAGE)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CPropPage)
	COM_INTERFACE_ENTRY(IPropPage)
	COM_INTERFACE_ENTRY2(IDispatch,IPropPage)
	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(ISpecifyPropertyPages)
	COM_INTERFACE_ENTRY(IQuickActivate)
	COM_INTERFACE_ENTRY(IPersistStorage)
	COM_INTERFACE_ENTRY(IDataObject)
	COM_INTERFACE_ENTRY(IProvideClassInfo)
	COM_INTERFACE_ENTRY(IProvideClassInfo2)
	COM_INTERFACE_ENTRY(IPersistPropertyBag) 
	COM_INTERFACE_ENTRY(Outlook::PropertyPage) 
END_COM_MAP()

BEGIN_PROP_MAP(CPropPage)
	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_MSG_MAP(CPropPage)
CHAIN_MSG_MAP(CComCompositeControl<CPropPage>)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
COMMAND_HANDLER(IDC_BLUE, BN_CLICKED, OnClickedBlue)
COMMAND_HANDLER(IDC_GREEN, BN_CLICKED, OnClickedGreen)
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(CPropPage)
	//Make sure the Event Handlers have __stdcall calling convention
END_SINK_MAP()

STDMETHOD(GetControlInfo)(LPCONTROLINFO pCI);
STDMETHOD(SetClientSite)(IOleClientSite *pSite);

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



// IViewObjectEx
	DECLARE_VIEW_STATUS(0)

// IPropPage
public:

	enum { IDD = IDD_PROPPAGE };
// PropertyPage
	STDMETHOD(GetPageInfo)(BSTR * HelpFile, LONG * HelpContext);
	STDMETHOD(get_Dirty)(VARIANT_BOOL * Dirty);
	STDMETHOD(Apply)();
	
	

	private:
		CComVariant m_fDirty;
		CComPtr<Outlook::PropertyPageSite> m_pPropPageSite; 


	LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
	{
		// TODO : Add Code for message handler. Call DefWindowProc if necessary.
		CWindow pWnd ;
		pWnd.Attach(GetDlgItem(IDC_RED));
		ATLASSERT(pWnd);
		CButton pButton =pWnd.Detach();  
		pButton.SetCheck(1);
		return 0;
	}
	LRESULT OnClickedBlue(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
	{
		// TODO : Add Code for control notification handler.
		m_fDirty = true;
		m_pPropPageSite->OnStatusChange();
		return 0;
	}
	LRESULT OnClickedGreen(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
	{
		// TODO : Add Code for control notification handler.
		return 0;
	}
};

#endif //__PROPPAGE_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

Share

About the Author

Amit Dey
Web Developer
India India
Amit Dey is a freelance programmer from Bangalore,India. Chiefly programming VC++/MFC, ATL/COM and PocketPC and Palm platforms. Apart from programming and CP, he is a self-taught guitar and keyboard player.
 
He can be contacted at visualcdev@hotmail.com
 

| Advertise | Privacy | Mobile
Web03 | 2.8.141022.2 | Last Updated 1 May 2003
Article Copyright 2002 by Amit Dey
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid