How to get Selected Body message Text

  • Thread starter pasteface method crashing outlook
  • Start date
P

pasteface method crashing outlook

Hi,

I need to handle an event whenever we select something in mail body. Can
anyone say how to handle this event and how to get selected text.

I'm developing an outlook add-in in ATL COM(VC++)

Regards
Kiran. S
 
K

Ken Slovak - [MVP - Outlook]

There is no such event in the Outlook object model. If you are using
WordMail you can get Inspector.WordEditor as a Word.Document object and use
the Word Object model for that. If you are using HTML then you would have to
use the IHTMLDocument object model.




"pasteface method crashing outlook"
 
P

pasteface method crashing outlook

Thanks Ken,

I tried Word Object Model and tried to capture the WordEditor of an mail
item. But inspector->get_WordEditor() is giving null pointer.
Code:
CComQIPtr<Outlook::_Inspector> spInspector;

CComPtr<MSWord::_Document> spWordDoc;
CComPtr<MSWord::Selection> spWordSelection;
CComPtr<MSWord::_Application> spWordApp;

spMailItem->get_GetInspector(&spInspector);
CComPtr<Outlook::_Application> spApp;
spInspector->get_EditorType(&editType);
BSTR str;
VARIANT_BOOL vTemp;

spInspector->IsWordMail(&vTemp);

if(vTemp == VARIANT_TRUE)
{

spInspector->get_WordEditor((IDispatch**)&spWordDoc);

spWordDoc->get_Application(&spWordApp);
spWordApp->get_Selection(&spWordSelection);
spWordSelection->get_Text(&str);
}

Please let me know if any issue found.

Regards
Kiran. S
 
K

Ken Slovak - [MVP - Outlook]

Where are you calling that code?

I've seen, especially in Outlook 2007, that WordEditor is null up until the
first Inspector.Activate() event. For example it's null in
Inspectors.NewInspector() because you're only getting a weak object
reference at that point.

If there is no Inspector then obviously there can't be a WordEditor object
since there is no Inspector.




"pasteface method crashing outlook"
 
P

pasteface method crashing outlook

I'm call the code when we change mail item in main pane( BY handling
Command-Bar events). I'm able to get Inspector pointer but its WordEditor is
returning NULL. Using the below code to capture Inspector pointer.

Code:
CComPtr< Outlook::Selection>spSelection;
m_pExplorer->get_Selection(&spSelection);

BSTR strname;
if(spSelection)
{

CComPtr< IDispatch > spItem;
CComVariant vCount(1);
spSelection->Item(vCount,&spItem);
if(!spItem)
return;
ATLASSERT(spItem);
CComQIPtr< Outlook::_MailItem> spMailItem(spItem);
ATLASSERT(spMailItem);

fprintf(fileptr,"[WSforOutlookMailItemSearching]->spMailItem::Success\r\n");
fflush(fileptr);

CComQIPtr<Outlook::_Inspector> spInspector;
spMailItem->get_GetInspector(&spInspector)
}

- Kiran. S
 
K

Ken Slovak - [MVP - Outlook]

You would need to display the Inspector.




"pasteface method crashing outlook"
 
P

pasteface method crashing outlook

can you tell me which event is needed to handle , when we select the text in
outlook 2007.

-Kiran.S

Ken Slovak - said:
You would need to display the Inspector.




"pasteface method crashing outlook"
I'm call the code when we change mail item in main pane( BY handling
Command-Bar events). I'm able to get Inspector pointer but its WordEditor
is
returning NULL. Using the below code to capture Inspector pointer.

Code:
CComPtr< Outlook::Selection>spSelection;
m_pExplorer->get_Selection(&spSelection);

BSTR strname;
if(spSelection)
{

CComPtr< IDispatch > spItem;
CComVariant vCount(1);
spSelection->Item(vCount,&spItem);
if(!spItem)
return;
ATLASSERT(spItem);
CComQIPtr< Outlook::_MailItem> spMailItem(spItem);
ATLASSERT(spMailItem);

fprintf(fileptr,"[WSforOutlookMailItemSearching]->spMailItem::Success\r\n");
fflush(fileptr);

CComQIPtr<Outlook::_Inspector> spInspector;
spMailItem->get_GetInspector(&spInspector)
}

- Kiran. S
 
K

Ken Slovak - [MVP - Outlook]

There is no event for that in the Outlook object model.

You'd have to open the item so it was being handled by WordMail, get
Inspector.WordEditor as a Word.Document object, then get the Parent property
of that as Word.Application and use the
Word.Application.WindowSelectionChange() event.

If the text was selected in the reading pane I don't know of a way to get an
event for that at all.




"pasteface method crashing outlook"
 

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