G
Guest
Hi,
I would like to paste a RTF content in a MailItem, so to do that I wrote the
code attached at the end of the message.
Everything seems to work but if, before the paste, I show a modal dialog
window, or simply a MessageBox, sometimes the btn3 (paste button) seems to
be not enabled; note that the dialog is already closed before the paste.
I tried to activate the inspector (spInsp->Activate()) and to set the active
windows (using ::SetActiveWindow) but however sometime the paste doesn't
work.
Furthermore, as you can see in the code, I used a trick for understanding if
the focus is on the edit control where I can write the mail; is there a more
convenient method to do that?
Someone could help me?
Thanks Sektor
// Get MailItem's Inspector
CComPtr<Outlook::_Inspector> spInsp;
HRESULT hr = _mailItem->get_GetInspector(&spInsp);
if (FAILED(hr))
return hr;
// Set Mail Format as RTF mail
_mailItem->put_BodyFormat(Outlook:lFormatRichText);
CComPtr<Office::_CommandBars> bars;
CComPtr<Office::CommandBarControl> cbtn;
CComPtr<Office::_CommandBarButton> btn1; // Edit Message
CComPtr<Office::_CommandBarButton> btn2; // Select All
CComPtr<Office::_CommandBarButton> btn3; // Paste
CComPtr<Office::_CommandBarButton> btn4; // Find
hr = spInsp->get_CommandBars(&bars);
if (FAILED(hr))
return hr;
hr = bars->FindControl(CComVariant(Office::msoControlButton),
CComVariant(BTNID_EDITMSG), vtMissing, vtMissing, &cbtn);
cbtn.Attach(NULL);
hr = bars->FindControl(CComVariant(Office::msoControlButton),
CComVariant(BTNID_SELECTALL), vtMissing, vtMissing, &cbtn);
if (FAILED(hr) || !cbtn)
return E_FAIL;
btn2 = cbtn;
cbtn.Attach(NULL);
hr = bars->FindControl(CComVariant(Office::msoControlButton),
CComVariant(BTNID_PASTE), vtMissing, vtMissing, &cbtn);
if (FAILED(hr) || !cbtn)
return E_FAIL;
btn3 = cbtn;
cbtn.Attach(NULL);
hr = bars->FindControl(CComVariant(Office::msoControlButton),
CComVariant(BTNID_FIND), vtMissing, vtMissing, &cbtn);
if (FAILED(hr) || !cbtn)
return E_FAIL;
btn4 = cbtn;
cbtn.Attach(NULL);
// Check if the focus is on message control
// Trick: we can not check directly where the focus is ...so we check if
the
// Edit -> Find button is enabled :-(
if (btn4)
{
VARIANT_BOOL enb = VARIANT_FALSE;
btn4->get_Enabled(&enb);
if (enb == VARIANT_FALSE)
return E_FAIL;
}
// Click on "Edit Message"
// It is not an error: if we are creating an e-mail or if the e-mail
received is a RTF message
// it is already editable
if (btn1)
{
hr = btn1->Execute();
}
// Click on "Select All"
hr = btn2->Execute();
if (FAILED(hr))
{
return hr;
}
VARIANT_BOOL enb = VARIANT_FALSE;
btn3->get_Enabled(&enb);
if (enb != VARIANT_TRUE)
return E_FAIL;
hr = btn3->Execute();
if (FAILED(hr))
{
return hr;
}
I would like to paste a RTF content in a MailItem, so to do that I wrote the
code attached at the end of the message.
Everything seems to work but if, before the paste, I show a modal dialog
window, or simply a MessageBox, sometimes the btn3 (paste button) seems to
be not enabled; note that the dialog is already closed before the paste.
I tried to activate the inspector (spInsp->Activate()) and to set the active
windows (using ::SetActiveWindow) but however sometime the paste doesn't
work.
Furthermore, as you can see in the code, I used a trick for understanding if
the focus is on the edit control where I can write the mail; is there a more
convenient method to do that?
Someone could help me?
Thanks Sektor
// Get MailItem's Inspector
CComPtr<Outlook::_Inspector> spInsp;
HRESULT hr = _mailItem->get_GetInspector(&spInsp);
if (FAILED(hr))
return hr;
// Set Mail Format as RTF mail
_mailItem->put_BodyFormat(Outlook:lFormatRichText);
CComPtr<Office::_CommandBars> bars;
CComPtr<Office::CommandBarControl> cbtn;
CComPtr<Office::_CommandBarButton> btn1; // Edit Message
CComPtr<Office::_CommandBarButton> btn2; // Select All
CComPtr<Office::_CommandBarButton> btn3; // Paste
CComPtr<Office::_CommandBarButton> btn4; // Find
hr = spInsp->get_CommandBars(&bars);
if (FAILED(hr))
return hr;
hr = bars->FindControl(CComVariant(Office::msoControlButton),
CComVariant(BTNID_EDITMSG), vtMissing, vtMissing, &cbtn);
cbtn.Attach(NULL);
hr = bars->FindControl(CComVariant(Office::msoControlButton),
CComVariant(BTNID_SELECTALL), vtMissing, vtMissing, &cbtn);
if (FAILED(hr) || !cbtn)
return E_FAIL;
btn2 = cbtn;
cbtn.Attach(NULL);
hr = bars->FindControl(CComVariant(Office::msoControlButton),
CComVariant(BTNID_PASTE), vtMissing, vtMissing, &cbtn);
if (FAILED(hr) || !cbtn)
return E_FAIL;
btn3 = cbtn;
cbtn.Attach(NULL);
hr = bars->FindControl(CComVariant(Office::msoControlButton),
CComVariant(BTNID_FIND), vtMissing, vtMissing, &cbtn);
if (FAILED(hr) || !cbtn)
return E_FAIL;
btn4 = cbtn;
cbtn.Attach(NULL);
// Check if the focus is on message control
// Trick: we can not check directly where the focus is ...so we check if
the
// Edit -> Find button is enabled :-(
if (btn4)
{
VARIANT_BOOL enb = VARIANT_FALSE;
btn4->get_Enabled(&enb);
if (enb == VARIANT_FALSE)
return E_FAIL;
}
// Click on "Edit Message"
// It is not an error: if we are creating an e-mail or if the e-mail
received is a RTF message
// it is already editable
if (btn1)
{
hr = btn1->Execute();
}
// Click on "Select All"
hr = btn2->Execute();
if (FAILED(hr))
{
return hr;
}
VARIANT_BOOL enb = VARIANT_FALSE;
btn3->get_Enabled(&enb);
if (enb != VARIANT_TRUE)
return E_FAIL;
hr = btn3->Execute();
if (FAILED(hr))
{
return hr;
}