home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / general / ctrltest / spintest.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  2.6 KB  |  109 lines

  1. // spintest.cpp : New control example - Uses MicroScroll32
  2. //                custom control DLL from MuScrl32 sample
  3. //
  4. // This is a part of the Microsoft Foundation Classes C++ library.
  5. // Copyright (C) 1992-1998 Microsoft Corporation
  6. // All rights reserved.
  7. //
  8. // This source code is only intended as a supplement to the
  9. // Microsoft Foundation Classes Reference and related
  10. // electronic documentation provided with the library.
  11. // See these sources for detailed information regarding the
  12. // Microsoft Foundation Classes product.
  13.  
  14. #include "stdafx.h"
  15. #include "ctrltest.h"
  16.  
  17. #include "paredit.h"
  18.  
  19. /////////////////////////////////////////////////////////////////////////////
  20. // Example of a dialog with special controls in it
  21.  
  22. #define NUM_EDIT        4
  23. #define IDC_EDIT_MIN    IDC_EDIT1
  24. #define IDC_BUTTON_MAX  IDC_BUTTON4
  25.     // IDC_EDIT1->IDC_EDIT4 and IDC_BUTTON1->IDC_BUTTON4 must be contiguous
  26.  
  27. class CSpinEditDlg : public CDialog
  28. {
  29. protected:
  30.     CParsedEdit edit[NUM_EDIT];
  31. public:
  32.     //{{AFX_DATA(CSpinEditDlg)
  33.         enum { IDD = IDD_SPIN_EDIT };
  34.     //}}AFX_DATA
  35.     CSpinEditDlg()
  36.         : CDialog(CSpinEditDlg::IDD)
  37.             { }
  38.  
  39.     BOOL OnInitDialog();
  40.     //{{AFX_MSG(CSpinEditDlg)
  41.         virtual void OnOK();
  42.     //}}AFX_MSG
  43.     DECLARE_MESSAGE_MAP()
  44. };
  45.  
  46. BEGIN_MESSAGE_MAP(CSpinEditDlg, CDialog)
  47.     //{{AFX_MSG_MAP(CSpinEditDlg)
  48.     //}}AFX_MSG_MAP
  49. END_MESSAGE_MAP()
  50.  
  51.  
  52. BOOL CSpinEditDlg::OnInitDialog()
  53. {
  54.     int value = 1;
  55.     for (int i = 0; i < NUM_EDIT; i++)
  56.     {
  57.         // associate button with edit item
  58.         CSpinButtonCtrl* pSpin = (CSpinButtonCtrl*)GetDlgItem(IDC_BUTTON_MAX - i);
  59.         ASSERT(pSpin != NULL);
  60.             pSpin->SetPos(value++);     // 1, 2, 3, 4
  61.     }
  62.     return TRUE;
  63. }
  64.  
  65. void CSpinEditDlg::OnOK()
  66. {
  67.     int values[NUM_EDIT];
  68.     UINT nID = 0;
  69.     BOOL bOk = TRUE;
  70.     for (int i = 0; bOk && i < NUM_EDIT; i++)
  71.     {
  72.         nID = IDC_EDIT_MIN + i;
  73.         values[i] = GetDlgItemInt(nID, &bOk);
  74.     }
  75.  
  76.     if (!bOk)
  77.     {
  78.         // report illegal value
  79.         CString str;
  80.         str.LoadString(IDS_ILLEGAL_VALUE);
  81.         MessageBox(str);
  82.         CEdit& badEdit = *(CEdit*)GetDlgItem(nID);
  83.         badEdit.SetSel(0, -1);
  84.         badEdit.SetFocus();
  85.         return;     // don't end dialog
  86.     }
  87.  
  88. #ifdef _DEBUG
  89.     // dump results, normally you would do something with these
  90.     TRACE0("Final values:\n");
  91.     for (i = 0; i < NUM_EDIT; i++)
  92.         TRACE1("\t%d\n", values[i]);
  93. #endif
  94.     EndDialog(IDOK);
  95. }
  96.  
  97. /////////////////////////////////////////////////////////////////////////////
  98. // Run the test
  99.  
  100. void CTestWindow::OnTestSpinEdit()
  101. {
  102.     TRACE0("running dialog with spin controls in it\n");
  103.     CSpinEditDlg dlg;
  104.     dlg.DoModal();
  105. }
  106.  
  107.  
  108. /////////////////////////////////////////////////////////////////////////////
  109.