Board index » delphi » Outlook 2003 Addin, EventSinkImp, Button OnClick

Outlook 2003 Addin, EventSinkImp, Button OnClick


2005-12-01 10:59:41 PM
delphi236
Dear Newsgroup,
I'm having a few troubles with correctly setting up my addin. A colleague
of mine started this project and as he's not longer in the company any
more, it is my turn to extend it.
He used EventSinkImp to connect to the IConnectionPoint interfaces and
derived a few more classes we need. For example he derived a
TAddinOutlookButton from TOutlookCommandBarButton to store the Buttons
Inspector of Explorer reference.
Our plugin should be installed in each the CommandBar, the Explorer- and
the Interface-Toolbar. My Colleague implemented the Menu we require for
each of the three different toolbars and it was the hell to extend/change
it because you had to do it three times each... I then started to
reorganize the menu and saved the complete layout within an array (each
item refers to it is parents ItemID so they have incremental IDs..
This all works very well and the menu is displayed properly, but I now have
the following problem:
Each time a menu gets created, the OnClick event of a single item will get
called as often as it was built: So if we go for one creation in the
explorer, one in the CommandBar and one in the Inspector and clicking on
one item, it "get's clicked" three times! I tried it with a MessageDlg and
let the menu for the CommandBar create it in every RefreshCommandBars event
with the result that i get the Message Dialog as often as the Command Bar
got created.
Perhaps I should say that my colleague used OleVariants and IDispatches in
a very bad way (he mixed it up as often as he could... *gna*) and maybe
there are some wronge references.
Any Idea why the Button get's clicked so often? And sorry for my english,
it got a bit rusty the last few months ;)
Best regards,
Nicolai Waniek
 
 

Re:Outlook 2003 Addin, EventSinkImp, Button OnClick

Set the CommandBarButton.Tag property to a *unique* string for each instance
of the button.
Dmitry Streblechenko (MVP)
www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
"Nicolai Waniek" <"Nicolai dot Waniek at sphere71 dot com">writes
Quote
Dear Newsgroup,
I'm having a few troubles with correctly setting up my addin. A colleague
of mine started this project and as he's not longer in the company any
more, it is my turn to extend it.

He used EventSinkImp to connect to the IConnectionPoint interfaces and
derived a few more classes we need. For example he derived a
TAddinOutlookButton from TOutlookCommandBarButton to store the Buttons
Inspector of Explorer reference.

Our plugin should be installed in each the CommandBar, the Explorer- and
the Interface-Toolbar. My Colleague implemented the Menu we require for
each of the three different toolbars and it was the hell to extend/change
it because you had to do it three times each... I then started to
reorganize the menu and saved the complete layout within an array (each
item refers to it is parents ItemID so they have incremental IDs..

This all works very well and the menu is displayed properly, but I now
have
the following problem:
Each time a menu gets created, the OnClick event of a single item will get
called as often as it was built: So if we go for one creation in the
explorer, one in the CommandBar and one in the Inspector and clicking on
one item, it "get's clicked" three times! I tried it with a MessageDlg and
let the menu for the CommandBar create it in every RefreshCommandBars
event
with the result that i get the Message Dialog as often as the Command Bar
got created.

Perhaps I should say that my colleague used OleVariants and IDispatches in
a very bad way (he mixed it up as often as he could... *gna*) and maybe
there are some wronge references.

Any Idea why the Button get's clicked so often? And sorry for my english,
it got a bit rusty the last few months ;)

Best regards,
Nicolai Waniek
 

Re:Outlook 2003 Addin, EventSinkImp, Button OnClick

