Environment: Win 98/NT/2000/Me/XP Outlook (Office 9.0)
Here is a sample that would easily integrate with the outlook application and would respond to some usual events.
Even though there is documentation available for Outlook automation objects, the naming convention which is used is very confusing and misleading. Class ‘Inspectors’ can be used as a mail watcher to allow notification when a mail is opened by the user.
In the same way class ‘Explorer’ is used to display mails in the mail folder.
Now you know why we need this sample!!.
Note: You need to run this application only after opening Outlook.
// Following are the includes you might need to
// find the actual location and modify following imports
#import “C:\Program Files\Common Files\Designer\msaddndr.dll”
#import “D:\Microsoft Office\Office\Mso9.dll”
#import “D:\Microsoft Office\Office\Msoutl9.olb”…
//
//connect to outlook & watch for some events
if(m_outlook == 0) {
if(m_outlook.CreateInstance(__uuidof(Outlook::Application)) == S_OK)
{
Outlook::_InspectorsPtr inspectors;
//get inspectors and make event sink connection
if(m_outlook->get_Inspectors(&inspectors) == S_OK) {
//use helper method to sink into
CEventSink::Advice( inspectors,
GetIDispatch(FALSE),
__uuidof(Outlook::InspectorsEvents));
}
//
// get explorer(mail listing window)
// make event sink connetion
new CEventSink(*this,m_outlook->ActiveExplorer());
}
}…
//
// when mail is opened in a seperate window(following
// event is fired)
void COutlooksampleDlg::NewInspector(IDispatch *disp)
{
// connect a event sink for this mail
new CEventSink(*this,disp);
}…
//
// when mail shown in preview windowvoid CEventSink::SelectionChange()
{
long count = 0;
if(m_explorer != 0) {
Outlook::SelectionPtr& selection =m_explorer->Selection;
if(selection->get_Count(&count) == S_OK && count > 0)
{
Outlook::_MailItemPtr mailItem = selection->Item((short)1);
//display this in edit box
m_dlg.DisplayMailItem(mailItem);
}
}
}