M
Mark Wilson
I've developed a Word COM Addin in C++ and I'm attempting to get the text of
a WordMail message body using the "Text" property. Most of the time this
works but occasionally it fails with a result code of 0x80020009.
The version of Outlook being used is Outlook XP (10.6760.6714) and prior to
accessing the Text property the SetFocus method was called to make sure that
the focus was in the message body.
It has been observed that every time the process fails, the value of
FocusInMailHeader is TRUE and every time the process succeeds the value of
FocusInMailHeader is FALSE.
Calling SetFocus when FocusInMailHeader is TRUE does not set the focus to
the message body even though the SetFocus method returns S_OK for a return
value.
How do you force the focus to be in the body of an e-mail message when Word
is selected as the e-mail editor?
Sample code:
-----------------------------------------------------------------------
hr = GetProperty(vtRange.pdispVal, L"Text", &vtText);
if (FAILED(hr))
{
OutputDebugString("Error: Can't get Text property");
hr = GetProperty(pDoc, L"Application", &vtApplication);
if (!FAILED(hr))
{
hr = GetProperty(vtApplication.pdispVal, L"FocusInMailHeader", &vtFocus);
if (!FAILED(hr))
{
if (vtFocus.boolVal)
{
OutputDebugString("Error: FocusInMailHeader = TRUE");
hr = GetProperty(pDoc,L"ActiveWindow",&vtWindow);
if (!FAILED(hr))
{
hResult = CallMethod(vtWindow.pdispVal, L"SetFocus", NULL, 0, 0);
if (!FAILED(hResult))
{
hr = GetProperty(vtApplication.pdispVal, L"FocusInMailHeader",
&vtFocus);
if (!FAILED(hr))
{
if (vtFocus.boolVal)
OutputDebugString("Error: FocusInMailHeader = TRUE (after
SetFocus)");
}
}
}
}
}
}
}
a WordMail message body using the "Text" property. Most of the time this
works but occasionally it fails with a result code of 0x80020009.
The version of Outlook being used is Outlook XP (10.6760.6714) and prior to
accessing the Text property the SetFocus method was called to make sure that
the focus was in the message body.
It has been observed that every time the process fails, the value of
FocusInMailHeader is TRUE and every time the process succeeds the value of
FocusInMailHeader is FALSE.
Calling SetFocus when FocusInMailHeader is TRUE does not set the focus to
the message body even though the SetFocus method returns S_OK for a return
value.
How do you force the focus to be in the body of an e-mail message when Word
is selected as the e-mail editor?
Sample code:
-----------------------------------------------------------------------
hr = GetProperty(vtRange.pdispVal, L"Text", &vtText);
if (FAILED(hr))
{
OutputDebugString("Error: Can't get Text property");
hr = GetProperty(pDoc, L"Application", &vtApplication);
if (!FAILED(hr))
{
hr = GetProperty(vtApplication.pdispVal, L"FocusInMailHeader", &vtFocus);
if (!FAILED(hr))
{
if (vtFocus.boolVal)
{
OutputDebugString("Error: FocusInMailHeader = TRUE");
hr = GetProperty(pDoc,L"ActiveWindow",&vtWindow);
if (!FAILED(hr))
{
hResult = CallMethod(vtWindow.pdispVal, L"SetFocus", NULL, 0, 0);
if (!FAILED(hResult))
{
hr = GetProperty(vtApplication.pdispVal, L"FocusInMailHeader",
&vtFocus);
if (!FAILED(hr))
{
if (vtFocus.boolVal)
OutputDebugString("Error: FocusInMailHeader = TRUE (after
SetFocus)");
}
}
}
}
}
}
}