opening new custom contact form

A

Andrea Cacciarru

I have created my custom contact form. Now I want display my new custom form
when a user open an existing contact. I've write this code that caugth new
inspector event:

void __stdcall OutlookAddin::OnNewInspector(IDispatch* pdispInspector)
{
CComQIPtr <Outlook::_Inspector> spInspector;
CComPtr <Outlook::_ContactItem> pContact;
CComPtr <Outlook::_ContactItem> NewContactItem;
Outlook::OlInspectorClose oic = olDiscard;
IDispatch* pDispItem;
spInspector = pdispInspector;
spInspector->get_CurrentItem(&pDispItem);
HRESULT hr = pDispItem->QueryInterface(&pContact);
if (FAILED(hr))
return;

//**** modify Message Class ****

BSTR defaultMsgClass,newMsgClass;
_bstr_t defaultMsgClass_T (_T("IPM.Contact"));
defaultMsgClass = defaultMsgClass_T.copy();
_bstr_t newMsgClass_T (_T("IPM.Contact.MyContact"));
newMsgClass = newMsgClass_T.copy();

BSTR curMsgClass;
hr = pContact->get_MessageClass(&curMsgClass);
if (FAILED(hr)) {
return;//error
}
string curMsgClassStr = ToStdString(curMsgClass);
string defaultMsgClassStr= ToStdString(defaultMsgClass);
if (curMsgClassStr.compare(defaultMsgClassStr) ==0) { //only if the
current item have default form
pContact->put_MessageClass(newMsgClass); //convert "IPM.Contact" to
"IPM.Contact.MyContact"
pContact->Save(); //perhaps don't care
pContact->Copy((IDispatch**)&NewContactItem); //create a new contact
item with IPM.Contact.MyContact form
NewContactItem->Save();
pContact->Delete(); // delete item with default form
}

NewContactItem->Display(); //display MyContact form
}

I noticed that if I don't follow this way, i.e. modify Message Class of item
with default form, copy this item in a new item with MyContact form, Save
this new contact item and then delete old current item, but I only change
the Message Class of current item, Outlook doesn't displays correctly the
form (displays always the default form) unless I restart outlook.
Now, when I double click on a contact, outlook displays two forms: one
default form and one MyContact form. Why, if I deleted old default form with
pContact->Delete() ?

Bye, Thank's in advance
Andrea
 

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