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

  1. // dlgsamp2.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 "dlgsamp2.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. // CSample2Dialog
  36. //
  37. // CSample1Dialog is based on the IDD_DLGSAMP2 dialog template.
  38. // I have dragged an user control into the dialog template and
  39. // set the control class to "CGXTabWnd".
  40. //
  41. // CGXTabWnd is a registered window class. Registration is
  42. // automatically done in CGridSampleApp::InitInstance which
  43. // calls the method GXRegisterClass().
  44. //
  45. // The macro GetTabWnd() returns a pointer to the tab window.
  46. // OnInitDialog creates several grid windows and attaches these
  47. // windows to the tabwindow.
  48. //
  49. // CSample2GridWnd is a derived grid control. It shows you
  50. // how to do custom cell validation.
  51. //
  52. // In DoDataExchange, I have added the line
  53. // DDV_GXTabWnd(pDX, GetTabWnd());
  54. // which enables control validation in the dialog.
  55.  
  56. #define GetTabWnd()     ((CGXTabWnd*) GetDlgItem(IDC_TABWND2))
  57.  
  58. /////////////////////////////////////////////////////////////////////////////
  59. // CSample2GridWnd grid control
  60.  
  61. // validation routine
  62.  
  63. BOOL CSample2GridWnd::OnValidateCell(ROWCOL nRow, ROWCOL nCol)
  64. {
  65.     CString s;
  66.  
  67.     // retrieve text from current cell
  68.     CGXControl* pControl = GetControl(nRow, nCol);
  69.     pControl->GetCurrentText(s);
  70.  
  71.     if (_ttol(s) < 0 || _ttol(s) > 100)
  72.     {
  73.         TCHAR sz[255];
  74.         wsprintf(sz, _T("Please enter a value between 0 and 100!"));
  75.  
  76.         ScrollCellInView(nRow, nCol);
  77.  
  78.         // Display message box
  79.         if (m_bLockActivateGrid)
  80.         {
  81.             AfxMessageBox(sz);
  82.  
  83.             // m_bWarningTextDisplayed is looked up in OnLButtonHitRowCol
  84.             // if you set this TRUE, OnLButtonHitRowCol will cancel any further mouse processing
  85.             m_bWarningTextDisplayed = TRUE;
  86.  
  87.             // If you want the current cell to be undone, call
  88.             // TransferCurrentCell(FALSE);
  89.  
  90.             // This is only a sample. You might also display a message box
  91.             // and ask the user if he wants to retry or ignore the value or
  92.             // you could also call pControl->SetCurrentText() to change
  93.             // the value.
  94.             // pControl->SetCurrentText("22");
  95.         }
  96.  
  97.         // else do nothing, the focus will go back to the current cell
  98.  
  99.         return FALSE;
  100.     }
  101.  
  102.     return TRUE;
  103. }
  104.  
  105. BEGIN_MESSAGE_MAP(CSample2GridWnd, CGXGridWnd)
  106.     //{{AFX_MSG_MAP(CSample2GridWnd)
  107.     //}}AFX_MSG_MAP
  108. END_MESSAGE_MAP()
  109.  
  110. /////////////////////////////////////////////////////////////////////////////
  111. // CSample2Dialog dialog
  112.  
  113. CSample2Dialog::CSample2Dialog(CWnd* pParent /*=NULL*/)
  114.     : CDialog(CSample2Dialog::IDD, pParent)
  115. {
  116.     //{{AFX_DATA_INIT(CSample2Dialog)
  117.     m_nEdit = 0;
  118.     m_nVal2 = 0;
  119.     //}}AFX_DATA_INIT
  120. }
  121.  
  122. void CSample2Dialog::DoDataExchange(CDataExchange* pDX)
  123. {
  124.     CDialog::DoDataExchange(pDX);
  125.     //{{AFX_DATA_MAP(CSample2Dialog)
  126.     DDX_Text(pDX, IDC_EDIT1, m_nEdit);
  127.     DDV_MinMaxInt(pDX, m_nEdit, 0, 100);
  128.     DDX_Text(pDX, IDC_EDIT2, m_nVal2);
  129.     DDV_MinMaxInt(pDX, m_nVal2, 0, 100);
  130.     //}}AFX_DATA_MAP
  131.  
  132.     // validation routine for CGXTabWnd controls
  133.     DDV_GXTabWnd(pDX, GetTabWnd());
  134. }
  135.  
  136. BEGIN_MESSAGE_MAP(CSample2Dialog, CDialog)
  137.     //{{AFX_MSG_MAP(CSample2Dialog)
  138.     ON_WM_NCACTIVATE()
  139.     //}}AFX_MSG_MAP
  140. END_MESSAGE_MAP()
  141.  
  142.  
  143. /////////////////////////////////////////////////////////////////////////////
  144. // CSample2Dialog message handlers
  145.  
  146. BOOL CSample2Dialog::OnInitDialog()
  147. {
  148.     CDialog::OnInitDialog();
  149.  
  150.     m_grid1.Create(0, CRect(0,0,1,1), GetTabWnd(), GetTabWnd()->GetNextID());
  151.     m_grid2.Create(0, CRect(0,0,1,1), GetTabWnd(), GetTabWnd()->GetNextID());
  152.     m_grid3.Create(0, CRect(0,0,1,1), GetTabWnd(), GetTabWnd()->GetNextID());
  153.  
  154.     GetTabWnd()->AttachWnd(&m_grid1, _T("Grid 1"));
  155.     GetTabWnd()->AttachWnd(&m_grid2, _T("Grid 2"));
  156.     GetTabWnd()->AttachWnd(&m_grid3, _T("Grid 3"));
  157.  
  158.     m_grid1.Initialize();
  159.     m_grid2.Initialize();
  160.     m_grid3.Initialize();
  161.  
  162.     m_grid1.SetRowCount(256);
  163.     m_grid2.SetRowCount(256);
  164.     m_grid3.SetRowCount(256);
  165.  
  166.     m_grid1.SetColCount(52);
  167.     m_grid2.SetColCount(52);
  168.     m_grid3.SetColCount(52);
  169.  
  170.     m_grid1.SetCurrentCell(1,1);
  171.     m_grid2.SetCurrentCell(1,1);
  172.     m_grid3.SetCurrentCell(1,1);
  173.  
  174.     GetTabWnd()->SetFocus();
  175.  
  176.     return FALSE;  // return TRUE  unless you set the focus to a control
  177. }
  178.  
  179. BOOL CSample2Dialog::OnNcActivate(BOOL bActive)
  180. {
  181.     if (CGXGridCombo::GetComboBoxDropDown())
  182.         return TRUE;
  183.  
  184.     return CDialog::OnNcActivate(bActive);
  185. }
  186.