Hi Dmitry and thank you for your answer as it seems to work. Meanwhile I
rebuild the complete menu-storage structure to make it even more easy to
add new items. As I did that, i kicked out my colleagues IDispatches and
OleVariants but have now the problem on adding pictures to the buttons. the
source code that should add the buttons is show below:
[code]
if CmdBarControl.QueryInterface(IID__CommandBarButton, cmdBarButton) = S_OK
then begin
{$IFDEF DEBUG}OutputDebugString('TAddin.AddCmdBarControl::Button->Try to
add icons');{$ENDIF}
if MenuItem.IconResStr <>'' then begin
{$IFDEF DEBUG}OutputDebugString('TAddin.AddCmdBarControl::Adding
Icon');{$ENDIF}
Icon := TPicture.Create;
try
Icon.Bitmap.LoadFromResourceName(hInstance, MenuItem.IconResStr);
GetOlePicture(Icon, IconDisp);
CmdBarButton.Picture := IconDisp;
finally
FreeAndNil(Icon);
end;
end;
if MenuItem.IconMaskResStr <>'' then begin
{$IFDEF DEBUG}OutputDebugString('TAddin.AddCmdBarControl::Adding Icon
Mask');{$ENDIF}
Icon := TPicture.Create;
try
Icon.Bitmap.LoadFromResourceName(hInstance, MenuItem.IconMaskResStr);
GetOlePicture(Icon, IconDisp);
CmdBarButton.Mask := IconDisp;
finally
FreeAndNil(Icon);
end;
end;
end;
[/code]
It doesn't matter if the icons are release through FreeAndNil or not,
there's no difference regarding the result. Icon is a TPicture an MenuItem
is my instance of class holding the menu item's setup. the
"LoadFromResourceName" procedure must work as the IconMaskResStr and the
IconResStr are defined by the same constants as it was before i changed it
to this way.
Could you help me again? Thanks a lot in advance!
Best regards,
Nicolai Waniek
Am Thu, 1 Dec 2005 10:45:33 -0700 schrieb Dmitry Streblechenko:
Quote
Set the CommandBarButton.Tag property to a *unique* string for each instance
of the button.

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

 

Re:Outlook 2003 Addin, EventSinkImp, Button OnClick

Are you trying to set an icon on a toolbar button that lives in a Word
editor in Outlook (Tools|Options|Mail Format)?
If yes, Word editor runs in the word.exe process space, not outlook.exe; and
IPicture cannot be marshalled across the process boundaries. In this case
you need to resort to copying the bitmap to the clipboard, then pasting it
using CommandBarButton.PasteFace.
Dmitry Streblechenko (MVP)
www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
"Nicolai Waniek" <"Nicolai dot Waniek at sphere71 dot com">writes
Quote
Hi Dmitry and thank you for your answer as it seems to work. Meanwhile I
rebuild the complete menu-storage structure to make it even more easy to
add new items. As I did that, i kicked out my colleagues IDispatches and
OleVariants but have now the problem on adding pictures to the buttons.
the
source code that should add the buttons is show below:

[code]
if CmdBarControl.QueryInterface(IID__CommandBarButton, cmdBarButton) =
S_OK
then begin
{$IFDEF DEBUG}OutputDebugString('TAddin.AddCmdBarControl::Button->Try to
add icons');{$ENDIF}
if MenuItem.IconResStr <>'' then begin
{$IFDEF DEBUG}OutputDebugString('TAddin.AddCmdBarControl::Adding
Icon');{$ENDIF}
Icon := TPicture.Create;
try
Icon.Bitmap.LoadFromResourceName(hInstance, MenuItem.IconResStr);
GetOlePicture(Icon, IconDisp);
CmdBarButton.Picture := IconDisp;
finally
FreeAndNil(Icon);
end;
end;
if MenuItem.IconMaskResStr <>'' then begin
{$IFDEF DEBUG}OutputDebugString('TAddin.AddCmdBarControl::Adding Icon
Mask');{$ENDIF}
Icon := TPicture.Create;
try
Icon.Bitmap.LoadFromResourceName(hInstance, MenuItem.IconMaskResStr);
GetOlePicture(Icon, IconDisp);
CmdBarButton.Mask := IconDisp;
finally
FreeAndNil(Icon);
end;
end;
end;
[/code]

It doesn't matter if the icons are release through FreeAndNil or not,
there's no difference regarding the result. Icon is a TPicture an MenuItem
is my instance of class holding the menu item's setup. the
"LoadFromResourceName" procedure must work as the IconMaskResStr and the
IconResStr are defined by the same constants as it was before i changed it
to this way.

Could you help me again? Thanks a lot in advance!

Best regards,
Nicolai Waniek



Am Thu, 1 Dec 2005 10:45:33 -0700 schrieb Dmitry Streblechenko:

>Set the CommandBarButton.Tag property to a *unique* string for each
>instance
>of the button.
>
>Dmitry Streblechenko (MVP)
>www.dimastr.com/
>OutlookSpy - Outlook, CDO
>and MAPI Developer Tool
>
 

Re:Outlook 2003 Addin, EventSinkImp, Button OnClick

Hi, I checked my mail editor and it was word, but after changing it, the
behaviour didn't change. After a while of searching, I noticed that I
forgot to set the CmdBarButton.Style to msoButtonIconAndCaption...
Thank you for your help!
Nicolai Waniek
Am Fri, 2 Dec 2005 10:27:28 -0700 schrieb Dmitry Streblechenko:
Quote
Are you trying to set an icon on a toolbar button that lives in a Word
editor in Outlook (Tools|Options|Mail Format)?
If yes, Word editor runs in the word.exe process space, not outlook.exe; and
IPicture cannot be marshalled across the process boundaries. In this case
you need to resort to copying the bitmap to the clipboard, then pasting it
using CommandBarButton.PasteFace.