problem getting toolbar button coordinates

S

Sorin Vinatoru

Hi All,

I am writing a plugin that will modify some properties on a message and then
send it automatically when you click the button I added to the toolbar.

I am having a problem with automatically sending the message. I am trying to
do it by simulating a click on the "Send" button. The problem is that the
button coordinates for the send button are always the button coordinates of
the toolbar this button is in. So if the send button is the third button, you
will get the coordinates of the first one (which for some users is "Print"
button).

Here's my code:

CComQIPtr <Office::_CommandBars> cmdBars;
m_pInspector->get_CommandBars((Office::_CommandBars**)&cmdBars);
CComQIPtr <Office::CommandBarControl> spCmdBarCtrl;
CComVariant varId((long)5469, VT_I4);
spCmdBarCtrl = cmdBars->FindControl(CComVariant(msoControlSplitButtonPopup),
varId, vtMissing, vtMissing);
if (!spCmdBarCtrl) return;

int leftPoint = spCmdBarCtrl->GetLeft(); // this returns the bad location

I also checked out the coordinates using Outlook Spy application and they
look the same as those I find with my plugin.

This is happening in Outlook 2003, I haven't checked older versions yet.

Can you please help me find a workaround for this?

Thanks,
Sorin Vinatoru
 
K

Ken Slovak - [MVP - Outlook]

Why use button coordinates? Just use the ID for the Send button and call its
Execute method. You can never rely on where a button is, a user could move
things around.
 
S

Sorin Vinatoru

Hi Ken,

Thanks for your reply. I have tried doing that. However, if I call the
Execute method, Outlook will crash.

When I add this line,

spCmdBarCtrl->Execute();

it crashes, returning this error code: 80004005

I was not able to find any referrence for this error code, so I am not sure
why it crashes. Reading properties from the object works, calling methods
just crashes outlook with that error message.

Thanks,
Sorin
 
K

Ken Slovak - [MVP - Outlook]

The Send button is restricted unless you are using a trusted COM addin.
That's probably the source of the crash. You must follow the rules for a
trusted COM addin to avoid the problem.

According to Google that error is typically due to permissions problems on a
database. I'd expect that from calling Send in an untrusted fashion. (All I
did was type that error number into Google Search).
 

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