A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Catching buttons pressing in Outlook appointment window.



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old November 26th 08, 09:05 AM posted to microsoft.public.outlook.program_addins
Sergeichik
external usenet poster
 
Posts: 21
Default Catching buttons pressing in Outlook appointment window.

I have an Outlook 2007 installed on.
I have small Outlook Add-in example (in C++) somewhere from
http://www.codeproject.com ..

I try to catch buttons, located at 'Appointment window toolbar' (in Outlook
Calendar press some date, and this window will be appear) press by the
following way:

Function OnInspectorEvent is called when new inspector being created:

CAdding private member
CTimeZonesButtonCatcher m_watch

void __stdcall CAddin::OnInspectorEvent (LPDISPATCH ctrl)
{
OutlookInspectorPtr insp(ctrl);
OutlookCommandBarsPtr bars;
HRESULT hr = insp-get_CommandBars(&bars);
m_watch.FindTimeZonesButton(bars);
m_watch.SubscribeToItemEvents();
MessageBox(NULL, "Inspector event hooked !!", "!", MB_OK | MB_APPLMODAL);
}

There is CTimeZonesButtonCatcher class:
header:
//////////////----------------------------------------------
-------------------------------///////////////////////////// /
// TimeZonesButtonCatcher.h

#pragma once

class CTimeZonesButtonCatcher :
public IDispEventSimpleImpl4, CTimeZonesButtonCatcher,
&__uuidof(Office::_CommandBarButtonEvents)
{
public:
CTimeZonesButtonCatcher()
{
}

// event sinks map
BEGIN_SINK_MAP(CTimeZonesButtonCatcher)
SINK_ENTRY_INFO(4, __uuidof(Office::_CommandBarButtonEvents), 0x00000001,
OnClick, &CancelableDispEventHandler)
END_SINK_MAP()

public:
// Handles item events
HRESULT(SubscribeToItemEvents)();
HRESULT(UnSubscribeToItemEvents)();
bool FindTimeZonesButton(OutlookCommandBarsPtr& bars);

protected:

virtual void __stdcall OnClick(LPDISPATCH ctrl, VARIANT_BOOL * cancel);

private:

template typename CONTAINTER_CLASS
OutlookCommandBarControlPtr FindControl(CONTAINTER_CLASS parent, CComBSTR
caption);

OutlookCommandBarControlPtr TimeZoneButton_m;
};

realization:
//////////////----------------------------------------------
-------------------------------///////////////////////////// /
// TimeZonesButtonCatcher.cpp : implementation of CTimeZonesButtonCatcher

#include "stdafx.h"
#include "TimeZonesButtonCatcher.h"


HRESULT CTimeZonesButtonCatcher::SubscribeToItemEvents()
{
HRESULT hr = IDispEventSimpleImpl4, CTimeZonesButtonCatcher,
&__uuidof(Office::_CommandBarButtonEvents):ispE ventAdvise(TimeZoneButton_m, &__uuidof(Office::_CommandBarButtonEvents));
return hr;
}

HRESULT CTimeZonesButtonCatcher::UnSubscribeToItemEvents()
{
HRESULT hr = IDispEventSimpleImpl4, CTimeZonesButtonCatcher,
&__uuidof(Office::_CommandBarButtonEvents):ispE ventUnadvise(TimeZoneButton_m);
return hr;
}

bool CTimeZonesButtonCatcher::FindTimeZonesButton(Outlo okCommandB arsPtr&
bars)
{
if (!bars.p) return false;

// Look for menu bar
int count;
bars-get_Count(&count);

for (int i=1; i=count; i++)
{
VARIANT index;
index.lVal = i;
index.vt = VT_I4;
OutlookCommandBarPtr bar;
HRESULT hr = bars-get_Item(index, &bar);
CComBSTR barName;
bar-get_Name(&barName);
if(barName == _T("Standard") )
{
OutlookCommandBarControlPtr item = FindControl(bar, _T("I&nvite Attendees") );
if(item.p == NULL)
{
return S_FALSE;
}
TimeZoneButton_m = item;
break;
}
}

if (!TimeZoneButton_m) return S_FALSE;

}


template typename CONTAINTER_CLASS
OutlookCommandBarControlPtr
CTimeZonesButtonCatcher::FindControl(CONTAINTER_CL ASS parent, CComBSTR
caption)
{
OutlookCommandBarControlsPtr controls;
HRESULT hr = parent-get_Controls(&controls);
int controlsCount;
hr = controls-get_Count(&controlsCount);
for(int i=1; i=controlsCount; i++)
{
VARIANT controlsIndex;
controlsIndex.lVal = i;
controlsIndex.vt = VT_I4;
OutlookCommandBarControlPtr control;
hr = controls-get_Item(controlsIndex, &control);
CComBSTR controlName;
hr = control-get_Caption(&controlName);
if(controlName == caption)
return control;
}
return OutlookCommandBarControlPtr();
}

