home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / addins / autobld / config.cpp < prev    next >
C/C++ Source or Header  |  1998-04-02  |  8KB  |  245 lines

  1. // Config.cpp : implementation file
  2. //
  3.  
  4. // Copyright (C) 1992-1998 Microsoft Corporation
  5. // All rights reserved.
  6.  
  7. #include "stdafx.h"
  8. #include "AutoBld.h"
  9. #include "Config.h"
  10. #include "Workspcs.h"
  11.  
  12. #ifdef _DEBUG
  13. #define new DEBUG_NEW
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CConfigure dialog
  20.  
  21.  
  22. CConfigure::CConfigure(CWnd* pParent /*=NULL*/)
  23.     : CDialog(CConfigure::IDD, pParent)
  24. {
  25.     //{{AFX_DATA_INIT(CConfigure)
  26.         // NOTE: the ClassWizard will add member initialization here
  27.     //}}AFX_DATA_INIT
  28. }
  29.  
  30.  
  31. void CConfigure::DoDataExchange(CDataExchange* pDX)
  32. {
  33.     CDialog::DoDataExchange(pDX);
  34.     //{{AFX_DATA_MAP(CConfigure)
  35.     DDX_Control(pDX, IDC_STATUSWARNERR, m_StatusWarnErr);
  36.     DDX_Control(pDX, IDC_STATUSTEXT, m_StatusText);
  37.     DDX_Control(pDX, IDC_STATUSLINE, m_StatusLine);
  38.     DDX_Control(pDX, IDC_SENDTO, m_SendTo);
  39.     DDX_Control(pDX, IDC_SENDTEXT, m_SendText);
  40.     DDX_Control(pDX, IDC_SENDMAIL, m_SendMail);
  41.     DDX_Control(pDX, IDC_SENDGROUP, m_SendGroup);
  42.     DDX_Control(pDX, IDC_FILENAMETEXT, m_FileName);
  43.     DDX_Control(pDX, IDC_CLOSEWHENDONE, m_CloseWhenDone);
  44.     DDX_Control(pDX, IDC_BROWSE, m_Browse);
  45.     DDX_Control(pDX, IDC_BODYGROUP, m_BodyGroup);
  46.     DDX_Control(pDX, IDC_BODYFILENAME, m_BodyFileName);
  47.     //}}AFX_DATA_MAP
  48. }
  49.  
  50.  
  51. BEGIN_MESSAGE_MAP(CConfigure, CDialog)
  52.     //{{AFX_MSG_MAP(CConfigure)
  53.     ON_BN_CLICKED(IDC_WORKSPACES, OnWorkspaces)
  54.     ON_BN_CLICKED(IDC_BROWSE, OnBrowse)
  55.     ON_BN_CLICKED(IDC_SENDFILEASBODY, OnSendFileAsBody)
  56.     ON_BN_CLICKED(IDC_BLANKBODY, OnBlankBody)
  57.     ON_BN_CLICKED(IDC_SENDMAIL, OnSendMail)
  58.     //}}AFX_MSG_MAP
  59. END_MESSAGE_MAP()
  60.  
  61. /////////////////////////////////////////////////////////////////////////////
  62. // CConfigure message handlers
  63.  
  64. void CConfigure::OnWorkspaces()
  65. {
  66.     //The user wishes to configure which workspaces should be built.
  67.     CWorkspaces Workspaces;
  68.     Workspaces.DoModal();
  69. }
  70.  
  71. void CConfigure::OnBrowse()
  72. {
  73.     //The user wants to browse for a file to send as the message body
  74.     CString strFileSpec;
  75.     strFileSpec.LoadString(IDS_TEXTFILES);
  76.     CFileDialog Browser(TRUE, "", "", OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
  77.             strFileSpec);
  78.     if (Browser.DoModal() == IDOK)
  79.     {
  80.         m_strFileToSend = Browser.GetPathName();
  81.         m_BodyFileName.SetWindowText(m_strFileToSend);
  82.     }
  83. }
  84.  
  85. void CConfigure::OnSendFileAsBody()
  86. {
  87.     //If the user does want to send a file as the message body,
  88.     //then enable the file name edit box.
  89.     m_FileName.EnableWindow(TRUE);
  90.     m_BodyFileName.EnableWindow(TRUE);
  91.     m_Browse.EnableWindow(TRUE);
  92. }
  93.  
  94. void CConfigure::OnBlankBody()
  95. {
  96.     //If the user does not want to send a file as the message body,
  97.     //then disable the file name edit box.
  98.     m_FileName.EnableWindow(FALSE);
  99.     m_BodyFileName.EnableWindow(FALSE);
  100.     m_Browse.EnableWindow(FALSE);
  101. }
  102.  
  103. void CConfigure::OnSendMail()
  104. {
  105.     m_bSendMail = (m_SendMail.GetCheck() == 1) ? TRUE : FALSE;
  106.     m_StatusWarnErr.EnableWindow(m_bSendMail);
  107.     m_StatusText.EnableWindow(m_bSendMail);
  108.     m_StatusLine.EnableWindow(m_bSendMail);
  109.     m_BodyFileName.EnableWindow(m_bSendMail);
  110.     m_BodyGroup.EnableWindow(m_bSendMail);
  111.     m_Browse.EnableWindow(m_bSendMail);
  112.     m_SendGroup.EnableWindow(m_bSendMail);
  113.     m_SendTo.EnableWindow(m_bSendMail);
  114.     m_SendText.EnableWindow(m_bSendMail);
  115.     ((CButton*)GetDlgItem(IDC_EVERYCONFIG))->EnableWindow(m_bSendMail);
  116.     ((CButton*)GetDlgItem(IDC_ENTIREWORKSPACE))->EnableWindow(m_bSendMail);
  117.     ((CButton*)GetDlgItem(IDC_SENDFILEASBODY))->EnableWindow(m_bSendMail);
  118.     ((CButton*)GetDlgItem(IDC_BLANKBODY))->EnableWindow(m_bSendMail);
  119.     ((CButton*)GetDlgItem(IDC_FILENAMETEXT))->EnableWindow(m_bSendMail);
  120.     if (m_bSendFile == TRUE)
  121.     {
  122.         ((CButton*)GetDlgItem(IDC_SENDFILEASBODY))->SetCheck(1);
  123.         m_FileName.EnableWindow(TRUE);
  124.         m_BodyFileName.EnableWindow(TRUE);
  125.         m_Browse.EnableWindow(TRUE);
  126.     }
  127.     else
  128.     {
  129.         ((CButton*)GetDlgItem(IDC_BLANKBODY))->SetCheck(1);
  130.         m_FileName.EnableWindow(FALSE);
  131.         m_BodyFileName.EnableWindow(FALSE);
  132.         m_Browse.EnableWindow(FALSE);
  133.     }
  134. }
  135.  
  136. void CConfigure::OnOK()
  137. {
  138.     // save this little flag for always.
  139.     AfxGetApp()->WriteProfileInt(_T("Configure"), _T("SendMail"), m_bSendMail);
  140.  
  141.     m_SendTo.GetWindowText(m_strSendTo);
  142.  
  143.     if (m_SendMail.GetCheck() == 1)
  144.     {
  145.         if (m_strSendTo == _T(""))
  146.             AfxMessageBox(IDS_NEEDMAILADDR);
  147.         else
  148.         {
  149.             //Prepare to write data to the registry by checking the appropriate
  150.             //  control to see what should be saved.
  151.             m_StatusLine.GetWindowText(m_strStatusLine);
  152.             m_bIncBuildResults = (m_StatusWarnErr.GetCheck() == 1) ? TRUE : FALSE;
  153.             m_bSendMail = (m_SendMail.GetCheck() == 1) ? TRUE : FALSE;
  154.             m_bMailOnEach = (((CButton*)GetDlgItem(IDC_EVERYCONFIG))->GetCheck()
  155.                         == 1) ? TRUE : FALSE;
  156.             m_bSendFile = (((CButton*)GetDlgItem(IDC_SENDFILEASBODY))->GetCheck()
  157.                         == 1) ? TRUE : FALSE;
  158.             m_bCloseWhenDone = (m_CloseWhenDone.GetCheck() == 1) ? TRUE : FALSE;
  159.  
  160.             //Here the data for general configuration of AutoBuild is saved
  161.             //  for later use...
  162.             AfxGetApp()->WriteProfileString(_T("Configure"), _T("SendTo"),
  163.                         m_strSendTo);
  164.             AfxGetApp()->WriteProfileString(
  165.                         _T("Configure"), _T("StatusText"), m_strStatusLine);
  166.             AfxGetApp()->WriteProfileInt(
  167.                         _T("Configure"), _T("MailOnEach"), m_bMailOnEach);
  168.             AfxGetApp()->WriteProfileInt(
  169.                         _T("Configure"), _T("SendMail"), m_bSendMail);
  170.             AfxGetApp()->WriteProfileInt(
  171.                         _T("Configure"), _T("IncludeBuildResults"),
  172.                         m_bIncBuildResults);
  173.             AfxGetApp()->WriteProfileInt(
  174.                         _T("Configure"), _T("SendFile"), m_bSendFile);
  175.             AfxGetApp()->WriteProfileInt(
  176.                         _T("Configure"), _T("CloseWhenDone"), m_bCloseWhenDone);
  177.             AfxGetApp()->WriteProfileString(
  178.                         _T("Configure"), _T("FileToSend"), m_strFileToSend);
  179.  
  180.  
  181.             CDialog::OnOK();
  182.         }
  183.     }
  184.     else
  185.         CDialog::OnOK();
  186. }
  187.  
  188. BOOL CConfigure::OnInitDialog()
  189. {
  190.     CDialog::OnInitDialog();
  191.  
  192.     //This method checks for existing data values, and enables/disables
  193.     //controls based on the corresponding value
  194.     m_SendMail.SetCheck(m_bSendMail);
  195.     if (m_bIncBuildResults == TRUE)
  196.         m_StatusWarnErr.SetCheck(1);
  197.     else
  198.         m_StatusWarnErr.SetCheck(0);
  199.  
  200.     if (m_bMailOnEach == TRUE)
  201.         ((CButton*)GetDlgItem(IDC_EVERYCONFIG))->SetCheck(1);
  202.     else
  203.         ((CButton*)GetDlgItem(IDC_ENTIREWORKSPACE))->SetCheck(1);
  204.  
  205.     ((CButton*)GetDlgItem(IDC_CLOSEWHENDONE))->SetCheck(m_bCloseWhenDone);
  206.  
  207.     m_BodyFileName.SetWindowText(m_strFileToSend);
  208.     if (m_bSendFile == TRUE)
  209.     {
  210.         ((CButton*)GetDlgItem(IDC_SENDFILEASBODY))->SetCheck(1);
  211.         m_FileName.EnableWindow(TRUE);
  212.         m_BodyFileName.EnableWindow(TRUE);
  213.         m_Browse.EnableWindow(TRUE);
  214.     }
  215.     else
  216.     {
  217.         ((CButton*)GetDlgItem(IDC_BLANKBODY))->SetCheck(1);
  218.         m_FileName.EnableWindow(FALSE);
  219.         m_BodyFileName.EnableWindow(FALSE);
  220.         m_Browse.EnableWindow(FALSE);
  221.     }
  222.  
  223.     m_SendTo.SetWindowText(m_strSendTo);
  224.     m_StatusLine.SetWindowText(m_strStatusLine);
  225.  
  226.     //This tangled mess is just a bunch of enabling/disabling windows,
  227.     //setting up stored values, etc.
  228.     m_StatusWarnErr.EnableWindow(m_bSendMail);
  229.     m_StatusText.EnableWindow(m_bSendMail);
  230.     m_StatusLine.EnableWindow(m_bSendMail);
  231.  
  232.     m_BodyGroup.EnableWindow(m_bSendMail);
  233.     m_SendGroup.EnableWindow(m_bSendMail);
  234.     m_SendTo.EnableWindow(m_bSendMail);
  235.     m_SendText.EnableWindow(m_bSendMail);
  236.     ((CButton*)GetDlgItem(IDC_EVERYCONFIG))->EnableWindow(m_bSendMail);
  237.     ((CButton*)GetDlgItem(IDC_ENTIREWORKSPACE))->EnableWindow(m_bSendMail);
  238.     ((CButton*)GetDlgItem(IDC_SENDFILEASBODY))->EnableWindow(m_bSendMail);
  239.     ((CButton*)GetDlgItem(IDC_BLANKBODY))->EnableWindow(m_bSendMail);
  240.     ((CButton*)GetDlgItem(IDC_FILENAMETEXT))->EnableWindow(m_bSendMail);
  241.     m_SendTo.SetWindowText(m_strSendTo);
  242.     return TRUE;  // return TRUE unless you set the focus to a control
  243.                   // EXCEPTION: OCX Property Pages should return FALSE
  244. }
  245.