Board index » delphi » Outlook COM Add-in email inspector commandbar button event sinking problem

Outlook COM Add-in email inspector commandbar button event sinking problem


2004-08-23 10:25:48 PM
delphi278
Would someone have an idea why handling from OnStartupComplete,
this code to add an event sink for a new button created in a new commandbar
works as expected:
FButton: CommandBarButton;
FCommandBar: CommandBar;
FCookie: Longint;
FEventSink: TEventSink;
FEventSink := TEventSink.Create(CommandBarButtonClick);
InterfaceConnect(FButton, DIID__CommandBarButtonEvents, FEventSink,
FCookie);
FCommandBar.Visible := True;
but for a commandbar button created in the email Inspector, this is not
working,
ie. no events are handled by the eventsink?
This shows how the commandbar button was created & event sink attached:
oItem := FApplication.CreateItem(olMailItem);
oCBS := oItem.GetInspector.CommandBars;
CmdBarsInsp := CommandBars(oCBS);
for i := 1 to CmdBarsInsp.Count do
begin
if CmdBarsInsp.Item[i].Name = 'BrunosBar' then
FCommandBarInsp := CommandBar(CmdBarsInsp.Item[i]);
end;
if FCommandBarInsp = nil then
FCommandBarInsp := CmdBarsInsp.Add('BrunosBar', EmptyParam, EmptyParam,
EmptyParam);
if FCommandBarInsp.Controls_.Count>0 then
Control := FCommandBarInsp.Controls_.Item[1]
else
Control := FCommandBarInsp.Controls_.Add(msoControlButton, EmptyParam,
EmptyParam, EmptyParam, EmptyParam);
// access control as command bar button
FButtonInsp := CommandBarButton(Control);
FButtonInsp.Caption := 'Bruno''s Button';
FButtonInsp.Style := msoButtonIconAndCaption;
rh := LoadBitmap(sysinit.HInstance , MakeIntResource(101)) ;
if (rh <>0) then
begin
Image1 := TImage.Create(nil);
try
Image1.Picture.Bitmap.Handle := rh ;
clipboard.Assign( Image1.Picture.Graphic) ;
finally
Image1.Free ;
end ;
end ;
FButtonInsp.PasteFace ;
FButtonInsp.Visible := True;
FButtonInsp.TooltipText := 'Tip for my button' ;
// hook up Click event
FEventSinkInsp := TEventSink.Create(InspectorButtonClick);
InterfaceConnect2(FButtonInsp, DIID__CommandBarButtonEvents,
FEventSinkInsp, FCookieInsp);
FCommandBarInsp.Visible := True;
oItem := unassigned;
Same was tried by inserting the button from the NewInspector event (using an
event sink for NewInspector)
and also in this case, the button / commandbar is succesfully added to the
email inspector, but no way to get the button click event. ?
Any tips / hints would be very welcome
Thanks,
Bruno
 
 

Re:Outlook COM Add-in email inspector commandbar button event sinking problem

Hi Bruno,
This problem seems to be solved in our Add-in Express.
Look at www.add-in-express.com
Best regards,
Eugene E. Starostin
---
Afalina Co., Ltd.
"Bruno Fierens [tmssoftware.com]" <XXXX@XXXXX.COM>writes
Quote
Would someone have an idea why handling from OnStartupComplete,
this code to add an event sink for a new button created in a new
commandbar
works as expected:

FButton: CommandBarButton;
FCommandBar: CommandBar;
FCookie: Longint;
FEventSink: TEventSink;

FEventSink := TEventSink.Create(CommandBarButtonClick);
InterfaceConnect(FButton, DIID__CommandBarButtonEvents, FEventSink,
FCookie);
FCommandBar.Visible := True;



but for a commandbar button created in the email Inspector, this is not
working,
ie. no events are handled by the eventsink?



This shows how the commandbar button was created & event sink attached:

oItem := FApplication.CreateItem(olMailItem);
oCBS := oItem.GetInspector.CommandBars;
CmdBarsInsp := CommandBars(oCBS);

for i := 1 to CmdBarsInsp.Count do
begin
if CmdBarsInsp.Item[i].Name = 'BrunosBar' then
FCommandBarInsp := CommandBar(CmdBarsInsp.Item[i]);
end;

