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 / dlgsamp4.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-27  |  3.6 KB  |  144 lines

  1. // dlgsamp4.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 "dlgsamp4.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. // CSample4Dialog
  36. //
  37. // As described in the overview of the programmers guide,
  38. // you can use a grid as dialog control in a dialog template.
  39. //
  40. // CSample4Dialog is based on the IDD_DLGSAMP4 dialog template.
  41. // I have dragged an user control into the dialog template and
  42. // set the control class to "CSample4GridWnd".
  43. //
  44. // CSample4GridWnd is registered in CGridSampleApp::InitInstance
  45. // which calls the method CSample4GridWnd::RegisterClass().
  46. //
  47. // The macro GetGridWnd() returns a pointer to the grid window.
  48. // OnInitDialog calls the Initialize method of the grid.
  49. //
  50. // In DoDataExchange, I have added the line
  51. // DDV_GXGridWnd(pDX, GetGridWnd());
  52. // which enables control validation in the dialog.
  53.  
  54. /////////////////////////////////////////////////////////////////////////////
  55. // CSample4GridWnd grid control
  56.  
  57. IMPLEMENT_REGISTER(CSample4GridWnd, CS_DBLCLKS, 0, 0, 0);
  58.  
  59. // validation routine
  60.  
  61. BOOL CSample4GridWnd::OnValidateCell(ROWCOL nRow, ROWCOL nCol)
  62. {
  63.     CString s;
  64.  
  65.     // retrieve text from current cell
  66.     CGXControl* pControl = GetControl(nRow, nCol);
  67.     pControl->GetCurrentText(s);
  68.  
  69.     if (_ttol(s) < 0 || _ttol(s) > 100)
  70.     {
  71.         SetWarningText(_T("Please enter a value between 0 and 100!"));
  72.         return FALSE;
  73.     }
  74.  
  75.     return TRUE;
  76. }
  77.  
  78. BEGIN_MESSAGE_MAP(CSample4GridWnd, CGXGridWnd)
  79.     //{{AFX_MSG_MAP(CSample4GridWnd)
  80.     //}}AFX_MSG_MAP
  81. END_MESSAGE_MAP()
  82.  
  83. /////////////////////////////////////////////////////////////////////////////
  84. // CSample4Dialog dialog
  85.  
  86. #define GetGridWnd() ((CSample4GridWnd*) GetDlgItem(IDC_GRIDWND4))
  87.  
  88. CSample4Dialog::CSample4Dialog(CWnd* pParent /*=NULL*/)
  89.     : CDialog(CSample4Dialog::IDD, pParent)
  90. {
  91.     //{{AFX_DATA_INIT(CSample4Dialog)
  92.     m_nEdit = 0;
  93.     m_nVal2 = 0;
  94.     //}}AFX_DATA_INIT
  95. }
  96.  
  97. void CSample4Dialog::DoDataExchange(CDataExchange* pDX)
  98. {
  99.     CDialog::DoDataExchange(pDX);
  100.     //{{AFX_DATA_MAP(CSample4Dialog)
  101.     DDX_Text(pDX, IDC_EDIT1, m_nEdit);
  102.     DDV_MinMaxInt(pDX, m_nEdit, 0, 100);
  103.     DDX_Text(pDX, IDC_EDIT2, m_nVal2);
  104.     DDV_MinMaxInt(pDX, m_nVal2, 0, 100);
  105.     //}}AFX_DATA_MAP
  106.  
  107.     // validation routine for CGXGridWnd controls
  108.     DDV_GXGridWnd(pDX, GetGridWnd());
  109. }
  110.  
  111. BEGIN_MESSAGE_MAP(CSample4Dialog, CDialog)
  112.     //{{AFX_MSG_MAP(CSample4Dialog)
  113.     ON_WM_NCACTIVATE()
  114.     //}}AFX_MSG_MAP
  115. END_MESSAGE_MAP()
  116.  
  117.  
  118. /////////////////////////////////////////////////////////////////////////////
  119. // CSample4Dialog message handlers
  120.  
  121. BOOL CSample4Dialog::OnInitDialog()
  122. {
  123.     CDialog::OnInitDialog();
  124.  
  125.     GetGridWnd()->Initialize();
  126.  
  127.     GetGridWnd()->SetRowCount(256);
  128.     GetGridWnd()->SetColCount(52);
  129.  
  130.     GetGridWnd()->SetCurrentCell(1,1);
  131.  
  132.     GetGridWnd()->SetFocus();
  133.  
  134.     return FALSE;  // return TRUE  unless you set the focus to a control
  135. }
  136.  
  137. BOOL CSample4Dialog::OnNcActivate(BOOL bActive)
  138. {
  139.     if (CGXGridCombo::GetComboBoxDropDown())
  140.         return TRUE;
  141.  
  142.     return CDialog::OnNcActivate(bActive);
  143. }
  144.