void __stdcall CTimeZonesButtonCatcher::OnClick(LPDISPATCH ctrl,
VARIANT_BOOL * cancel)
{
OutlookCommandBarButtonPtr button(ctrl);
MessageBox(NULL, "Hi2222", "Catched !", MB_OK | MB_APPLMODAL);
}
//////////////----------------------------------------------
-------------------------------///////////////////////////// /

line in stdafx.cpp:
_ATL_FUNC_INFO CancelableDispEventHandler = {CC_STDCALL, VT_EMPTY, 2,
{VT_DISPATCH, VT_BYREF | VT_BOOL}};

and lines in stdafx.h:
typedef CComQIPtrOffice::_CommandBars OutlookCommandBarsPtr;
typedef CComQIPtrOffice::CommandBar OutlookCommandBarPtr;
typedef CComQIPtrOffice::CommandBarControls OutlookCommandBarControlsPtr;
typedef CComQIPtrOffice::CommandBarControl OutlookCommandBarControlPtr;
typedef CComQIPtrOffice::_CommandBarButton OutlookCommandBarButtonPtr;

extern _ATL_FUNC_INFO DispParamEventHandler;
//////////////----------------------------------------------
-------------------------------///////////////////////////// /


And I'm don't catch button click by such a way, although I catch button
click (using this code) if deal with buttons in main outlook menu, not in
rarely appeared "Appointment window".

How catch in "Appointment" and other windows, appears not just after Outlook
startup ?

Best regards, N.
Ads
  #2  
Old November 26th 08, 02:09 PM posted to microsoft.public.outlook.program_addins
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default Catching buttons pressing in Outlook appointment window.

Inspectors in Outlook 2007 use the Ribbon, not the CommandBar interface. You
must use Ribbon callbacks to do what you want. You use XML to set up a
custom Ribbon or to handle existing Ribbon controls and then the callbacks
are called as appropriate.

You should look at some of the sample addins for Outlook 2007 and Office
2007 available for download on the Office Developer Web site at MS. They're
going to be in VB.NET or C# for the most part, but they should give you the
idea.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"Sergeichik" wrote in message
...
I have an Outlook 2007 installed on.
I have small Outlook Add-in example (in C++) somewhere from
http://www.codeproject.com ..

I try to catch buttons, located at 'Appointment window toolbar' (in
Outlook
Calendar press some date, and this window will be appear) press by the
following way:

Function OnInspectorEvent is called when new inspector being created:

CAdding private member
CTimeZonesButtonCatcher m_watch

void __stdcall CAddin::OnInspectorEvent (LPDISPATCH ctrl)
{
OutlookInspectorPtr insp(ctrl);
OutlookCommandBarsPtr bars;
HRESULT hr = insp-get_CommandBars(&bars);
m_watch.FindTimeZonesButton(bars);
m_watch.SubscribeToItemEvents();
MessageBox(NULL, "Inspector event hooked !!", "!", MB_OK | MB_APPLMODAL);
}

There is CTimeZonesButtonCatcher class:
header:
//////////////----------------------------------------------
-------------------------------///////////////////////////// /
// TimeZonesButtonCatcher.h

#pragma once

class CTimeZonesButtonCatcher :
public IDispEventSimpleImpl4, CTimeZonesButtonCatcher,
&__uuidof(Office::_CommandBarButtonEvents)
{
public:
CTimeZonesButtonCatcher()
{
}

// event sinks map
BEGIN_SINK_MAP(CTimeZonesButtonCatcher)
SINK_ENTRY_INFO(4, __uuidof(Office::_CommandBarButtonEvents), 0x00000001,
OnClick, &CancelableDispEventHandler)
END_SINK_MAP()

public:
// Handles item events
HRESULT(SubscribeToItemEvents)();
HRESULT(UnSubscribeToItemEvents)();
bool FindTimeZonesButton(OutlookCommandBarsPtr& bars);

protected:

virtual void __stdcall OnClick(LPDISPATCH ctrl, VARIANT_BOOL * cancel);

private:

template typename CONTAINTER_CLASS
OutlookCommandBarControlPtr FindControl(CONTAINTER_CLASS parent, CComBSTR
caption);

OutlookCommandBarControlPtr TimeZoneButton_m;
};

