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

  1. /*******************************************************************/
  2. /*
  3.  -  oper.cpp
  4.  -  Copyright (C) 1995 Microsoft Corporation
  5.  -
  6.  *  Purpose:
  7.  *      Contains member functions for COperation.
  8.  *      This class is used to bring up a dialog from which the 
  9.  *      user can select data to be used as parameters to operations.
  10.  *      Not all the dialog controls are used in every case.
  11.  */
  12. /*******************************************************************/
  13.                                                    
  14. #undef  CINTERFACE      // C++ calling convention for mapi calls
  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 <windowsx.h>
  26. #include <string.h>
  27.  
  28. #ifdef WIN16
  29. #include <compobj.h>
  30. #endif
  31.  
  32. #ifdef WIN32
  33. #include <objbase.h>
  34. #include <objerror.h>
  35. #ifdef _WIN95
  36. #include <ole2.h>
  37. #endif
  38. #endif
  39.  
  40. #ifdef WIN16
  41. #include <mapiwin.h>    
  42. #endif
  43. #include <mapix.h>      
  44. #include <strtbl.h>     
  45. #include <misctool.h>
  46. #include "resource.h"   
  47. #include "oper.h"
  48.  
  49. /********************************************************************/
  50.  
  51. BEGIN_MESSAGE_MAP(COperation, CModalDialog)
  52.  
  53.     ON_BN_CLICKED(  IDC_OPSFLAG1,       OnFlag1)
  54.     ON_BN_CLICKED(  IDC_OPSFLAG2,       OnFlag2)
  55.     ON_BN_CLICKED(  IDC_OPSFLAG3,       OnFlag3)
  56.     ON_BN_CLICKED(  IDC_OPSFLAG4,       OnFlag4)
  57.     ON_BN_CLICKED(  IDC_OPSFLAG5,       OnFlag5)
  58.     ON_BN_CLICKED(  IDC_OPSFLAG6,       OnFlag6)
  59.          
  60. END_MESSAGE_MAP()
  61.  
  62. /********************************************************************/
  63. /*
  64.  -  COperation::
  65.  -  OnInitDialog
  66.  -
  67.  *  Purpose:
  68.  *      Initialize the dialog text and data in controls
  69.  *      Data members are set prior to calling this function
  70.  *      so that this function merely brings up UI with appropriate
  71.  *      controls reflecting the initialized data members.
  72.  */
  73.  /********************************************************************/
  74.  
  75. BOOL COperation::OnInitDialog()
  76. {
  77.     HRESULT         hResult         = hrSuccess;
  78.     char            szBuff[80];
  79.     DWORD           dwRet           = 0;
  80.     int             dCount          = 0;
  81.     int             idx             = 0;
  82.     CString         szCBElement;
  83.     
  84.     SetWindowText( m_CurrentOperation.GetBuffer(25) );
  85.  
  86.     // describe controls
  87.     SetDlgItemText(IDT_OPSCB1,m_CBText1);
  88.     SetDlgItemText(IDT_OPSCB2,m_CBText2);
  89.     SetDlgItemText(IDT_OPSCB3,m_CBText3);
  90.  
  91.     SetDlgItemText(IDT_OPSEDIT1,m_EditText1);
  92.     SetDlgItemText(IDT_OPSEDIT2,m_EditText2);
  93.     SetDlgItemText(IDT_OPSEDIT3,m_EditText3);
  94.  
  95.     SetDlgItemText(IDC_OPSFLAG1,m_FlagText1);
  96.     SetDlgItemText(IDC_OPSFLAG2,m_FlagText2);
  97.     SetDlgItemText(IDC_OPSFLAG3,m_FlagText3);
  98.     SetDlgItemText(IDC_OPSFLAG4,m_FlagText4);
  99.     SetDlgItemText(IDC_OPSFLAG5,m_FlagText5);
  100.     SetDlgItemText(IDC_OPSFLAG6,m_FlagText6);
  101.  
  102.     // determine which fields are enabled/disabled
  103.     if( !GetDlgItemText(IDT_OPSCB1,szBuff,80) )
  104.     {        
  105.         GetDlgItem(IDC_OPSCB1)->EnableWindow(FALSE);
  106.         GetDlgItem(IDT_OPSCB1)->EnableWindow(FALSE);
  107.     }    
  108.     if( !GetDlgItemText(IDT_OPSCB2,szBuff,80) )
  109.     {
  110.         GetDlgItem(IDC_OPSCB2)->EnableWindow(FALSE);
  111.         GetDlgItem(IDT_OPSCB2)->EnableWindow(FALSE);
  112.     }
  113.     if( !GetDlgItemText(IDT_OPSCB3,szBuff,80) )
  114.     {
  115.         GetDlgItem(IDC_OPSCB3)->EnableWindow(FALSE);
  116.         GetDlgItem(IDT_OPSCB3)->EnableWindow(FALSE);
  117.     }
  118.     if( !GetDlgItemText(IDT_OPSEDIT1,szBuff,80) )
  119.     {
  120.         GetDlgItem(IDC_OPSEDIT1)->EnableWindow(FALSE);
  121.         GetDlgItem(IDT_OPSEDIT1)->EnableWindow(FALSE);
  122.     }
  123.     if( !GetDlgItemText(IDT_OPSEDIT2,szBuff,80) )
  124.     {
  125.         GetDlgItem(IDC_OPSEDIT2)->EnableWindow(FALSE);
  126.         GetDlgItem(IDT_OPSEDIT2)->EnableWindow(FALSE);
  127.     }
  128.     if( !GetDlgItemText(IDT_OPSEDIT3,szBuff,80) )
  129.     {
  130.         GetDlgItem(IDC_OPSEDIT3)->EnableWindow(FALSE);
  131.         GetDlgItem(IDT_OPSEDIT3)->EnableWindow(FALSE);
  132.     }
  133.     
  134.     if( !GetDlgItemText(IDC_OPSFLAG1,szBuff,80) )
  135.         GetDlgItem(IDC_OPSFLAG1)->EnableWindow(FALSE);
  136.     else
  137.         CheckDlgButton(IDC_OPSFLAG1,    0);
  138.         
  139.     if( !GetDlgItemText(IDC_OPSFLAG2,szBuff,80) )
  140.         GetDlgItem(IDC_OPSFLAG2)->EnableWindow(FALSE);
  141.     else
  142.         CheckDlgButton(IDC_OPSFLAG2,    0);
  143.  
  144.     if( !GetDlgItemText(IDC_OPSFLAG3,szBuff,80) )
  145.         GetDlgItem(IDC_OPSFLAG3)->EnableWindow(FALSE);
  146.     else
  147.         CheckDlgButton(IDC_OPSFLAG3,    0);
  148.  
  149.     if( !GetDlgItemText(IDC_OPSFLAG4,szBuff,80) )
  150.         GetDlgItem(IDC_OPSFLAG4)->EnableWindow(FALSE);    
  151.     else
  152.         CheckDlgButton(IDC_OPSFLAG4,    0);
  153.  
  154.     if( !GetDlgItemText(IDC_OPSFLAG5,szBuff,80) )
  155.         GetDlgItem(IDC_OPSFLAG5)->EnableWindow(FALSE);    
  156.     else
  157.         CheckDlgButton(IDC_OPSFLAG5,    0);
  158.  
  159.     if( !GetDlgItemText(IDC_OPSFLAG6,szBuff,80) )
  160.         GetDlgItem(IDC_OPSFLAG6)->EnableWindow(FALSE);    
  161.     else
  162.         CheckDlgButton(IDC_OPSFLAG6,    0);
  163.     
  164.  
  165.     // initialize data inside Combo boxes  
  166.     if(dCount = m_CBContents1.GetSize() )
  167.     {
  168.         for( idx = 0 ; idx < dCount ; idx++)
  169.         {
  170.             szCBElement = m_CBContents1.GetAt(idx);
  171.             dwRet = SendDlgItemMessage(IDC_OPSCB1, CB_ADDSTRING,0 ,(LPARAM)szCBElement.GetBuffer(10) );
  172.         }        
  173.         dwRet = SendDlgItemMessage(IDC_OPSCB1, CB_SETCURSEL,0 ,0 );       
  174.     }
  175.  
  176.     if( dCount = m_CBContents2.GetSize() )
  177.     {
  178.         for( idx = 0 ; idx < dCount ; idx++)
  179.         {
  180.             szCBElement = m_CBContents2.GetAt(idx);
  181.             dwRet = SendDlgItemMessage(IDC_OPSCB2, CB_ADDSTRING,0 ,(LPARAM)szCBElement.GetBuffer(10) );
  182.         }        
  183.         dwRet = SendDlgItemMessage(IDC_OPSCB2, CB_SETCURSEL,0 ,0 );       
  184.     }
  185.  
  186.     if( dCount = m_CBContents3.GetSize() )
  187.     {
  188.         for( idx = 0 ; idx < dCount ; idx++)
  189.         {
  190.             szCBElement = m_CBContents3.GetAt(idx);
  191.             dwRet = SendDlgItemMessage(IDC_OPSCB3, CB_ADDSTRING,0 ,(LPARAM)szCBElement.GetBuffer(10) );
  192.         }        
  193.         dwRet = SendDlgItemMessage(IDC_OPSCB3, CB_SETCURSEL,0 ,0 );       
  194.     }
  195.  
  196.     // initialize data in edit controls 
  197.     SetDlgItemText(IDC_OPSEDIT1,m_EditDefault1);
  198.     SetDlgItemText(IDC_OPSEDIT2,m_EditDefault2);
  199.     SetDlgItemText(IDC_OPSEDIT3,m_EditDefault3);
  200.  
  201.     return TRUE;
  202. }
  203.  
  204. /*******************************************************************/
  205. /*
  206.  -  COperation::
  207.  -  OnOK
  208.  -
  209.  *  Purpose:
  210.  *      Take data in edit controls, comboboxes, and flags and
  211.  *      put in format to be passed back to the calling function
  212.  *      i.e. put in strings and boolean flags
  213.  *  
  214.  */
  215. /*******************************************************************/
  216.  
  217. void COperation::OnOK()
  218. {
  219.     LONG    lCurSelect      = 0;
  220.     LONG    dRet            = 0;
  221.  
  222.     // get combo box selection and put in data member strings
  223.     lCurSelect = SendDlgItemMessage(IDC_OPSCB1,CB_GETCURSEL,0,0);
  224.     dRet = SendDlgItemMessage(IDC_OPSCB1,CB_GETLBTEXT,(WPARAM)lCurSelect,(LPARAM)m_szCB1);
  225.     m_szCB1[dRet] = '\0';
  226.  
  227.     lCurSelect = SendDlgItemMessage(IDC_OPSCB2,CB_GETCURSEL,0,0);
  228.     dRet = SendDlgItemMessage(IDC_OPSCB2,CB_GETLBTEXT,(WPARAM)lCurSelect,(LPARAM)m_szCB2);
  229.     m_szCB2[dRet] = '\0';
  230.  
  231.     lCurSelect = SendDlgItemMessage(IDC_OPSCB3,CB_GETCURSEL,0,0);
  232.     dRet = SendDlgItemMessage(IDC_OPSCB3,CB_GETLBTEXT,(WPARAM)lCurSelect,(LPARAM)m_szCB3);
  233.     m_szCB3[dRet] = '\0';
  234.  
  235.     // get edit control selection and put in data member strings
  236.     *(WORD *)m_szEdit1 = sizeof(m_szEdit1) -1;    // first char has buffer length   
  237.     dRet = SendDlgItemMessage(IDC_OPSEDIT1,EM_GETLINE,0,(LPARAM)m_szEdit1);
  238.     m_szEdit1[dRet] = '\0';
  239.  
  240.     *(WORD *)m_szEdit2 = sizeof(m_szEdit2) -1;    // first char has buffer length   
  241.     dRet = SendDlgItemMessage(IDC_OPSEDIT2,EM_GETLINE,0,(LPARAM)m_szEdit2);
  242.     m_szEdit2[dRet] = '\0';
  243.  
  244.     *(WORD *)m_szEdit3 = sizeof(m_szEdit3) -1;    // first char has buffer length   
  245.     dRet = SendDlgItemMessage(IDC_OPSEDIT3,EM_GETLINE,0,(LPARAM)m_szEdit3);
  246.     m_szEdit3[dRet] = '\0';
  247.     
  248.     // get checkbox state and put in boolean data members
  249.     if( IsDlgButtonChecked(IDC_OPSFLAG1) )                
  250.         m_bFlag1 = TRUE;
  251.  
  252.     if( IsDlgButtonChecked(IDC_OPSFLAG2) )                
  253.         m_bFlag2 = TRUE;
  254.  
  255.     if( IsDlgButtonChecked(IDC_OPSFLAG3) )                
  256.         m_bFlag3 = TRUE;
  257.  
  258.     if( IsDlgButtonChecked(IDC_OPSFLAG4) )                
  259.         m_bFlag4 = TRUE;
  260.  
  261.     if( IsDlgButtonChecked(IDC_OPSFLAG5) )                
  262.         m_bFlag5 = TRUE;
  263.  
  264.     if( IsDlgButtonChecked(IDC_OPSFLAG6) )                
  265.         m_bFlag6 = TRUE;
  266.  
  267.     EndDialog(IDOK);
  268. }
  269.  
  270. /*******************************************************************/
  271. /*
  272.  -  COperation::
  273.  -  OnCancel
  274.  -
  275.  *  Purpose:
  276.  *      Closes the Table viewer dialog.
  277.  *
  278.  */
  279. /*******************************************************************/
  280.  
  281. void COperation::OnCancel()
  282. {
  283.     EndDialog(IDCANCEL);
  284. }
  285.  
  286. /*******************************************************************/
  287. /*
  288.  -  COperation::
  289.  -  OnFlag*
  290.  -
  291.  *  Purpose:
  292.  *      Toggles the state of the flag check
  293.  *
  294.  */
  295. /*******************************************************************/
  296.  
  297. void COperation::OnFlag1()
  298. {   
  299.     CheckDlgButton(IDC_OPSFLAG1, !IsDlgButtonChecked(IDC_OPSFLAG1) );
  300. }
  301.  
  302. void COperation::OnFlag2()
  303. {   
  304.     CheckDlgButton(IDC_OPSFLAG2, !IsDlgButtonChecked(IDC_OPSFLAG2) );
  305. }
  306.  
  307. void COperation::OnFlag3()
  308. {   
  309.     CheckDlgButton(IDC_OPSFLAG3, !IsDlgButtonChecked(IDC_OPSFLAG3) );
  310. }
  311.  
  312. void COperation::OnFlag4()
  313. {
  314.     CheckDlgButton(IDC_OPSFLAG4, !IsDlgButtonChecked(IDC_OPSFLAG4) );
  315. }
  316. void COperation::OnFlag5()
  317. {
  318.     CheckDlgButton(IDC_OPSFLAG5, !IsDlgButtonChecked(IDC_OPSFLAG5) );
  319. }
  320. void COperation::OnFlag6()
  321. {
  322.     CheckDlgButton(IDC_OPSFLAG6, !IsDlgButtonChecked(IDC_OPSFLAG6) );
  323. }
  324.  
  325.  
  326.