Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

108 lines
2.5 KiB

  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. #include "stdafx.h"
  14. #include "ctrltest.h"
  15. #include "paredit.h"
  16. /////////////////////////////////////////////////////////////////////////////
  17. // Example of a dialog with special controls in it
  18. #define NUM_EDIT 4
  19. #define IDC_EDIT_MIN IDC_EDIT1
  20. #define IDC_BUTTON_MAX IDC_BUTTON4
  21. // IDC_EDIT1->IDC_EDIT4 and IDC_BUTTON1->IDC_BUTTON4 must be contiguous
  22. class CSpinEditDlg : public CDialog
  23. {
  24. protected:
  25. CParsedEdit edit[NUM_EDIT];
  26. public:
  27. //{{AFX_DATA(CSpinEditDlg)
  28. enum { IDD = IDD_SPIN_EDIT };
  29. //}}AFX_DATA
  30. CSpinEditDlg()
  31. : CDialog(CSpinEditDlg::IDD)
  32. { }
  33. BOOL OnInitDialog();
  34. //{{AFX_MSG(CSpinEditDlg)
  35. virtual void OnOK();
  36. //}}AFX_MSG
  37. DECLARE_MESSAGE_MAP()
  38. };
  39. BEGIN_MESSAGE_MAP(CSpinEditDlg, CDialog)
  40. //{{AFX_MSG_MAP(CSpinEditDlg)
  41. //}}AFX_MSG_MAP
  42. END_MESSAGE_MAP()
  43. BOOL CSpinEditDlg::OnInitDialog()
  44. {
  45. int value = 1;
  46. for (int i = 0; i < NUM_EDIT; i++)
  47. {
  48. // associate button with edit item
  49. CSpinButtonCtrl* pSpin = (CSpinButtonCtrl*)GetDlgItem(IDC_BUTTON_MAX - i);
  50. ASSERT(pSpin != NULL);
  51. pSpin->SetPos(value++); // 1, 2, 3, 4
  52. }
  53. return TRUE;
  54. }
  55. void CSpinEditDlg::OnOK()
  56. {
  57. int values[NUM_EDIT];
  58. UINT nID = 0;
  59. BOOL bOk = TRUE;
  60. for (int i = 0; bOk && i < NUM_EDIT; i++)
  61. {
  62. nID = IDC_EDIT_MIN + i;
  63. values[i] = GetDlgItemInt(nID, &bOk);
  64. }
  65. if (!bOk)
  66. {
  67. // report illegal value
  68. CString str;
  69. str.LoadString(IDS_ILLEGAL_VALUE);
  70. MessageBox(str);
  71. CEdit& badEdit = *(CEdit*)GetDlgItem(nID);
  72. badEdit.SetSel(0, -1);
  73. badEdit.SetFocus();
  74. return; // don't end dialog
  75. }
  76. #ifdef _DEBUG
  77. // dump results, normally you would do something with these
  78. TRACE0("Final values:\n");
  79. for (i = 0; i < NUM_EDIT; i++)
  80. TRACE1("\t%d\n", values[i]);
  81. #endif
  82. EndDialog(IDOK);
  83. }
  84. /////////////////////////////////////////////////////////////////////////////
  85. // Run the test
  86. void CTestWindow::OnTestSpinEdit()
  87. {
  88. TRACE0("running dialog with spin controls in it\n");
  89. CSpinEditDlg dlg;
  90. dlg.DoModal();
  91. }
  92. /////////////////////////////////////////////////////////////////////////////