PC Review Forums Newsgroups Microsoft Outlook Microsoft Outlook Program Addins Programmatically invoking menu items?

Reply

Programmatically invoking menu items?

 
Thread Tools Rate Thread
Old 15-07-2003, 08:01 AM   #1
Martynas Kunigelis
Guest
 
Posts: n/a
Default Programmatically invoking menu items?


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:eliverNow(), but that only works
with Exchange.

Thanks in advance!

Best,
Martynas

  Reply With Quote
Old 15-07-2003, 09:22 PM   #2
Dmitry Streblechenko
Guest
 
Posts: n/a
Default Re: Programmatically invoking menu items?

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


"Martynas Kunigelis" <kunigelis@centras.lt> wrote in message
news:##WAVdqSDHA.2148@TK2MSFTNGP12.phx.gbl...
> 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:eliverNow(), but that only

works
> with Exchange.
>
> Thanks in advance!
>
> Best,
> Martynas
>



  Reply With Quote
Old 16-07-2003, 04:54 AM   #3
Martynas Kunigelis
Guest
 
Posts: n/a
Default Re: Programmatically invoking menu items?

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


"Dmitry Streblechenko" <dmitry@dimastr.com> wrote in message
news:u7gTtcxSDHA.2260@TK2MSFTNGP12.phx.gbl...
> 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
>
>


  Reply With Quote
Old 17-07-2003, 11:46 AM   #4
Martynas Kunigelis
Guest
 
Posts: n/a
Default Re: Programmatically invoking menu items?

Could you elaborate on adding "do events"? How do I do this?

"Dmitry Streblechenko" <dmitry@dimastr.com> wrote in message
news:u3BSt%237SDHA.212@TK2MSFTNGP10.phx.gbl...
> I don't know, sorry. I guess a menu items needs to be displayed for some
> time before it becomes useable. Try to add "do events" before you call
> CommandBarButton.Execute.
>
> Dmitry Streblechenko (MVP)
> http://www.dimastr.com/
> OutlookSpy - Outlook, CDO
> and MAPI Developer Tool
>
>


  Reply With Quote
Old 17-07-2003, 04:45 PM   #5
Dmitry Streblechenko
Guest
 
Posts: n/a
Default Re: Programmatically invoking menu items?

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


"Martynas Kunigelis" <kunigelis@centras.lt> wrote in message
news:uInEKkFTDHA.2264@TK2MSFTNGP11.phx.gbl...
> Could you elaborate on adding "do events"? How do I do this?
>
> "Dmitry Streblechenko" <dmitry@dimastr.com> wrote in message
> news:u3BSt%237SDHA.212@TK2MSFTNGP10.phx.gbl...
> > I don't know, sorry. I guess a menu items needs to be displayed for some
> > time before it becomes useable. Try to add "do events" before you call
> > CommandBarButton.Execute.
> >
> > Dmitry Streblechenko (MVP)
> > http://www.dimastr.com/
> > OutlookSpy - Outlook, CDO
> > and MAPI Developer Tool
> >
> >

>



  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

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