Prevent "Save changes" message box when programatically customising form

M

Matt Fletcher

I'm customising the a form programatically (currently just playing around
with colours and field locations, and adding a button). When I close a
message which has these customisations applied, Outlook prompts me to save
changes to the item.

Is it possible to suppress this message cleanly (maybe by somehow discarding
the changes)? Or do I have to hook the message box?

Thanks for any help
Matt Fletcher
 
S

Sue Mosher [MVP-Outlook]

Sounds like you're doing more than just playing with controls. You won't get
that message unless a property has changed. You might want to add code to
the PropertyChange and CustomPropertyChange events to see what's going on.
 
M

Matt Fletcher

Sue,

thanks for the reply. I've stripped down my code to find the minimum that
will cause the Save changes message box to display - all I need to do is to
add the "Message" page to the ModifiedFormPages collection (i.e. I have
removed all the useful code that actually customises the form, and just left
the basis for applying the customisation). I've tried to remove the added
page from the ModifiedFormPages collection when the item is closed, but this
throws an exception.

A fix for this would be nice as even though I can hook the message box, I
can't suppress the beep.

Matt Fletcher
 
S

Sue Mosher [MVP-Outlook]

Code snippet?

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
M

Matt Fletcher

Sue,

here's the minimum (C++) code that causes the Save changes message box to
appear. Note that this code is a handler for
MailItemEvents::Open.

STDMETHODIMP_(void) CMailHandler::OnOpen(VARIANT_BOOL* Cancel)
{
..
..
try
{
PagesPtr spPages = m_spInspector->ModifiedFormPages;

if (spPages)
{
IDispatchPtr spPageDisp = spPages->Add("Message");

// convert spPageDisp to MSUserForms::_UserFormPtr and amend
controls - commented out at present
}
}
catch (_com_error & e)
{
SPTRACE("CMailHandler::OnOpen - caught COM error: %s\n",
e.ErrorMessage());
}
..
..
}

I've commented out all my code which uses spPageDisp, and the problem still
occurs

Matt Fletcher
 
S

Sue Mosher [MVP-Outlook]

Ah, I see now (despite my minimal ability to read C++ code). By customizing
the form programmatically in this fashion, you are actually embedding the
form in the item and thus causing the item itself to change. You cannot,
therefore, avoid the message box.

I do hope you're publishing the form after you customize it? Otherwise,
you'll have a one-off.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
M

Matt Fletcher

Sue,

Thanks for your assistance.

As the customisation will only be applied to received mails, I won't be
publishing the form - the addin will amend the form each time it is opened.
So if I avoid saving the form, I only create a temporary one-off form for
the life of the Inspector. (The reason I've adopted this approach is partly
to avoid one-off forms when forwarding SMIME mails viewed in a custom form).
I found mention of this technique in KB238755 ("OL2000: How to
Programmatically Create a Form") - I'm surprised that it hasn't been
developed further, as it makes a lot of sense from an addin developer's
point of view.

I'll just need to get my hooking code to work, and work out how to suppress
the beep (if it's possible).

Matt Fletcher
 

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