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

  1. // dlgsamp1.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 "dlgsamp1.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. // CSample1Dialog
  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. // CSample1Dialog is based on the IDD_DLGSAMP1 dialog template.
  41. // I have dragged an user control into the dialog template and
  42. // set the control class to "CGXGridWnd".
  43. //
  44. // CGXGridWnd is a registered window class. Registration is
  45. // automatically done in CGridSampleApp::InitInstance which
  46. // calls the method GXRegisterClass().
  47. //
  48. // The macro GetGridWnd() returns a pointer to the grid window.
  49. // OnInitDialog calls the Initialize method of the grid.
  50. //
  51. // OnInitDialog also shows you how to apply styles for the whole
  52. // table and some simple cell validation.
  53. //
  54. // In DoDataExchange, I have added the line
  55. // DDV_GXGridWnd(pDX, GetGridWnd());
  56. // which enables control validation in the dialog.
  57.  
  58. #define GetGridWnd()    ((CGXGridWnd*) GetDlgItem(IDC_GRID1))
  59.  
  60. /////////////////////////////////////////////////////////////////////////////
  61. // CSample1Dialog dialog
  62.  
  63. CSample1Dialog::CSample1Dialog(CWnd* pParent /*=NULL*/)
  64.     : CDialog(CSample1Dialog::IDD, pParent)
  65. {
  66.     //{{AFX_DATA_INIT(CSample1Dialog)
  67.     m_nEdit = 0;
  68.     m_nVal2 = 0;
  69.     //}}AFX_DATA_INIT
  70. }
  71.  
  72. void CSample1Dialog::DoDataExchange(CDataExchange* pDX)
  73. {
  74.     CDialog::DoDataExchange(pDX);
  75.     //{{AFX_DATA_MAP(CSample1Dialog)
  76.     DDX_Text(pDX, IDC_EDIT1, m_nEdit);
  77.     DDV_MinMaxInt(pDX, m_nEdit, 0, 100);
  78.     DDX_Text(pDX, IDC_EDIT2, m_nVal2);
  79.     DDV_MinMaxInt(pDX, m_nVal2, 0, 100);
  80.     //}}AFX_DATA_MAP
  81.  
  82.     // validation routine for CGXGridWnd controls
  83.     DDV_GXGridWnd(pDX, GetGridWnd());
  84. }
  85.  
  86. BEGIN_MESSAGE_MAP(CSample1Dialog, CDialog)
  87.     //{{AFX_MSG_MAP(CSample1Dialog)
  88.     ON_WM_NCACTIVATE()
  89.     //}}AFX_MSG_MAP
  90. END_MESSAGE_MAP()
  91.  
  92.  
  93. /////////////////////////////////////////////////////////////////////////////
  94. // CSample1Dialog message handlers
  95.  
  96. BOOL CSample1Dialog::OnInitDialog()
  97. {
  98.     CDialog::OnInitDialog();
  99.  
  100.     GetGridWnd()->Initialize();
  101.  
  102.     GetGridWnd()->SetScrollBarMode(SB_BOTH, gxnAutomatic | gxnEnhanced);
  103.  
  104.     GetGridWnd()->SetRowCount(256);
  105.     GetGridWnd()->SetColCount(52);
  106.  
  107.     // minimumn, maximum value
  108.     GetGridWnd()->SetStyleRange(CGXRange().SetTable(), CGXStyle()
  109.             .SetUserAttribute(GX_IDS_UA_VALID_MIN, _T("0"))
  110.             .SetUserAttribute(GX_IDS_UA_VALID_MAX, _T("100"))
  111.             .SetUserAttribute(GX_IDS_UA_VALID_MSG, _T("Please enter a value between 0 and 100!"))
  112.         );
  113.  
  114.     GetGridWnd()->SetStyleRange(CGXRange().SetCols(1), CGXStyle()
  115.             .SetUserAttribute(GX_IDS_UA_TOOLTIPTEXT, _T("Column 1")));
  116.  
  117.     GetGridWnd()->SetStyleRange(CGXRange().SetCols(2), CGXStyle()
  118.             .SetUserAttribute(GX_IDS_UA_TOOLTIPTEXT, _T("Column 2")));
  119.  
  120.     GetGridWnd()->SetStyleRange(CGXRange().SetCols(3), CGXStyle()
  121.             .SetUserAttribute(GX_IDS_UA_TOOLTIPTEXT, _T("Column 3")));
  122.  
  123. #if _MFC_VER >= 0x0400 && !defined(_AFX_NO_OLE_SUPPORT)
  124.     // Enable grid to be used as data source
  125.     GetGridWnd()->EnableOleDataSource();
  126.  
  127.     // Register the grid as drop target
  128.     VERIFY(m_objDndDropTarget.Register(GetGridWnd()));
  129.  
  130. #endif
  131.  
  132. #if _MFC_VER >= 0x0400
  133.     GetGridWnd()->EnableGridToolTips();
  134.  
  135.     CGXStylesMap* stylesmap = GetGridWnd()->GetParam()->GetStylesMap();
  136.     stylesmap->AddUserAttribute(GX_IDS_UA_TOOLTIPTEXT,
  137.         CGXStyle().SetWrapText(TRUE).SetAutoSize(TRUE));
  138. #endif
  139.  
  140.     GetGridWnd()->SetCurrentCell(1,1);
  141.  
  142.     GetGridWnd()->SetFocus();
  143.  
  144.     return FALSE;  // return TRUE  unless you set the focus to a control
  145. }
  146.  
  147. BOOL CSample1Dialog::OnNcActivate(BOOL bActive)
  148. {
  149.     if (CGXGridCombo::GetComboBoxDropDown())
  150.         return TRUE;
  151.  
  152.     return CDialog::OnNcActivate(bActive);
  153. }
  154.