home *** CD-ROM | disk | FTP | other *** search
/ C/C++ User's Journal & Wi…eveloper's Journal Tools / C-C__Users_Journal_and_Windows_Developers_Journal_Tools_1997.iso / stingray / dlgsamp5.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-27  |  3.3 KB  |  136 lines

  1. // dlgsamp5.cpp : implementation file
  2. //
  3.  
  4. // This is a part of the Objective Grid C++ Library.
  5. // Copyright (C) 1995,1996 ClassWorks, Stefan Hoenig.
  6. // All rights reserved.
  7. //
  8. // This source code is only intended as a supplement to
  9. // the Objective Grid Classes Reference and related
  10. // electronic documentation provided with the library.
  11. // See these sources for detailed information regarding
  12. // the Objective Grid product.
  13. //
  14.  
  15. #include "stdafx.h"
  16. #include "gridapp.h"
  17. #include "dlgsamp5.h"
  18.  
  19. #ifndef _GXWND_H_
  20. #include "gxwnd.h"
  21. #endif
  22.  
  23. #ifndef _GXCTRL_H_
  24. #include "gxctrl.h"
  25. #endif
  26.  
  27. #ifdef _DEBUG
  28. #undef THIS_FILE
  29. static char BASED_CODE THIS_FILE[] = __FILE__;
  30. #endif
  31.  
  32. #define new DEBUG_NEW
  33.  
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CSample5Dialog
  36. //
  37. // CSample5Dialog is based on the IDD_DLGSAMP5 dialog template.
  38. // I have dragged an user control into the dialog template and
  39. // set the control class to "GXWnd".
  40. //
  41. // In OnInitDialog I call the SubclassDlgItem member funtion
  42. // which subclasses the CWnd control:
  43. //    m_wndGrid.SubclassDlgItem(IDC_GRIDWND5, this);
  44. //
  45. // After calling SubclassDlgItem, the user control is attached
  46. // to the m_wndGrid member variable. m_wndGrid is an instance
  47. // of the CSample5GridWnd class. OnInitDialog calls the
  48. // Initialize method to initialize the grid.
  49. //
  50. // In DoDataExchange, I have added the line
  51. // DDV_GXGridWnd(pDX, &m_wndGrid);
  52. // which enables control validation in the dialog.
  53.  
  54.  
  55. /////////////////////////////////////////////////////////////////////////////
  56. // CSample5GridWnd grid control
  57.  
  58. // validation routine
  59.  
  60. BOOL CSample5GridWnd::OnValidateCell(ROWCOL nRow, ROWCOL nCol)
  61. {
  62.     CString s;
  63.  
  64.     // retrieve text from current cell
  65.     CGXControl* pControl = GetControl(nRow, nCol);
  66.     pControl->GetCurrentText(s);
  67.  
  68.     if (_ttol(s) < 0 || _ttol(s) > 100)
  69.     {
  70.         SetWarningText(_T("Please enter a value between 0 and 100!"));
  71.         return FALSE;
  72.     }
  73.  
  74.     return TRUE;
  75. }
  76.  
  77. BEGIN_MESSAGE_MAP(CSample5GridWnd, CGXGridWnd)
  78.     //{{AFX_MSG_MAP(CSample5GridWnd)
  79.     //}}AFX_MSG_MAP
  80. END_MESSAGE_MAP()
  81.  
  82. /////////////////////////////////////////////////////////////////////////////
  83. // CSample5Dialog dialog
  84.  
  85. CSample5Dialog::CSample5Dialog(CWnd* pParent /*=NULL*/)
  86.     : CDialog(CSample5Dialog::IDD, pParent)
  87. {
  88.     //{{AFX_DATA_INIT(CSample5Dialog)
  89.     m_nEdit = 0;
  90.     m_nVal2 = 0;
  91.     //}}AFX_DATA_INIT
  92.  
  93.  
  94. }
  95.  
  96. void CSample5Dialog::DoDataExchange(CDataExchange* pDX)
  97. {
  98.     CDialog::DoDataExchange(pDX);
  99.     //{{AFX_DATA_MAP(CSample5Dialog)
  100.     DDX_Text(pDX, IDC_EDIT1, m_nEdit);
  101.     DDV_MinMaxInt(pDX, m_nEdit, 0, 100);
  102.     DDX_Text(pDX, IDC_EDIT2, m_nVal2);
  103.     DDV_MinMaxInt(pDX, m_nVal2, 0, 100);
  104.     //}}AFX_DATA_MAP
  105.  
  106.     // validation routine for CGXGridWnd controls
  107.     DDV_GXGridWnd(pDX, &m_wndGrid);
  108. }
  109.  
  110. BEGIN_MESSAGE_MAP(CSample5Dialog, CDialog)
  111.     //{{AFX_MSG_MAP(CSample5Dialog)
  112.     //}}AFX_MSG_MAP
  113. END_MESSAGE_MAP()
  114.  
  115.  
  116. /////////////////////////////////////////////////////////////////////////////
  117. // CSample5Dialog message handlers
  118.  
  119. BOOL CSample5Dialog::OnInitDialog()
  120. {
  121.     CDialog::OnInitDialog();
  122.  
  123.     m_wndGrid.SubclassDlgItem(IDC_GRIDWND5, this);
  124.  
  125.     m_wndGrid.Initialize();
  126.  
  127.     m_wndGrid.SetRowCount(256);
  128.     m_wndGrid.SetColCount(52);
  129.  
  130.     m_wndGrid.SetCurrentCell(1,1);
  131.  
  132.     m_wndGrid.SetFocus();
  133.  
  134.     return FALSE;  // return TRUE  unless you set the focus to a control
  135. }
  136.