"Sue Mosher [MVP-Outlook]" <
[email protected]> ha scritto nel
messaggio
You need to change the MessageClass on the existing items to point to
your
new form's class
Ok I've converted old message classes to the new names, but nothing
happens!
To create the new form I have selected Tools->Modules->Structure from
outlook 2003 menu.
I'have modified a form tab named "My Tab" (previous was named (p.2)) and I
saved this form template in a file oft.
Then I have introduced this code on my add-in:
//... load oft file
bstrName_T =_T("MyForm.oft");
bstrName = bstrName_T.copy();
hr = m_spApp->CreateItemFromTemplate(bstrName,myFolder,(IDispatch**)
&CustomContactItem);
if(FAILED(hr)) {
AfxMessageBox("Failed to load outlook form template");
}
//this code add an item MyForm to contacts list*************
CustomContactItem->get_FormDescription(&CustomFormDescription);
bstrName_T = _T("MyForm");
bstrName = bstrName_T.copy();
CustomFormDescription->put_Name(bstrName);
Outlook::OlFormRegistry ofr = olFolderRegistry;
CustomFormDescription->PublishForm(ofr,myFolder);
Outlook::OlInspectorClose oic = olSave;
CustomContactItem->Close(oic);
//****************************************************
CComPtr <Outlook::_NameSpace> olNs;
CComQIPtr <Outlook::_Items> spItems;
CComQIPtr <Outlook::MAPIFolder> oContacts;
Outlook::OlDefaultFolders enumODF = olFolderContacts;
spApp->GetNamespace(bstrName,&olNs);
olNs->GetDefaultFolder(enumODF,&oContacts);
BSTR oldMsgClass,newMsgClass;
_bstr_t oldMsgClass_T (_T("IPM.Contact"));
oldMsgClass = oldMsgClass_T.copy();
_bstr_t newMsgClass_T (_T("IPM.Contact.MyForm"));
newMsgClass = newMsgClass_T.copy();
oContacts->get_Items(&spItems);
long ItemCount;
spItems->get_Count(&ItemCount); //get number of contact items
for (int n = 1; n<=ItemCount;n++) {
CComVariant nItem (n);
IDispatch* itm;
hr = spItems->Item(nItem,&itm);
if (FAILED(hr)) {
AfxMessageBox("Error converting items (get item)");
break;
}
CComQIPtr <Outlook::_ContactItem> spItem;
spItem = itm;
BSTR curMsgClass;
spItem->get_MessageClass(&curMsgClass);
if (FAILED(hr)) {
AfxMessageBox("Error converting items (message class)");
break;
}
CString* curMsgClassStr = ToCString(curMsgClass); //conversion from BSTR
to CString
CString* oldMsgClassStr = ToCString(oldMsgClass); //conversion from BSTR
to CString
if (curMsgClassStr->Compare(*oldMsgClassStr) ==0) {
spItem->put_MessageClass(newMsgClass);
spItem->Save();
AfxMessageBox("Item Converted");
}
}
AfxMessageBox("Conversion finished");
The conversion process seem works fine, in fact when I read MessageClass
of
contact items with Oulook Spy I obtain "IPM.Contact.MyForm". But the look
of
items is the same of default "IPM.Contact"...
Where I'm wrong?
Bye
Andrea