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

  1. /*******************************************************************/
  2. /*
  3.  -  getprop.cpp
  4.  -  Copyright (C) 1995 Microsoft Corporation
  5.  -
  6.  *  Purpose:
  7.  *      Contains member functions for CGetPropDlg
  8.  */
  9. /*******************************************************************/
  10.                                                    
  11. #undef  CINTERFACE      // C++ calling convention for mapi calls
  12.  
  13. #ifdef WIN32
  14. #ifdef _WIN95
  15. #define _INC_OLE
  16. #endif
  17. #define INC_OLE2
  18. #define INC_RPC
  19. #endif
  20.  
  21. #include <afxwin.h>     
  22. #include <windowsx.h>
  23. #include <string.h>
  24.  
  25. #ifdef WIN16
  26. #include <compobj.h>
  27. #endif
  28.  
  29. #ifdef WIN32
  30. #include <objbase.h>
  31. #include <objerror.h>
  32. #ifdef _WIN95
  33. #include <ole2.h>
  34. #endif
  35. #endif
  36.  
  37.  
  38. #ifdef WIN16
  39. #include <mapiwin.h>    
  40. #endif
  41. #include <mapix.h>      
  42. #include <strtbl.h>     
  43. #include <misctool.h>
  44. #include "resource.h"   
  45. #include "propvu.h"  
  46. #include "getprop.h"
  47.  
  48. /*******************************************************************/
  49. /**************************** GETPROPS *****************************/
  50.  
  51. /******************* Set Property Message Map *********************/
  52.  
  53. BEGIN_MESSAGE_MAP(CGetPropDlg, CModalDialog)
  54.  
  55.     ON_COMMAND(         IDC_STOREPROPS,     OnDumpPropValsToFile)
  56.     ON_COMMAND(         IDC_STORETAGS,      OnDumpPropTagsToFile)
  57.              
  58. END_MESSAGE_MAP()
  59.  
  60. /********************************************************************/
  61. /*
  62.  -  CGetPropDlg::
  63.  -  OnInitDialog
  64.  -
  65.  *  Purpose:
  66.  *
  67.  */
  68. /********************************************************************/
  69.  
  70. BOOL CGetPropDlg::OnInitDialog()
  71. {
  72.     HRESULT         hResult         = hrSuccess;
  73.     CGetError       E;
  74.         
  75.     SetWindowText( "lpObj->GetProps()" );
  76.  
  77.     SendDlgItemMessage(IDC_GP_EXPPROPTAGS,LB_RESETCONTENT,0,0);
  78.     SendDlgItemMessage(IDC_GP_ACTPROPTAGS,LB_RESETCONTENT,0,0);
  79.  
  80.  
  81.     if( (!m_lpPTA)  || (!m_lpPVA) || (!m_cValues))
  82.     {
  83.         MessageBox( "CGetPropDlg::OnInitDialog   (lpsPTA == NULL) || (m_lpPVA == NULL) || (m_cValues == 0)",
  84.                     "Client", MBS_ERROR );
  85.         goto error;
  86.     }           
  87.     if((m_cValues) && (m_lpPVA != NULL))
  88.         DisplayProps();
  89.     else
  90.         goto error;
  91.  
  92.     return TRUE;    
  93.  
  94. error:
  95.  
  96.     if(m_lpPVA)
  97.     {
  98.         MAPIFreeBuffer(m_lpPVA);
  99.         m_lpPVA         = NULL;
  100.         m_cValues       = 0;
  101.     }
  102.     
  103.     return FALSE;
  104. }
  105.  
  106.  
  107.  
  108. /*******************************************************************/
  109. /*
  110.  -  CBldPropDlg::
  111.  -  DisplayProps
  112.  *
  113.  *  Purpose:
  114.  *
  115.  *  Parameters:
  116.  *
  117.  *  Returns:
  118.  *
  119.  */
  120. /*******************************************************************/
  121.  
  122. void CGetPropDlg::DisplayProps()
  123. {
  124.     char            szBuffer[1024];
  125.     int             idx             = 0;
  126.     int             rgTabStops[4];
  127.     DWORD           dwReturn        = 0;      
  128.     char            szExpectedCVals[30];
  129.     char            szActualCVals[30];
  130.  
  131.  
  132.     // multi value props stuff    
  133.     char            szMV[1024];    
  134.     char            szMVSeps[]      = ";:.";
  135.     char            *lpszToken      = NULL;
  136.     char            szTemp[30];
  137.     ULONG           ulMVRow         = 0;
  138.     ULONG           ulMVcValues     = 0;
  139.     char            *szEnd          = NULL;
  140.  
  141.  
  142.     char szID[50];
  143.     char szData[512];
  144.     char szType[32];      // Assumes no PropType string longer than 31 chars
  145.  
  146.         
  147.     // DISPLAY Expected lpPTA->cValues
  148.     wsprintf(szExpectedCVals,"cValues:  %lu",m_lpPTA->cValues);
  149.     SetDlgItemText(IDT_GP_EXPCVALUES,szExpectedCVals);
  150.  
  151.     szBuffer[0] = '\0' ;
  152.  
  153.     SendDlgItemMessage(IDC_GP_EXPPROPTAGS,LB_RESETCONTENT,0,0);
  154.  
  155.     // load properties into listbox
  156.     dwReturn = SendDlgItemMessage(IDC_GP_EXPPROPTAGS,LB_SETHORIZONTALEXTENT,
  157.                     (WPARAM) PROP_LISTBOX_HORIZONTAL_SIZE ,0 );
  158.  
  159.     rgTabStops[0] = PROP_LISTBOX_TAB1_SIZE ;
  160.     rgTabStops[1] = PROP_LISTBOX_TAB2_SIZE ;
  161.  
  162.     dwReturn = SendDlgItemMessage(IDC_GP_EXPPROPTAGS,LB_SETTABSTOPS,
  163.                     (WPARAM) 2,(LPARAM)rgTabStops );
  164.     
  165.     // DISPLAY Expected PropTagArray
  166.     for(idx = 0; idx < m_lpPTA->cValues; idx++)
  167.     {   
  168.         szID[0]     = '\0' ;
  169.         szType[0]   = '\0' ;
  170.         szBuffer[0] = '\0' ;
  171.             
  172.         if(GetString("PropIDs", PROP_ID(m_lpPTA->aulPropTag[idx]), szID ) )
  173.         {
  174.             lstrcat(szBuffer, szID );               
  175.             lstrcat(szBuffer, "\t");
  176.         }
  177.         else
  178.         {
  179.             wsprintf(szBuffer,"%#04X\t", PROP_ID(m_lpPTA->aulPropTag[idx]) );       
  180.         }
  181.  
  182.         if( GetString("PropType", PROP_TYPE(m_lpPTA->aulPropTag[idx]), szType) )
  183.         {
  184.             lstrcat(szBuffer, szType);
  185.             lstrcat(szBuffer,"\t");
  186.         }       
  187.         else
  188.         {
  189.             wsprintf(szType,"%#04X\t", PROP_TYPE(m_lpPTA->aulPropTag[idx]) );
  190.             lstrcat(szBuffer,szType);
  191.         }
  192.         dwReturn = SendDlgItemMessage(IDC_GP_EXPPROPTAGS,LB_ADDSTRING,0,
  193.                             (LPARAM)szBuffer);
  194.     
  195.     }  
  196.    
  197.     // DISPLAY Actual m_cValues
  198.     wsprintf(szActualCVals,"cValues:  %lu",m_cValues);
  199.     SetDlgItemText(IDT_GP_ACTCVALUES,szActualCVals);
  200.     
  201.     // DISPLAY PropValue Array
  202.     szBuffer[0] = '\0' ;
  203.  
  204.     SendDlgItemMessage(IDC_GP_ACTPROPTAGS,LB_RESETCONTENT,0,0);
  205.  
  206.     // load properties into listbox
  207.     dwReturn = SendDlgItemMessage(IDC_GP_ACTPROPTAGS,LB_SETHORIZONTALEXTENT,
  208.                     (WPARAM) PROP_LISTBOX_HORIZONTAL_SIZE ,0 );
  209.  
  210.     rgTabStops[0] = PROP_LISTBOX_TAB1_SIZE ;
  211.     rgTabStops[1] = PROP_LISTBOX_TAB2_SIZE ;
  212.  
  213.     dwReturn = SendDlgItemMessage(IDC_GP_ACTPROPTAGS,LB_SETTABSTOPS,
  214.                     (WPARAM) 2,(LPARAM)rgTabStops );
  215.     
  216.  
  217.     for(idx = 0; idx < m_cValues; idx++)
  218.     {   
  219.         szID[0]     = '\0' ;
  220.         szData[0]   = '\0' ;
  221.         szType[0]   = '\0' ;
  222.         szBuffer[0] = '\0' ;
  223.             
  224.         if(GetString("PropIDs", PROP_ID(m_lpPVA[idx].ulPropTag), szID ) )
  225.         {
  226.             lstrcat(szBuffer, szID );               
  227.             lstrcat(szBuffer, "\t");
  228.         }
  229.         else
  230.         {
  231.             wsprintf(szBuffer,"%#04X\t", PROP_ID(m_lpPVA[idx].ulPropTag) );     
  232.         }
  233.  
  234.         if( GetString("PropType", PROP_TYPE(m_lpPVA[idx].ulPropTag), szType) )
  235.         {
  236.             lstrcat(szBuffer, szType);
  237.             lstrcat(szBuffer,"\t");
  238.         }       
  239.         else
  240.         {
  241.             wsprintf(szType,"%#04X\t", PROP_TYPE(m_lpPVA[idx].ulPropTag) );
  242.             lstrcat(szBuffer,szType);
  243.         }
  244.  
  245.         SzGetPropValue(szData,(LPSPropValue) &m_lpPVA[idx]);
  246.  
  247.         // if it is a MultiValueProperty, parse the output, and add
  248.         //   more than one row for this property
  249.         if( (PROP_TYPE(m_lpPVA[idx].ulPropTag)) & MV_FLAG )
  250.         {
  251.             // it is multi value, so strtok out the data 
  252.             // and add a row for each data value                                                        
  253.             ulMVRow = 0;
  254.  
  255.             // determine number of cValues
  256.             lpszToken   = strtok(szData,szMVSeps);
  257.             ulMVcValues = strtoul(lpszToken,&szEnd,16);        
  258.  
  259.             // rip out first row of multi value prop
  260.             lpszToken = strtok(NULL,szMVSeps);
  261.                             
  262.             // rip out remaining rows                
  263.             while( lpszToken != NULL )
  264.             {
  265.                 lstrcpy(szMV,szBuffer);
  266.                 wsprintf(szTemp,"[%lu] ",ulMVRow);
  267.                 lstrcat(szMV,szTemp);
  268.                 lstrcat(szMV,lpszToken);
  269.             
  270.                 dwReturn = SendDlgItemMessage(IDC_GP_ACTPROPTAGS,LB_ADDSTRING,0,
  271.                         (LPARAM)szMV);
  272.             
  273.                 lpszToken = strtok(NULL,szMVSeps);
  274.                 ulMVRow++;
  275.             }                
  276.             
  277.             // if all the data was not there, fill in the remainder with bogus stub
  278.             while( ulMVRow < ulMVcValues )
  279.             {
  280.                 lstrcpy(szMV,szBuffer);
  281.                 wsprintf(szTemp,"[%lu] ",ulMVRow);
  282.                 lstrcat(szMV,szTemp);
  283.                 lstrcat(szMV,"<No Data Available>");
  284.             
  285.                 dwReturn = SendDlgItemMessage(IDC_GP_ACTPROPTAGS,LB_ADDSTRING,0,
  286.                         (LPARAM)szMV);
  287.                 ulMVRow++;                            
  288.             }
  289.         }
  290.         else            
  291.         {
  292.             lstrcat(szBuffer,szData);
  293.             dwReturn = SendDlgItemMessage(IDC_GP_ACTPROPTAGS,LB_ADDSTRING,0,
  294.                         (LPARAM)szBuffer);
  295.         }
  296.  
  297.     } 
  298.  
  299.     dwReturn = SendDlgItemMessage(IDC_GP_ACTPROPTAGS,LB_SETCURSEL,(WPARAM) -1 ,0 );
  300. }
  301.  
  302.  
  303. /*******************************************************************/
  304. /*
  305.  -  CGetPropDlg::
  306.  -  ~CGetPropDlg
  307.  -
  308.  *  Purpose:
  309.  *      Destructor for class CGetPropDlg. Releases and Frees memory
  310.  *      allocated in this class
  311.  *
  312.  */
  313. /*******************************************************************/
  314.  
  315. CGetPropDlg::~CGetPropDlg()
  316. {
  317.  
  318.  
  319. /*******************************************************************/
  320. /*
  321.  -  CGetPropDlg::
  322.  -  OnDumpPropValsToFile
  323.  *
  324.  *  Purpose:
  325.  *      Store PropValues in object to file
  326.  */
  327. /*******************************************************************/
  328.  
  329. void CGetPropDlg::OnDumpPropValsToFile()
  330. {
  331.     char                szTag[80];
  332.     char                szFileName[80];
  333.     CStorePropValDlg    StoreProp(this);
  334.     LPTSTR              lpszTemp;
  335.         
  336.     // find file to open
  337.     lpszTemp = getenv("MAPITEST");
  338.  
  339.     if(lpszTemp)
  340.         strcpy(szFileName, lpszTemp);
  341.     else
  342.         strcpy(szFileName, "c:\\mapitest");
  343.  
  344.     strcat(szFileName, "\\data\\propvu.txt");
  345.  
  346.     // create the tag with braces around it
  347.     strcpy(szTag,"[PROPVAL00001]");
  348.  
  349.     StoreProp.m_TagID       = szTag;
  350.     StoreProp.m_FileName    = szFileName;
  351.     
  352.     if( StoreProp.DoModal() == IDOK )
  353.     {    
  354.         if((m_cValues != 0) && (m_lpPVA != NULL) )
  355.         {
  356.             WritePropValArray( StoreProp.m_szFileName,
  357.                         StoreProp.m_szTagID,
  358.                         m_cValues,
  359.                         m_lpPVA,
  360.                         StoreProp.m_ulFlags);
  361.         }                        
  362.     }
  363. }
  364.  
  365.  
  366.  
  367. /*******************************************************************/
  368. /*
  369.  -  CGetPropDlg::
  370.  -  OnDumpPropTagsToFile
  371.  *
  372.  *  Purpose:
  373.  *      Store PropValues in object to file
  374.  */
  375. /*******************************************************************/
  376.  
  377. void CGetPropDlg::OnDumpPropTagsToFile()
  378. {
  379.     char                szTag[80];
  380.     char                szFileName[80];
  381.     CStorePropValDlg    StoreProp(this);
  382.     LPTSTR              lpszTemp;
  383.         
  384.     // find file to open
  385.     lpszTemp = getenv("MAPITEST");
  386.  
  387.     if(lpszTemp)
  388.         strcpy(szFileName, lpszTemp);
  389.     else
  390.         strcpy(szFileName, "c:\\mapitest");
  391.  
  392.     strcat(szFileName, "\\data\\propvu.txt");
  393.  
  394.     // create the tag with braces around it
  395.     strcpy(szTag,"[PROPTAG00001]");
  396.  
  397.     StoreProp.m_TagID       = szTag;
  398.     StoreProp.m_FileName    = szFileName;
  399.     
  400.     if( StoreProp.DoModal() == IDOK )
  401.     {    
  402.         // if it is a prop tag array 
  403.         if(m_lpPTA)
  404.         {   
  405.             WritePropTagArray(  StoreProp.m_szFileName,
  406.                             StoreProp.m_szTagID,
  407.                             m_lpPTA);
  408.         }
  409.     }
  410. }
  411.  
  412.