Microsoft KB Archive/170601: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - "&" to "&")
 
(One intermediate revision by the same user not shown)
Line 80: Line 80:
                                                 PR_ACCESS };
                                                 PR_ACCESS };


       hRes = pFolder -> CreateMessage ( NULL, 0L, &pMsg );
       hRes = pFolder -> CreateMessage ( NULL, 0L, &pMsg );


       if ( SUCCEEDED ( hRes ) )
       if ( SUCCEEDED ( hRes ) )
           hRes = pMsg -> SaveChanges ( KEEP_OPEN_READWRITE );
           hRes = pMsg -> SaveChanges ( KEEP_OPEN_READWRITE );


       // Need to know certain properties of message for ShowForm.
       // Need to know certain properties of message for ShowForm.
       hRes = pMsg -> GetProps ( (LPSPropTagArray)&sptMsgProps,
       hRes = pMsg -> GetProps ( (LPSPropTagArray)&sptMsgProps,
                                 0L,
                                 0L,
                                 &cValues,
                                 &cValues,
                                 &pPropsMsg );
                                 &pPropsMsg );


       // Get an IFormManager interface pointer
       // Get an IFormManager interface pointer
       if ( FAILED ( hRes = MAPIOpenFormMgr ( m_pSession, &pFormMgr ) ) )
       if ( FAILED ( hRes = MAPIOpenFormMgr ( m_pSession, &pFormMgr ) ) )
           goto Quit;
           goto Quit;


       // Use the message class of the message to resolve to the correct
       // Use the message class of the message to resolve to the correct
       //  message class.
       //  message class.
       if ( FAILED ( hRes = pFormMgr->ResolveMessageClass (
       if ( FAILED ( hRes = pFormMgr->ResolveMessageClass (
                                     pPropsMsg[0].Value.lpszA,
                                     pPropsMsg[0].Value.lpszA,
                                     MAPIFORM_EXACTMATCH,
                                     MAPIFORM_EXACTMATCH,
                                     NULL,
                                     NULL,
                                     &pFormInfo ) ) )
                                     &pFormInfo ) ) )
           goto Quit;
           goto Quit;


       // Create an instance of the form and store is in an
       // Create an instance of the form and store is in an
       // IPersistMessage interface pointer.
       // IPersistMessage interface pointer.
       if ( FAILED ( hRes = pFormMgr -> CreateForm ( m_hWnd,
       if ( FAILED ( hRes = pFormMgr -> CreateForm ( m_hWnd,
                                           0L,
                                           0L,
                                           pFormInfo,
                                           pFormInfo,
                                           IID_IPersistMessage,
                                           IID_IPersistMessage,
                                           (LPVOID*) &pPersistMessage ) ) )
                                           (LPVOID*) &pPersistMessage ) ) )
           goto Quit;
           goto Quit;


       // Call the IPersistMessage::Save method.
       // Call the IPersistMessage::Save method.
       pPersistMessage -> Save ( pMsg, TRUE );
       pPersistMessage -> Save ( pMsg, TRUE );


       // Prepare the form to be loaded by getting its token.
       // Prepare the form to be loaded by getting its token.
       if ( FAILED ( hRes = m_pSession -> PrepareForm ( &IID_IMessage,
       if ( FAILED ( hRes = m_pSession -> PrepareForm ( &IID_IMessage,
                                           pMsg,
                                           pMsg,
                                           &ulMessageToken ) ) )
                                           &ulMessageToken ) ) )
           goto Quit;
           goto Quit;


Line 125: Line 125:
       // properties we retreived above will be used in each of the
       // properties we retreived above will be used in each of the
       // corresponding parameters in this call.
       // corresponding parameters in this call.
       if ( FAILED ( m_pSession -> ShowForm (
       if ( FAILED ( m_pSession -> ShowForm (
                                   m_hWnd,
                                   m_hWnd,
                                   m_pMDB,
                                   m_pMDB,
                                   pFolder,
                                   pFolder,
                                   &IID_IMessage,
                                   &IID_IMessage,
                                   ulMessageToken,
                                   ulMessageToken,
                                   0L,
                                   0L,
Line 146: Line 146:
       if ( NULL != pMsg )
       if ( NULL != pMsg )
       {
       {
           pMsg -> Release ( );
           pMsg -> Release ( );
           pMsg = NULL;
           pMsg = NULL;
       }
       }
Line 152: Line 152:
       if ( NULL != pFormMgr )
       if ( NULL != pFormMgr )
       {
       {
           pFormMgr -> Release ( );
           pFormMgr -> Release ( );
           pFormMgr = NULL;
           pFormMgr = NULL;
       }
       }
Line 158: Line 158:
       if ( NULL != pFormInfo )
       if ( NULL != pFormInfo )
       {
       {
           pFormInfo -> Release ( );
           pFormInfo -> Release ( );
           pFormInfo = NULL;
           pFormInfo = NULL;
       }
       }
Line 164: Line 164:
       if ( NULL != pPersistMessage )
       if ( NULL != pPersistMessage )
       {
       {
           pPersistMessage -> Release ( );
           pPersistMessage -> Release ( );
           pPersistMessage = NULL;
           pPersistMessage = NULL;
       }
       }

Latest revision as of 12:29, 21 July 2020

Knowledge Base


How To Displaying the Compose IPM.Note Form

Article ID: 170601

Article Last Modified on 8/18/2005



APPLIES TO

  • Microsoft Messaging Application Programming Interface



This article was previously published under Q170601

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;
   }
                

Keywords: kbhowto kbmsg KB170601