realization:
//////////////----------------------------------------------
-------------------------------///////////////////////////// /
// TimeZonesButtonCatcher.cpp : implementation of CTimeZonesButtonCatcher

#include "stdafx.h"
#include "TimeZonesButtonCatcher.h"


HRESULT CTimeZonesButtonCatcher::SubscribeToItemEvents()
{
HRESULT hr = IDispEventSimpleImpl4, CTimeZonesButtonCatcher,
&__uuidof(Office::_CommandBarButtonEvents):ispE ventAdvise(TimeZoneButton_m,
&__uuidof(Office::_CommandBarButtonEvents));
return hr;
}

HRESULT CTimeZonesButtonCatcher::UnSubscribeToItemEvents()
{
HRESULT hr = IDispEventSimpleImpl4, CTimeZonesButtonCatcher,
&__uuidof(Office::_CommandBarButtonEvents):ispE ventUnadvise(TimeZoneButton_m);
return hr;
}

bool CTimeZonesButtonCatcher::FindTimeZonesButton(Outlo okCommandB arsPtr&
bars)
{
if (!bars.p) return false;

// Look for menu bar
int count;
bars-get_Count(&count);

for (int i=1; i=count; i++)
{
VARIANT index;
index.lVal = i;
index.vt = VT_I4;
OutlookCommandBarPtr bar;
HRESULT hr = bars-get_Item(index, &bar);
CComBSTR barName;
bar-get_Name(&barName);
if(barName == _T("Standard") )
{
OutlookCommandBarControlPtr item = FindControl(bar, _T("I&nvite
Attendees") );
if(item.p == NULL)
{
return S_FALSE;
}
TimeZoneButton_m = item;
break;
}
}

if (!TimeZoneButton_m) return S_FALSE;

}


template typename CONTAINTER_CLASS
OutlookCommandBarControlPtr
CTimeZonesButtonCatcher::FindControl(CONTAINTER_CL ASS parent, CComBSTR
caption)
{
OutlookCommandBarControlsPtr controls;
HRESULT hr = parent-get_Controls(&controls);
int controlsCount;
hr = controls-get_Count(&controlsCount);
for(int i=1; i=controlsCount; i++)
{
VARIANT controlsIndex;
controlsIndex.lVal = i;
controlsIndex.vt = VT_I4;
OutlookCommandBarControlPtr control;
hr = controls-get_Item(controlsIndex, &control);
CComBSTR controlName;
hr = control-get_Caption(&controlName);
if(controlName == caption)
return control;
}
return OutlookCommandBarControlPtr();
}

void __stdcall CTimeZonesButtonCatcher::OnClick(LPDISPATCH ctrl,
VARIANT_BOOL * cancel)
{
OutlookCommandBarButtonPtr button(ctrl);
MessageBox(NULL, "Hi2222", "Catched !", MB_OK | MB_APPLMODAL);
}
//////////////----------------------------------------------
-------------------------------///////////////////////////// /

line in stdafx.cpp:
_ATL_FUNC_INFO CancelableDispEventHandler = {CC_STDCALL, VT_EMPTY, 2,
{VT_DISPATCH, VT_BYREF | VT_BOOL}};

and lines in stdafx.h:
typedef CComQIPtrOffice::_CommandBars OutlookCommandBarsPtr;
typedef CComQIPtrOffice::CommandBar OutlookCommandBarPtr;
typedef CComQIPtrOffice::CommandBarControls
OutlookCommandBarControlsPtr;
typedef CComQIPtrOffice::CommandBarControl OutlookCommandBarControlPtr;
typedef CComQIPtrOffice::_CommandBarButton OutlookCommandBarButtonPtr;

extern _ATL_FUNC_INFO DispParamEventHandler;
//////////////----------------------------------------------
-------------------------------///////////////////////////// /


And I'm don't catch button click by such a way, although I catch button
click (using this code) if deal with buttons in main outlook menu, not in
rarely appeared "Appointment window".

How catch in "Appointment" and other windows, appears not just after
Outlook
startup ?

Best regards, N.


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Triggering commands or pressing buttons as custom actions? Michael Moser Outlook - General Queries 1 August 15th 08 02:29 PM
Outlook not catching most of junk mail coopfab Outlook - Installation 0 February 13th 07 05:44 PM
Cannot open appointment window in Outlook Calendar SRM JR Outlook - Using Forms 0 November 22nd 06 03:49 PM
adding coomand bar buttons to inspector window Ram Add-ins for Outlook 4 May 26th 06 06:16 AM
outlook appointment window default Peter Harrison Outlook - Calandaring 3 March 19th 06 08:31 PM


All times are GMT +1. The time now is 09:32 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.