Programmatically invoking menu items?

M

Martynas Kunigelis

Hi all,

I'm developing an Outlook AddIn in C++ using ATL. I've found that I can
programmatically invoke the spelling checker on a new email message being
composed by using the Find method of _CommandBars to locate the Tools menu
control, and then the Spelling... menu item control, and calling Execute()
on them in the right order, i.e.

hr = spTools->Execute();
hr = spSpelling->Execute();

This works like a charm.

Now I need to be able to invoke Tools -> Send/Receive -> Send All of the top
level explorer in Outlook 2002. It seems identical to the above case, except
that the menu item is two levels deep.

However, for some reason this does not work. When I call Execute() on the
Send All menu item (having previously called Execute() on Tools and
Send/Receive in that order), it returns E_FAIL, and the Send All operation
is not performed.

Does anyone have an explanation for this? Is there another way? I know I
could "invoke" the Send/Receive button on the Standard toolbar, but what I
need is "send", not "send and receive".

And I am aware of Redemption::IMAPIUtils::DeliverNow(), but that only works
with Exchange.

Thanks in advance!

Best,
Martynas
 
D

Dmitry Streblechenko

1. You do not need to travel the menu hierarchy to find a button, use
CommandBars.FindControl instead, it will search all of the child toolbars.
2. Executing a menu item hidden at the time the code runs results in an
error, I don't think there are any workarounds.

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

Martynas Kunigelis

Hi Dmitry,

You misunderstood, I don't travel the hierarchy to find the menu items, I
use just the technique you've described. However, when I have retrieved all
the items in the "chain", I "travel" the hierarchy calling Execute() on
them, so that the bottom level menu actually gets displayed.

This is why I'm surprised that spSendAll->Execute() fails -- the "Send /
Receive" menu is certainly visible at the moment, and "Send All" is enabled.

Again, this technique works fine for invoking Inspector's
Tools ->Spelling... menu item, but fails for Explorer's Tools->Send /
Receive->Send All for some reason. The only difference I can see is that in
the latter case the menu item is two levels deep... Any ideas?

Thanks for your answer!

Best,
Martynas
 
D

Dmitry Streblechenko

I mean running the Windows message loop: in C++/Delphi
(GetMessage/TranslateMessage/DispatchMessage) in VB - "Do Events" (or
whatever it is called).

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top