home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 19.ddi / MFC / SAMPLES / CTRLTEST / SPINTEST.CP_ / SPINTEST.CP
Encoding:
Text File  |  1993-02-08  |  3.0 KB  |  124 lines

  1. // muscroll.cpp : New control example - MicroScroller
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and Microsoft
  9. // WinHelp documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "ctrltest.h"
  15.  
  16. #include "paredit.h"
  17. #include "spin.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_MIN  IDC_BUTTON1
  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.         UINT nID = IDC_EDIT_MIN + i;
  58.         edit[i].SubclassEdit(nID, this, PES_NUMBERS);
  59.         SetDlgItemInt(nID, value);
  60.         value++;        // 1, 2, 3, 4
  61.  
  62.         // associate button with edit item
  63.         CSpinControl* pSpin = (CSpinControl*)GetDlgItem(IDC_BUTTON_MIN + i);
  64.         ASSERT(pSpin != NULL);
  65.             pSpin->SetAssociate(&edit[i]);
  66.     }
  67.     return TRUE;
  68. }
  69.  
  70. void CSpinEditDlg::OnOK()
  71. {
  72.     int values[NUM_EDIT];
  73.     UINT nID = 0;
  74.     BOOL bOk = TRUE;
  75.     for (int i = 0; bOk && i < NUM_EDIT; i++)
  76.     {
  77.         nID = IDC_EDIT_MIN + i;
  78.         values[i] = GetDlgItemInt(nID, &bOk);
  79.     }
  80.  
  81.     if (!bOk)
  82.     {
  83.         // report illegal value
  84.         MessageBox("illegal value\n");
  85.         CEdit& badEdit = *(CEdit*)GetDlgItem(nID);
  86.         badEdit.SetSel(0, -1);
  87.         badEdit.SetFocus();
  88.         return;     // don't end dialog
  89.     }
  90.  
  91. #ifdef _DEBUG
  92.     // dump results, normally you would do something with these
  93.     TRACE("Final values:\n");
  94.     for (i = 0; i < NUM_EDIT; i++)
  95.         TRACE("\t%d\n", values[i]);
  96. #endif
  97.     EndDialog(IDOK);
  98. }
  99.  
  100. /////////////////////////////////////////////////////////////////////////////
  101. // Run the test
  102.  
  103. void CTestWindow::OnTestSpinEdit()
  104. {
  105.     HINSTANCE hLibrary;
  106.     if ((hLibrary = LoadLibrary("MUSCROLL.DLL")) < HINSTANCE_ERROR)
  107.     {
  108.         MessageBox("Can not do this test without custom control library");
  109.  
  110.         // prevent it from happening again
  111.         GetMenu()->EnableMenuItem(IDM_TEST_SPIN_EDIT, MF_DISABLED|MF_GRAYED);
  112.         return;
  113.     }
  114.  
  115.     TRACE("running dialog with spin controls in it\n");
  116.     CSpinEditDlg dlg;
  117.     dlg.DoModal();
  118.  
  119.     FreeLibrary(hLibrary);
  120. }
  121.  
  122.  
  123. /////////////////////////////////////////////////////////////////////////////
  124.