home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / sdk / mapi / win16 / dev / mdbview / attach.cpp next >
Encoding:
C/C++ Source or Header  |  1995-07-11  |  15.9 KB  |  579 lines

  1. /*******************************************************************/
  2. /*
  3.  -  Attach.cpp
  4.  -  Copyright (C) 1995 Microsoft Corporation
  5.  -
  6.  *  Purpose:
  7.  *      Contains member functions for CAttachDlg.
  8.  *      CAttachDlg is a class dialog that allows manipulation and
  9.  *      display of Attachment properties and operations.
  10.  */
  11. /*******************************************************************/
  12.                                                    
  13. #undef  CINTERFACE      // use C++ calling convention for mapi calls
  14.  
  15.  
  16. #ifdef WIN32
  17. #ifdef _WIN95
  18. #define _INC_OLE
  19. #endif
  20. #define INC_OLE2
  21. #define INC_RPC
  22. #endif
  23.  
  24. #include <afxwin.h>     
  25. #include <string.h>
  26.  
  27. #ifdef WIN16
  28. #include <compobj.h>
  29. #endif
  30.  
  31. #ifdef WIN32
  32. #include <objbase.h>
  33. #include <objerror.h>
  34. #ifdef _WIN95
  35. #include <ole2.h>
  36. #endif
  37. #endif
  38.  
  39. #include <mapix.h>
  40. #include <strtbl.h>     
  41. #include "resource.h"   
  42. #include "mdbview.h" 
  43. #include "attach.h"
  44. #include "oper.h"
  45. #include "msg.h"
  46.  
  47. /* PROPVU functions */
  48.  
  49. extern HINSTANCE    hlibPROPVU;
  50.  
  51. typedef BOOL (*LPFNVIEWMAPIPROP)(
  52.     LPSTR           lpszName,
  53.     LPMAPIPROP FAR *lppMAPIProp,
  54.     LPVOID          lpvDest,
  55.     HWND            hWnd);    
  56.  
  57. extern LPFNVIEWMAPIPROP lpfnViewMapiProp;
  58.  
  59. #define PROPVUViewMapiProp (*lpfnViewMapiProp)
  60.  
  61.  
  62.  
  63. extern LPMDB                lpMDB;
  64. extern LPVOID               lpvCopyToDest;
  65.  
  66. /******************* Attachment Message Map ****************************/
  67.  
  68. BEGIN_MESSAGE_MAP(CAttachDlg, CDialog)
  69.  
  70.     ON_LBN_DBLCLK(  IDC_PROPS,          OnPropInterface)
  71.     ON_COMMAND(     IDC_CALLFUNC,       OnCallFunction)
  72.     ON_COMMAND(     IDC_PROPINTERFACE,  OnPropInterface)
  73.     ON_COMMAND(     IDC_SPECIALPROPS,   OnSpecialProps)
  74.                                         
  75. END_MESSAGE_MAP() 
  76.  
  77.  
  78. /*******************************************************************/
  79. /**************************** Attach ******************************/
  80.  
  81. /*******************************************************************/
  82. /*
  83.  -  CAttachDlg::
  84.  -  OnSetCopyToDest
  85.  *
  86.  *  Purpose:
  87.  *      Set Destination object of CopyTo operation or CopyMessage or CopyFolder
  88.  *
  89.  *  lpvCopyToDest and CopyToDest are global
  90.  */
  91. /*******************************************************************/
  92.  
  93. void CAttachDlg::OnSetCopyToDest()
  94. {                
  95.     char    szBuffer[256];
  96.     
  97.     lpvCopyToDest   = (LPVOID) m_lpAttach;       
  98.  
  99.     wsprintf(szBuffer,"%s is next Destination for CopyTo(), CopyMessage(), or CopyFolder()",
  100.                 m_CurrentAttach.GetBuffer(40) );
  101.  
  102.     MessageBox( szBuffer,"Client", MBS_INFO );
  103.  
  104. }    
  105.  
  106. /********************************************************************/
  107. /*
  108.  -  CAttachDlg::
  109.  -  InitAttachDialog
  110.  -
  111.  *  Purpose:
  112.  *      Initialize the dialog after it was created in the PropDlg class
  113.  *      This routine is called in the constructor in instead of OnInitDialog()
  114.  *      so that it can fill in all of the appropriate listboxes, etc in
  115.  *      the dialog.  We can't use the OnInitDialog because the OnInitDialog
  116.  *      in the PropDialog Class and MFC doesn't explicitly call it for
  117.  *      this inherited class as well.
  118.  */
  119. /********************************************************************/
  120.  
  121. BOOL CAttachDlg::InitAttachDialog()
  122. {
  123.     DWORD           dwReturn    = 0;
  124.     LPSPropValue    lpspva      = NULL;
  125.     ULONG           ulValues    = 0;
  126.     DWORD           dwIndex     = 0;
  127.     
  128.     SizedSPropTagArray(1,sptaMethod) = 
  129.     {
  130.         1, 
  131.         { 
  132.             PR_ATTACH_METHOD,
  133.         }
  134.     };
  135.  
  136.  
  137.     // set title of dialog to attachment name/number
  138.     SetWindowText( m_CurrentAttach.GetBuffer(15) );
  139.  
  140.     m_hResult = m_lpAttach->GetProps( (LPSPropTagArray) &sptaMethod,0, &ulValues, &lpspva);
  141.     wsprintf(m_szLogBuf,"lpAttach->GetProps( &sptaMethod, &ulValues, &lpspva)\t SC: %s",
  142.                         GetString( "MAPIErrors", GetScode(m_hResult), m_szError ) );
  143.  
  144.     if( HR_FAILED(m_hResult))        
  145.     {
  146.         MessageBox( m_E.SzError("lpAttach->GetProps(&spta)",m_hResult),
  147.                      "Client", MBS_ERROR );
  148.     }
  149.  
  150.     dwReturn = SendDlgItemMessage(IDC_ATTMETHOD,LB_ADDSTRING,0,
  151.                         (LPARAM) GetString("AttachMethod",lpspva[0].Value.l,NULL) );
  152.  
  153.     if(lpspva)
  154.         MAPIFreeBuffer(lpspva);
  155.  
  156.     // disable the system menu close item
  157.     //  this is done because there is a MFC 2.0 bug that
  158.     //  makes you capture several PostNcDestroy messages etc.
  159.     GetSystemMenu(FALSE)->EnableMenuItem(SC_CLOSE, MF_GRAYED);
  160.  
  161.     // inherited property class operations for initialization
  162.     ResetPropButtons();
  163.     RedrawPropTable();
  164.  
  165.     //***** Add Strings to call function combo box *****
  166.     //***** Add Strings to call function combo box *****
  167.  
  168.     dwIndex = SendDlgItemMessage(IDC_FUNCTIONS, CB_ADDSTRING,
  169.                                 (WPARAM) 0 , (LPARAM) (LPCTSTR) "Attachment Properties" );
  170.  
  171.     if( (dwIndex == CB_ERR ) || (dwIndex == CB_ERRSPACE) )
  172.     {
  173.         MessageBox( "CB_ADDSTRING functions returned Error", "Client", MBS_ERROR );
  174.         return FALSE;
  175.     }            
  176.  
  177.     dwIndex = SendDlgItemMessage(IDC_FUNCTIONS, CB_ADDSTRING,
  178.                                 (WPARAM) 0 , (LPARAM) (LPCTSTR) "Message Store Properties" );
  179.  
  180.     if( (dwIndex == CB_ERR ) || (dwIndex == CB_ERRSPACE) )
  181.     {
  182.         MessageBox( "CB_ADDSTRING functions returned Error", "Client", MBS_ERROR );
  183.         return FALSE;
  184.     }            
  185.  
  186.  
  187.     dwIndex = SendDlgItemMessage(IDC_FUNCTIONS, CB_ADDSTRING,
  188.                                 (WPARAM) 0 , (LPARAM) (LPCTSTR) "Open Attachment as Message" );
  189.  
  190.     if( (dwIndex == CB_ERR ) || (dwIndex == CB_ERRSPACE) )
  191.     {
  192.         MessageBox( "CB_ADDSTRING functions returned Error", "Client", MBS_ERROR );
  193.         return FALSE;
  194.     }            
  195.  
  196.  
  197.     dwIndex = SendDlgItemMessage(IDC_FUNCTIONS, CB_ADDSTRING,
  198.                                 (WPARAM) 0 , (LPARAM) (LPCTSTR) "INTERNAL -- SET THIS FOLDER AS COPY DESTINATION" );
  199.  
  200.     if( (dwIndex == CB_ERR ) || (dwIndex == CB_ERRSPACE) )
  201.     {
  202.         MessageBox( "CB_ADDSTRING functions returned Error", "Client", MBS_ERROR );
  203.         return FALSE;
  204.     }            
  205.  
  206.  
  207.     // SET CURRENT SELECTION IN COMBO BOX TO 1ST ITEM
  208.     dwIndex = SendDlgItemMessage(IDC_FUNCTIONS, CB_SETCURSEL,
  209.                                 (WPARAM) 0 , (LPARAM) 0 );
  210.  
  211.     if( (dwIndex == CB_ERR ) || (dwIndex == CB_ERRSPACE) )
  212.     {
  213.         MessageBox( "CB_SETCURSEL functions returned Error", "Client", MBS_ERROR );
  214.         return FALSE;
  215.     }            
  216.  
  217.     return TRUE;
  218.  
  219. }   
  220.  
  221. /********************************************************************/
  222. /*
  223.  -  CAttachDlg::
  224.  -  OnCallFunction
  225.  -
  226.  *  Purpose:
  227.  *
  228.  /********************************************************************/
  229.  
  230. void CAttachDlg::OnCallFunction()
  231. {
  232.     LONG    lCurSelect = CB_ERR;
  233.     
  234.     // get the selection from the Drop Down Listbox combo box
  235.     // and switch to appropriate function selected based upon 
  236.     // position in the combo box. (NOTE position is determined by
  237.     // initialization from OnInitFld  order of adding to combobox
  238.     
  239.     // GetCurrentSelection Position
  240.     lCurSelect = SendDlgItemMessage(IDC_FUNCTIONS,CB_GETCURSEL, (WPARAM) 0, (LPARAM) 0 );
  241.     if(lCurSelect == CB_ERR)
  242.     {
  243.         // no item was selected, bring up dialog to tell them to select something
  244.         MessageBox( "Please Select a function in the adjacent drop down listbox to call",
  245.                 "Client", MBS_OOPS );
  246.         return;
  247.    
  248.     }
  249.     // else it is a valid index in combo box
  250.  
  251.     // Switch to appropriate function
  252.     switch(lCurSelect)
  253.     {
  254.         // Attach FUNCTIONS
  255.         case 0:        
  256.             OnPropInterface();       
  257.             break;
  258.         case 1:
  259.             OnMDBProp();             
  260.             break;
  261.         case 2:
  262.             OnOpenAttachAsMsg();
  263.             break;
  264.         case 3:
  265.             OnSetCopyToDest();      
  266.             break;
  267.  
  268.         default:
  269.             MessageBox( "CAttachDlg::OnCallFunction() default ",
  270.                 "Client", MBS_OOPS );
  271.             break;       
  272.     }    
  273.  
  274. }
  275.  
  276.  
  277.  
  278. /*******************************************************************/
  279. /*
  280.  -  CAttachDlg::
  281.  -  OnOpenAttachAsMsg
  282.  *
  283.  *  Purpose:
  284.  *     Open An Attachment as a message in message
  285.  */
  286. /*******************************************************************/
  287.  
  288. void CAttachDlg::OnOpenAttachAsMsg()
  289. {            
  290.     LPIID           lpInterface     = 0;
  291.     LPUNKNOWN       lpUnk           = NULL;
  292.     ULONG           ulInterfaceOptions = 0;    
  293.     CMessageDlg     *lpMessageDlg   = NULL;
  294.  
  295.     // if we have a data object, open property on this and open the message
  296.     lpInterface = (LPIID)(&IID_IMessage);
  297.  
  298.     m_hResult = m_lpAttach->OpenProperty(
  299.                             PR_ATTACH_DATA_OBJ,
  300.                             lpInterface,
  301.                             ulInterfaceOptions,
  302.                             MAPI_MODIFY,
  303.                             &lpUnk  );
  304.     wsprintf(m_szLogBuf,"lpAttach->OpenProperty(PR_ATTACH_DATA_OBJ,0x%X,%lu,MAPI_MODIFY,&lpUnk)\t SC: %s",
  305.                         lpInterface,ulInterfaceOptions, GetString( "MAPIErrors", GetScode(m_hResult), m_szError ) );
  306.  
  307.     if(HR_FAILED(m_hResult) )
  308.     {
  309.         MessageBox( m_E.SzError("lpAttach->OpenProperty(PR_ATTACH_DATA_OBJ)", m_hResult), 
  310.                             "Client", MBS_ERROR );
  311.         return;
  312.     }
  313.  
  314.     lpMessageDlg   =  new CMessageDlg("MESSAGE IN MESSAGE",(LPMESSAGE)lpUnk,this);
  315. }    
  316.  
  317.  
  318.  
  319. /*******************************************************************/
  320. /*
  321.  -  CAttachDlg::
  322.  -  OnCancel
  323.  -
  324.  *  Purpose:
  325.  *      Closes the Attach viewer dialog.
  326.  *
  327.  */
  328. /*******************************************************************/
  329.  
  330. void CAttachDlg::OnCancel()
  331. {
  332.     delete this;
  333. }
  334.  
  335. /*******************************************************************/
  336. /*
  337.  -  CAttachDlg::
  338.  -  Cleanup
  339.  -
  340.  *  Purpose:
  341.  *      Cleanup called by destructor for class CAttachDlg.  
  342.  *      Releases and Frees memory allocated in class
  343.  */
  344. /*******************************************************************/
  345.  
  346. void CAttachDlg::Cleanup()
  347. {   
  348.     if(m_lpAttach)
  349.     {
  350.         m_lpAttach->Release();
  351.         m_lpAttach  = NULL;
  352.         m_lpEntry   = NULL;
  353.     }
  354. }    
  355.  
  356.  
  357.  
  358. /********************************************************************/
  359. /*
  360.  -  CAttachDlg::
  361.  -  OnPropInterface
  362.  -
  363.  *  Purpose:
  364.  *  
  365.  /********************************************************************/
  366.  
  367. void CAttachDlg::OnPropInterface()
  368. {       
  369.     char    szBuffer[80];
  370.     
  371.     
  372.     lstrcpy(szBuffer,m_CurrentAttach.GetBuffer(50));
  373.     lstrcat(szBuffer," Properties");
  374.  
  375.     PROPVUViewMapiProp(szBuffer, 
  376.                 (LPMAPIPROP FAR *)&m_lpEntry,lpvCopyToDest, (HWND)this->m_hWnd );
  377. }
  378.  
  379.  
  380. /********************************************************************/
  381. /*
  382.  -  CAttachDlg::
  383.  -  OnMDBProp
  384.  -
  385.  *  Purpose:
  386.  *  
  387.  /********************************************************************/
  388.  
  389. void CAttachDlg::OnMDBProp()
  390. {   
  391.     PROPVUViewMapiProp("MDB Properties", 
  392.             (LPMAPIPROP FAR *)&lpMDB, lpvCopyToDest, (HWND)this->m_hWnd );
  393. }
  394.   
  395. /*******************************************************************/
  396. /*
  397.  -  CAttachDlg::
  398.  -  OnSpecialProps
  399.  -
  400.  *  Purpose:
  401.  *      Closes the Attach dialog.
  402.  *
  403.  */
  404. /*******************************************************************/
  405.  
  406. void CAttachDlg::OnSpecialProps()
  407. {
  408.     CAttachSpecialDlg    AttachSpecial((LPATTACH)m_lpAttach,this);
  409.     AttachSpecial.DoModal();
  410. }
  411.  
  412.  
  413. /*******************************************************************/
  414. /*********************** AttachSpecial **************************/
  415.  
  416. /********************************************************************/
  417. /*
  418.  -  CAttachSpecialDlg::
  419.  -  OnInitDialog
  420.  -
  421.  *  Purpose:
  422.  *
  423.  */
  424. /********************************************************************/
  425.  
  426. BOOL CAttachSpecialDlg::OnInitDialog()
  427. {
  428.     CGetError       E;
  429.     DWORD           dwReturn            = 0;
  430.     HRESULT         hResult             = hrSuccess;
  431.     char            szBuffer[300];
  432.     ULONG           cVals               = 0;
  433.     LPSPropValue    lpspva              = NULL;
  434.     ULONG           i;
  435.  
  436.   
  437.     SizedSPropTagArray(4,sptaAttachSpecial) =
  438.     {
  439.         4,
  440.         {
  441.             PR_ATTACH_METHOD,
  442.             PR_OBJECT_TYPE,
  443.             PR_ACCESS,
  444.             PR_ACCESS_LEVEL,
  445.         }
  446.     };
  447.  
  448.  
  449.  
  450.     hResult = m_lpAttach->GetProps((LPSPropTagArray)&sptaAttachSpecial,0,&cVals,&lpspva);
  451.     if( HR_FAILED(hResult) )
  452.     {
  453.         MessageBox( E.SzError("lpMDB->GetProps(sptaAttachSpecial)", hResult),
  454.                  "Client", MBS_ERROR );
  455.         return FALSE;
  456.     }
  457.  
  458.     i = 0;
  459.  
  460.  
  461.     // PR_ATTACH_METHOD
  462.     if(lpspva[i].ulPropTag != PR_ATTACH_METHOD )
  463.     {
  464.         if( PROP_TYPE(lpspva[i].ulPropTag) == PT_ERROR)
  465.             GetString( "MAPIErrors", lpspva[i].Value.err, szBuffer );
  466.         else
  467.             wsprintf(szBuffer,"PR_ATTACH_METHOD not available");
  468.     }
  469.     else
  470.         GetString("AttachMethod",lpspva[0].Value.l,szBuffer);
  471.     SetDlgItemText(IDT_ATTACH_METHOD1,szBuffer);
  472.     i++;
  473.  
  474.  
  475.     // PR_OBJECT_TYPE
  476.     if(lpspva[i].ulPropTag != PR_OBJECT_TYPE )
  477.     {
  478.         if( PROP_TYPE(lpspva[i].ulPropTag) == PT_ERROR)
  479.             GetString( "MAPIErrors", lpspva[i].Value.err, szBuffer );
  480.         else
  481.             wsprintf(szBuffer,"PR_SUBJECT not available");
  482.     }
  483.     else
  484.         GetString( "MAPIObjTypes", lpspva[i].Value.ul, szBuffer );
  485.     SetDlgItemText(IDT_OBJECT_TYPE1,szBuffer);
  486.     i++;
  487.  
  488.  
  489.     // PR_ACCESS
  490.     if(lpspva[i].ulPropTag != PR_ACCESS )
  491.     {
  492.         if( PROP_TYPE(lpspva[i].ulPropTag) == PT_ERROR)
  493.             GetString( "MAPIErrors", lpspva[i].Value.err, szBuffer );
  494.         else
  495.             wsprintf(szBuffer,"PR_SUBJECT not available");
  496.         SetDlgItemText(IDT_ACCESS1,szBuffer);
  497.     }
  498.     else
  499.     {
  500.         if( (lpspva[i].Value.ul & MAPI_ACCESS_MODIFY) )
  501.             SetDlgItemText(IDT_ACCESS1,"MAPI_ACCESS_MODIFY");
  502.             
  503.         if( (lpspva[i].Value.ul & MAPI_ACCESS_READ) )
  504.             SetDlgItemText(IDT_ACCESS2,"MAPI_ACCESS_READ");
  505.             
  506.         if( (lpspva[i].Value.ul & MAPI_ACCESS_DELETE) )
  507.             SetDlgItemText(IDT_ACCESS3,"MAPI_ACCESS_DELETE");
  508.             
  509.         if( (lpspva[i].Value.ul & MAPI_ACCESS_CREATE_HIERARCHY) )        
  510.             SetDlgItemText(IDT_ACCESS4,"MAPI_ACCESS_CREATE_HIERARCHY");
  511.             
  512.         if( (lpspva[i].Value.ul & MAPI_ACCESS_CREATE_CONTENTS) )
  513.             SetDlgItemText(IDT_ACCESS5,"MAPI_ACCESS_CREATE_CONTENTS");
  514.             
  515.         if( (lpspva[i].Value.ul & MAPI_ACCESS_CREATE_ASSOCIATED) )
  516.             SetDlgItemText(IDT_ACCESS6,"MAPI_ACCESS_CREATE_ASSOCIATED");
  517.     }
  518.     i++;
  519.  
  520.     // PR_ACCESS_LEVEL
  521.     if(lpspva[i].ulPropTag != PR_ACCESS_LEVEL )
  522.     {
  523.         if( PROP_TYPE(lpspva[i].ulPropTag) == PT_ERROR)
  524.             GetString( "MAPIErrors", lpspva[i].Value.err, szBuffer );
  525.         else
  526.             wsprintf(szBuffer,"PR_SUBJECT not available");
  527.     }
  528.     else
  529.     {
  530.         if(lpspva[i].Value.ul == MAPI_MODIFY )
  531.             wsprintf(szBuffer,"MAPI_MODIFY");
  532.         else
  533.             wsprintf(szBuffer,"Read Only");
  534.     }            
  535.     SetDlgItemText(IDT_ACCESS_LEVEL1,szBuffer);
  536.     i++;
  537.  
  538.  
  539.     MAPIFreeBuffer(lpspva);
  540.  
  541.     return TRUE;
  542. }
  543.  
  544.  
  545. /*******************************************************************/
  546. /*
  547.  -  CAttachSpecialDlg::
  548.  -  ~CAttachSpecialDlg
  549.  -
  550.  *  Purpose:
  551.  *      Destructor for class CAttachSpecialDlg. Releases and Frees memory
  552.  *      allocated in this class
  553.  *
  554.  */
  555. /*******************************************************************/
  556.  
  557. CAttachSpecialDlg::~CAttachSpecialDlg()
  558. {
  559.  
  560. }
  561.  
  562.  
  563. /*******************************************************************/
  564. /*
  565.  -  CAttachSpecialDlg::
  566.  -  OnCancel
  567.  -
  568.  *  Purpose:
  569.  *
  570.  */
  571. /*******************************************************************/
  572.  
  573. void CAttachSpecialDlg::OnCancel()
  574. {
  575.     EndDialog(IDCANCEL);
  576. }
  577.  
  578.           
  579.