📄 form.cpp
字号:
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/******************************************************************************
File: form.cpp
******************************************************************************/
#include "form.h"
#include "msgform.h"
/******************************************************************************
CFormProvider static member values initialization
******************************************************************************/
BOOL CFormProvider::m_fInitPropTags = FALSE;
ULONG CFormProvider::m_tagSMSUnicode = PR_NULL;
/******************************************************************************
FormFactoryEx - Entrypoint for the Inbox application to use to create forms
Params:
pszMsgClass[in] - specifies message class for forms
ppvObject[out] - address to store the retrieved interface. Set to NULL
if the incoming parameters are valid but the object could
not be created. Not touched if the incoming parameters
are invalid.
Returns:
S_OK if the object implementing the interface requested is available and
created.
MAPI_E_INVALID_PARAMETER if one or both of the incoming parameters
is NULL.
MAPI_E_NOT_ENOUGH_MEMORY if a memory allocation fails.
Side effects:
A CFormProvider object is created.
Description:
This is the entrypoint in the DLL that the Inbox application will look
for in order to retrieve an IFormProviderEx interface. This interface
provides two methods that the app will use to create message forms,
CreateComposeForm() and CreateReadForm(), as well as a method to
retrieve the index of the image to be used in the application's
listview for this type of message, GetMsgStatusIconIndex().
******************************************************************************/
HRESULT WINAPI FormFactoryEx(LPCWSTR pszMsgClass,
IFormProviderEx** ppvObject)
{
HRESULT hr = S_OK;
//Validate params
ASSERT(NULL != pszMsgClass);
ASSERT(NULL != ppvObject);
if (NULL == pszMsgClass ||
NULL == ppvObject)
{
RETAILMSG(TRUE, (_T("FormFactoryEx::Invalid argument\n")));
return MAPI_E_INVALID_PARAMETER;
}
//Create the new CFormProvider object to hand back to the application.
*ppvObject = new CFormProvider;
MAPI_EXIT_ON_NULL(*ppvObject);
//Now take any action required to use the provider.
hr = ((CFormProvider*)(*ppvObject))->Init(pszMsgClass);
EXIT_ON_FAILED(hr);
Exit:
if(FAILED(hr))
{
SAFE_DELETE(*ppvObject);
}
return hr;
}
/******************************************************************************
CFormProvider::CFormProvider - C'TOR
******************************************************************************/
CFormProvider::CFormProvider() :
m_cRef(1),
m_pMsgStore(NULL),
m_pSession(NULL),
m_pszMessageClass(NULL)
{
}
/******************************************************************************
CFormProvider::~CFormProvider - D'TOR
******************************************************************************/
CFormProvider::~CFormProvider()
{
//SAFE_RELEASE(m_pMsg);
SAFE_RELEASE(m_pMsgStore);
//Release session object last
SAFE_RELEASE(m_pSession);
delete [] m_pszMessageClass;
}
/******************************************************************************
CFormProvider::QueryInterface - Standard COM QueryInterface method.
******************************************************************************/
HRESULT CFormProvider::QueryInterface(REFIID iid, void** ppvObject)
{
// Any interface on this object is the object pointer
if(IID_IUnknown == iid)
{
*ppvObject = this;
}
else if(IID_IFormProviderEx == iid)
{
*ppvObject = reinterpret_cast<IFormProviderEx*>(this);
}
else
{
*ppvObject = NULL;
return(MAPI_E_INTERFACE_NOT_SUPPORTED);
}
//Increment the refcount and return success
AddRef();
return S_OK;
}
/******************************************************************************
CFormProvider::AddRef - Standard COM AddRef method.
******************************************************************************/
ULONG CFormProvider::AddRef()
{
return InterlockedIncrement((long*)&m_cRef);
}
/******************************************************************************
CFormProvider::Release - Standard COM Release method.
******************************************************************************/
ULONG CFormProvider::Release()
{
if(0 == InterlockedDecrement((long*)&m_cRef))
{
delete this;
return 0;
}
return m_cRef;
}
/******************************************************************************
CFormProvider::GetMsgStatusIconIndex -
IFormProviderEx::GetMsgStatusIconIndex implementation.
Params:
pfldr[in] - ignored
pid[in] - ignored
cbId[in] - ignored
ffFlags[in] - ignored
ffStatus[in] - ignored
pszMsgClass[in] - ignored
cAttachments[in]- ignored
pnIndex[in/out] - image index to use for the message icon
Returns:
S_OK is always returned when pnIndex is non-NULL.
MAPI_E_INVALID_PARAMETER is returned when pnIndex is NULL.
Remarks:
Returns the image index to use for the message icon. 0 is the standard
unread normal message icon index.
******************************************************************************/
HRESULT CFormProvider::GetMsgStatusIconIndex(LPMAPIFOLDER pfldr,
LPENTRYID pid,
ULONG cbId,
ULONG ffFlags,
ULONG ffStatus,
LPCWSTR pszMsgClass,
ULONG cAttachments,
ULONG* pnIndex)
{
HRESULT hr = S_OK;
//Validate param(s)
ASSERT(NULL != pnIndex);
MAPI_CHP(pnIndex);
//Start off with Unread normal message.
*pnIndex = 0;
Exit:
return S_OK;
}
/******************************************************************************
CFormProvider::CreateComposeForm - IFormProviderEx::CreateComposeForm
implementation.
Params:
pHost[in] - Interface for the Inbox application.
pMsg[in] - Interface of message to be composed.
eFormType[in] - Form type (Read, Reply, Reply All, Forward)
pMsgBase[in] - Base message for pMsg
pMsgFields[in] - Message field flags
hwndForm[in] - HWND of the form frame
phwndBody[in] - HWND of the form-created body
ppForm[in] - Interface of compose form for created.
Returns:
S_OK if the compose form was successfully created.
MAPI_E_INVALID_PARAMETER if ppForm is NULL.
MAPI_E_NOT_ENOUGH_MEMORY if a memory allocation fails.
E_FAIL if any other error occurs.
Remarks:
Creates a compose message form and returns an interface to that form's
IMessageForm interface to the caller.
******************************************************************************/
HRESULT CFormProvider::CreateComposeForm(IMessageFormHostEx* pHost,
LPMESSAGE pMsg,
FORMTYPE eFormType,
LPMESSAGE pMsgBase,
MESSAGEFIELDS* pMsgFields,
HWND hwndForm,
HWND* phwndBody,
IMessageFormEx** ppForm)
{
//We don't support compose EMS in this sample
HRESULT hr = E_FAIL;
return hr;
}
/******************************************************************************
CFormProvider::CreateReadForm - IFormProviderEx::CreateReadForm
implementation.
Params:
pHost[in] - Interface for the Inbox application.
pMsg[in] - Message to fill the form.
hwndForm[in] - HWND of the form frame
phwndBody[in/out] - HWND of the form-created body
ppForm[in/out] - Interface of read form for created.
Returns:
S_OK if the read form was successfully created.
MAPI_E_INVALID_PARAMETER if ppForm is NULL.
MAPI_E_NOT_ENOUGH_MEMORY if a memory allocation fails.
Also, any valid return value from MAPILogonEx(), OpenMsgStore(), or
GetIDsFromNames() may be returned if one of those calls fails.
Remarks:
Creates a read message form and returns an interface to that form's
IMessageForm interface to the caller.
******************************************************************************/
HRESULT CFormProvider::CreateReadForm(IMessageFormHostEx* pHost,
LPMESSAGE pMsg,
HWND hwndForm,
HWND* phwndBody,
IMessageFormEx** ppForm)
{
MESSAGEFIELDS msgFields = {0};
HRESULT hr = E_FAIL;
CMsgForm* pForm = NULL;
// Validate input
ASSERT (pMsg != NULL);
ASSERT(NULL != ppForm);
MAPI_CHP(ppForm);
*ppForm = NULL;
//Clean up any other previous sessions
CleanUpReadForm();
//Inbox cleans up this new, when the form calls . This is
//done whenever the user quits, sends, replies, or deletes a form.
pForm = new CMsgForm(pHost, pMsg);
MAPI_EXIT_ON_NULL(pForm);
//Now initialize the form.
hr = pForm->Init(this, hwndForm, phwndBody, &msgFields);
EXIT_ON_FAILED(hr);
// Let the form know if we'll be prefilling with an existing message's data.
hr = pForm->SetMessage(0, pMsg);
EXIT_ON_FAILED(hr);
// Everything worked ok.
*ppForm = pForm;
hr = S_OK;
Exit:
return hr;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -