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