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

  1. // DlgFile.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "bldrec.h"
  6. #include "DlgFile.h"
  7. #include <afxdlgs.h>
  8.  
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14.  
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CDlgFile dialog
  17.  
  18.  
  19. CDlgFile::CDlgFile(CWnd* pParent /*=NULL*/)
  20.     : CDialog(CDlgFile::IDD, pParent)
  21. {
  22.     //{{AFX_DATA_INIT(CDlgFile)
  23.     m_strFile = _T("");
  24.     //}}AFX_DATA_INIT
  25. }
  26.  
  27.  
  28. void CDlgFile::DoDataExchange(CDataExchange* pDX)
  29. {
  30.     CDialog::DoDataExchange(pDX);
  31.     //{{AFX_DATA_MAP(CDlgFile)
  32.     DDX_Control(pDX, IDC_EDITFILE, m_ctlEditFile);
  33.     DDX_Text(pDX, IDC_EDITFILE, m_strFile);
  34.     //}}AFX_DATA_MAP
  35. }
  36.  
  37.  
  38. BEGIN_MESSAGE_MAP(CDlgFile, CDialog)
  39.     //{{AFX_MSG_MAP(CDlgFile)
  40.     ON_BN_CLICKED(IDC_BUTTONBROWSE, OnButtonbrowse)
  41.     //}}AFX_MSG_MAP
  42. END_MESSAGE_MAP()
  43.  
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CDlgFile message handlers
  46.  
  47. CString& CDlgFile::GetFile()
  48. {
  49.     return(m_strFile);
  50. }
  51.  
  52. void CDlgFile::OnOK() 
  53. {
  54.     if (m_strFile.ReverseFind(_T('.')) < 0)
  55.     {
  56.         m_strFile += _T(".txt");
  57.     }
  58.     CDialog::OnOK();
  59. }
  60.  
  61. void CDlgFile::SetFile(LPCTSTR szFile)
  62. {
  63.     m_strFile = szFile;
  64. }
  65.  
  66. BOOL CDlgFile::OnInitDialog() 
  67. {
  68.     CDialog::OnInitDialog();
  69.     
  70.     UpdateData(FALSE);    
  71.     return TRUE;  // return TRUE unless you set the focus to a control
  72.                   // EXCEPTION: OCX Property Pages should return FALSE
  73. }
  74.  
  75. void CDlgFile::OnButtonbrowse() 
  76. {
  77.     CString strFilter, strExt;
  78.     strFilter.LoadString(IDS_TXTFILTER);
  79.     CFileDialog dlgGetFile(FALSE, NULL, NULL, OFN_EXPLORER,
  80.         strFilter,
  81.         this);
  82.     
  83.     if (dlgGetFile.DoModal() == IDOK)
  84.     {
  85.         m_strFile = dlgGetFile.GetPathName();
  86.         if (m_strFile.ReverseFind(_T('.')) < 0)
  87.         {
  88.             strExt.LoadString(IDS_DEFAULT_EXTENSION);
  89.             m_strFile += strExt;
  90.         }
  91.         m_ctlEditFile.SetWindowText(m_strFile);
  92.     }
  93. }
  94.