home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c031 / 11.ddi / MFC / SAMPLES / CTRLTEST / SPINTEST.CP$ / spintest
Encoding:
Text File  |  1992-03-16  |  2.7 KB  |  111 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. // QuickHelp documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "ctrltest.h"
  14.  
  15. #include "paredit.h"
  16. #include "spin.h"
  17.  
  18. /////////////////////////////////////////////////////////////////////////////
  19. // Example of a dialog with special controls in it
  20.  
  21. #define NUM_EDIT        4
  22. #define IDC_EDIT_MIN    IDC_EDIT1
  23. #define IDC_BUTTON_MIN  IDC_BUTTON1
  24.     // IDC_EDIT1->IDC_EDIT4 and IDC_BUTTON1->IDC_BUTTON4 must be contiguous
  25.  
  26. class CSpinEditDlg : public CModalDialog
  27. {
  28. protected:
  29.     CParsedEdit edit[NUM_EDIT];
  30. public:
  31.     CSpinEditDlg()
  32.         : CModalDialog(IDD_SPIN_EDIT)
  33.             { }
  34.  
  35.     BOOL OnInitDialog();
  36.     void OnOK();
  37. };
  38.  
  39. BOOL CSpinEditDlg::OnInitDialog()
  40. {
  41.     int value = 1;
  42.     for (int i = 0; i < NUM_EDIT; i++)
  43.     {
  44.         UINT nID = IDC_EDIT_MIN + i;
  45.         edit[i].SubclassEdit(nID, this, PES_NUMBERS);
  46.         SetDlgItemInt(nID, value);
  47.         value++;        // 1, 2, 3, 4
  48.  
  49.         // associate button with edit item
  50.         CSpinControl* pSpin = (CSpinControl*)GetDlgItem(IDC_BUTTON_MIN + i);
  51.         ASSERT(pSpin != NULL);
  52.             pSpin->SetAssociate(&edit[i]);
  53.     }
  54.     return TRUE;
  55. }
  56.  
  57. void CSpinEditDlg::OnOK()
  58. {
  59.     int values[NUM_EDIT];
  60.     UINT nID;
  61.     BOOL bOk = TRUE;
  62.     for (int i = 0; bOk && i < NUM_EDIT; i++)
  63.     {
  64.         nID = IDC_EDIT_MIN + i;
  65.         values[i] = GetDlgItemInt(nID, &bOk);
  66.     }
  67.  
  68.     if (!bOk)
  69.     {
  70.         // report illegal value
  71.         MessageBox("illegal value\n");
  72.         CEdit& badEdit = *(CEdit*)GetDlgItem(nID);
  73.         badEdit.SetSel(0, -1);
  74.         badEdit.SetFocus();
  75.         return;     // don't end dialog
  76.     }
  77.  
  78. #ifdef _DEBUG
  79.     // dump results, normally you would do something with these
  80.     TRACE("Final values:\n");
  81.     for (i = 0; i < NUM_EDIT; i++)
  82.         TRACE("\t%d\n", values[i]);
  83. #endif
  84.     EndDialog(IDOK);
  85. }
  86.  
  87. /////////////////////////////////////////////////////////////////////////////
  88. // Run the test
  89.  
  90. void CTestWindow::OnTestSpinEdit()
  91. {
  92.     HINSTANCE hLibrary;
  93.     if ((hLibrary = LoadLibrary("MUSCROLL.DLL")) < HINSTANCE_ERROR)
  94.     {
  95.         MessageBox("Can not do this test without custom control library");
  96.  
  97.         // prevent it from happening again
  98.         GetMenu()->EnableMenuItem(IDM_TEST_SPIN_EDIT, MF_DISABLED|MF_GRAYED);
  99.         return;
  100.     }
  101.  
  102.     TRACE("running dialog with spin controls in it\n");
  103.     CSpinEditDlg dlg;
  104.     dlg.DoModal();
  105.  
  106.     FreeLibrary(hLibrary);
  107. }
  108.  
  109.  
  110. /////////////////////////////////////////////////////////////////////////////
  111.