HOWTO: Displaying the Compose IPM.Note Form
ID: Q170601
|
The information in this article applies to:
-
Extended Messaging Application Programming Interface (MAPI), version 1.0
SUMMARY
This article demonstrates code for creating and sending a message using the
default Compose Note form using Extended MAPI.
MORE INFORMATION
A key feature to any messaging client is the ability to send and read a
message. It is up to you as the developer to decide whether or not your
user are presented with your own specially designed form for sending and
reading messages. If you choose to allow the user to use the default form
of the messaging subsystem for the purpose of either sending or reading
messages, the following code shows you one possible way of implementing
this:
HRESULT ShowForm ( LPMAPISESSION m_pSession,
LPMAPIFOLDER pFolder,
HWND m_hWnd )
{
HRESULT hRes = S_OK;
enum {MSG_CLASS, MSG_STATUS, MSG_FLAGS, MSG_ACCESS };
LPSPropValue pProps = NULL;
ULONG cProps,
ulObjType;
LPMESSAGE pMsg = NULL;
LPMAPIFORMMGR pFormMgr = NULL;
LPMAPIFORMINFO pFormInfo = NULL;
LPPERSISTMESSAGE pPersistMessage = NULL;
ULONG ulMessageToken = 0L,
cValues = 0L;
LPSPropValue pPropsMsg = NULL;
// Message properties tag array
SizedSPropTagArray ( 4, sptMsgProps ) = { 4,
PR_MESSAGE_CLASS,
PR_MSG_STATUS,
PR_MESSAGE_FLAGS,
PR_ACCESS };
hRes = pFolder -> CreateMessage ( NULL, 0L, &pMsg );
if ( SUCCEEDED ( hRes ) )
hRes = pMsg -> SaveChanges ( KEEP_OPEN_READWRITE );
// Need to know certain properties of message for ShowForm.
hRes = pMsg -> GetProps ( (LPSPropTagArray)&sptMsgProps,
0L,
&cValues,
&pPropsMsg );
// Get an IFormManager interface pointer
if ( FAILED ( hRes = MAPIOpenFormMgr ( m_pSession, &pFormMgr ) ) )
goto Quit;
// Use the message class of the message to resolve to the correct
// message class.
if ( FAILED ( hRes = pFormMgr->ResolveMessageClass (
pPropsMsg[0].Value.lpszA,
MAPIFORM_EXACTMATCH,
NULL,
&pFormInfo ) ) )
goto Quit;
// Create an instance of the form and store is in an
// IPersistMessage interface pointer.
if ( FAILED ( hRes = pFormMgr -> CreateForm ( m_hWnd,
0L,
pFormInfo,
IID_IPersistMessage,
(LPVOID*) &pPersistMessage ) ) )
goto Quit;
// Call the IPersistMessage::Save method.
pPersistMessage -> Save ( pMsg, TRUE );
// Prepare the form to be loaded by getting its token.
if ( FAILED ( hRes = m_pSession -> PrepareForm ( &IID_IMessage,
pMsg,
&ulMessageToken ) ) )
goto Quit;
// Call the session object's ShowForm method. Each of the
// properties we retreived above will be used in each of the
// corresponding parameters in this call.
if ( FAILED ( m_pSession -> ShowForm (
m_hWnd,
m_pMDB,
pFolder,
&IID_IMessage,
ulMessageToken,
0L,
MAPI_NEW_MESSAGE,
pPropsMsg[MSG_STATUS].Value.l,
pPropsMsg[MSG_FLAGS].Value.l,
pPropsMsg[MSG_ACCESS].Value.l,
pPropsMsg[MSG_CLASS].Value.lpszA)))
goto Quit;
// Clean up and release all objects no longer needed in this
// method. Be sure to return the value of hRes to the caller.
Quit:
if ( NULL != pMsg )
{
pMsg -> Release ( );
pMsg = NULL;
}
if ( NULL != pFormMgr )
{
pFormMgr -> Release ( );
pFormMgr = NULL;
}
if ( NULL != pFormInfo )
{
pFormInfo -> Release ( );
pFormInfo = NULL;
}
if ( NULL != pPersistMessage )
{
pPersistMessage -> Release ( );
pPersistMessage = NULL;
}
return hRes;
}
Additional query words:
Keywords : kbMsg kbMAPI100 MAPIFORM
Version : WINDOWS:1.0
Platform : WINDOWS
Issue type : kbhowto