if FCommandBarInsp = nil then
FCommandBarInsp := CmdBarsInsp.Add('BrunosBar', EmptyParam,
EmptyParam,
EmptyParam);

if FCommandBarInsp.Controls_.Count>0 then
Control := FCommandBarInsp.Controls_.Item[1]
else
Control := FCommandBarInsp.Controls_.Add(msoControlButton, EmptyParam,
EmptyParam, EmptyParam, EmptyParam);

// access control as command bar button
FButtonInsp := CommandBarButton(Control);
FButtonInsp.Caption := 'Bruno''s Button';
FButtonInsp.Style := msoButtonIconAndCaption;
rh := LoadBitmap(sysinit.HInstance , MakeIntResource(101)) ;
if (rh <>0) then
begin
Image1 := TImage.Create(nil);
try
Image1.Picture.Bitmap.Handle := rh ;
clipboard.Assign( Image1.Picture.Graphic) ;
finally
Image1.Free ;
end ;
end ;
FButtonInsp.PasteFace ;
FButtonInsp.Visible := True;
FButtonInsp.TooltipText := 'Tip for my button' ;

// hook up Click event
FEventSinkInsp := TEventSink.Create(InspectorButtonClick);
InterfaceConnect2(FButtonInsp, DIID__CommandBarButtonEvents,
FEventSinkInsp, FCookieInsp);
FCommandBarInsp.Visible := True;
oItem := unassigned;


Same was tried by inserting the button from the NewInspector event (using
an
event sink for NewInspector)
and also in this case, the button / commandbar is succesfully added to the
email inspector, but no way to get the button click event. ?

Any tips / hints would be very welcome
Thanks,
Bruno
 

Re:Outlook COM Add-in email inspector commandbar button event sinking problem

Try Setting the FButton.ID to some unique Identifier. It really doesn't
matter what, but set it to some string like the time..
Paul
"Bruno Fierens [tmssoftware.com]" <XXXX@XXXXX.COM>writes
Quote
Would someone have an idea why handling from OnStartupComplete,
this code to add an event sink for a new button created in a new
commandbar
works as expected:

FButton: CommandBarButton;
FCommandBar: CommandBar;
FCookie: Longint;
FEventSink: TEventSink;

FEventSink := TEventSink.Create(CommandBarButtonClick);
InterfaceConnect(FButton, DIID__CommandBarButtonEvents, FEventSink,
FCookie);
FCommandBar.Visible := True;



but for a commandbar button created in the email Inspector, this is not
working,
ie. no events are handled by the eventsink?



This shows how the commandbar button was created & event sink attached:

oItem := FApplication.CreateItem(olMailItem);
oCBS := oItem.GetInspector.CommandBars;
CmdBarsInsp := CommandBars(oCBS);

for i := 1 to CmdBarsInsp.Count do
begin
if CmdBarsInsp.Item[i].Name = 'BrunosBar' then
FCommandBarInsp := CommandBar(CmdBarsInsp.Item[i]);
end;

if FCommandBarInsp = nil then
FCommandBarInsp := CmdBarsInsp.Add('BrunosBar', EmptyParam,
EmptyParam,
EmptyParam);

if FCommandBarInsp.Controls_.Count>0 then
Control := FCommandBarInsp.Controls_.Item[1]
else
Control := FCommandBarInsp.Controls_.Add(msoControlButton, EmptyParam,
EmptyParam, EmptyParam, EmptyParam);

// access control as command bar button
FButtonInsp := CommandBarButton(Control);
FButtonInsp.Caption := 'Bruno''s Button';
FButtonInsp.Style := msoButtonIconAndCaption;
rh := LoadBitmap(sysinit.HInstance , MakeIntResource(101)) ;
if (rh <>0) then
begin
Image1 := TImage.Create(nil);
try
Image1.Picture.Bitmap.Handle := rh ;
clipboard.Assign( Image1.Picture.Graphic) ;
finally
Image1.Free ;
end ;
end ;
FButtonInsp.PasteFace ;
FButtonInsp.Visible := True;
FButtonInsp.TooltipText := 'Tip for my button' ;

// hook up Click event
FEventSinkInsp := TEventSink.Create(InspectorButtonClick);
InterfaceConnect2(FButtonInsp, DIID__CommandBarButtonEvents,
FEventSinkInsp, FCookieInsp);
FCommandBarInsp.Visible := True;
oItem := unassigned;


Same was tried by inserting the button from the NewInspector event (using
an
event sink for NewInspector)
and also in this case, the button / commandbar is succesfully added to the
email inspector, but no way to get the button click event. ?

Any tips / hints would be very welcome
Thanks,
Bruno









 

Re:Outlook COM Add-in email inspector commandbar button event sinking problem

You probably mean FButton.Tag.
Dmitry Streblechenko (MVP)
www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
"Paul Qualls" <XXXX@XXXXX.COM>writes
Quote
Try Setting the FButton.ID to some unique Identifier. It really doesn't
matter what, but set it to some string like the time..

Paul

"Bruno Fierens [tmssoftware.com]" <XXXX@XXXXX.COM>wrote in
message
news:4129fe52$XXXX@XXXXX.COM...
>Would someone have an idea why handling from OnStartupComplete,
>this code to add an event sink for a new button created in a new
commandbar
>works as expected:
>
>FButton: CommandBarButton;
>FCommandBar: CommandBar;
>FCookie: Longint;
>FEventSink: TEventSink;
>
>FEventSink := TEventSink.Create(CommandBarButtonClick);
>InterfaceConnect(FButton, DIID__CommandBarButtonEvents, FEventSink,
>FCookie);
>FCommandBar.Visible := True;
>
>
>
>but for a commandbar button created in the email Inspector, this is not
>working,
>ie. no events are handled by the eventsink?
>
>
>
>This shows how the commandbar button was created & event sink attached:
>
>oItem := FApplication.CreateItem(olMailItem);
>oCBS := oItem.GetInspector.CommandBars;
>CmdBarsInsp := CommandBars(oCBS);
>
>for i := 1 to CmdBarsInsp.Count do
>begin
>if CmdBarsInsp.Item[i].Name = 'BrunosBar' then
>FCommandBarInsp := CommandBar(CmdBarsInsp.Item[i]);
>end;
>
>if FCommandBarInsp = nil then
>FCommandBarInsp := CmdBarsInsp.Add('BrunosBar', EmptyParam,
EmptyParam,
>EmptyParam);
>
>if FCommandBarInsp.Controls_.Count>0 then
>Control := FCommandBarInsp.Controls_.Item[1]
>else
>Control := FCommandBarInsp.Controls_.Add(msoControlButton,
EmptyParam,
>EmptyParam, EmptyParam, EmptyParam);
>
>// access control as command bar button
>FButtonInsp := CommandBarButton(Control);
>FButtonInsp.Caption := 'Bruno''s Button';
>FButtonInsp.Style := msoButtonIconAndCaption;
>rh := LoadBitmap(sysinit.HInstance , MakeIntResource(101)) ;
>if (rh <>0) then
>begin
>Image1 := TImage.Create(nil);
>try
>Image1.Picture.Bitmap.Handle := rh ;
>clipboard.Assign( Image1.Picture.Graphic) ;
>finally
>Image1.Free ;
>end ;
>end ;
>FButtonInsp.PasteFace ;
>FButtonInsp.Visible := True;
>FButtonInsp.TooltipText := 'Tip for my button' ;
>
>// hook up Click event
>FEventSinkInsp := TEventSink.Create(InspectorButtonClick);
>InterfaceConnect2(FButtonInsp, DIID__CommandBarButtonEvents,
>FEventSinkInsp, FCookieInsp);
>FCommandBarInsp.Visible := True;
>oItem := unassigned;
>
>
>Same was tried by inserting the button from the NewInspector event
(using
an
>event sink for NewInspector)
>and also in this case, the button / commandbar is succesfully added to
the
>email inspector, but no way to get the button click event. ?
>
>Any tips / hints would be very welcome
>Thanks,
>Bruno
>
>
>
>
>
>
>
>
>


 

Re:Outlook COM Add-in email inspector commandbar button event sinking problem

yep
"Dmitry Streblechenko" <XXXX@XXXXX.COM>writes
Quote
You probably mean FButton.Tag.

Dmitry Streblechenko (MVP)
www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool