home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / CMNCTRL.PAK / SPINCTRL.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  4.8 KB  |  167 lines

  1. // SpinCtrl.cpp : implementation file
  2. //
  3.  
  4. // This is a part of the Microsoft Foundation Classes C++ library.
  5. // Copyright (C) 1992-1995 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 "ctrldemo.h"
  16. #include "SpinCtrl.h"
  17.  
  18. #ifdef _DEBUG
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22.  
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CSpinCtrlPage property page
  25.  
  26. IMPLEMENT_DYNCREATE(CSpinCtrlPage, CPropertyPage)
  27.  
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #endif
  31.  
  32. CSpinCtrlPage::CSpinCtrlPage() : CPropertyPage(CSpinCtrlPage::IDD)
  33. {
  34.     //{{AFX_DATA_INIT(CSpinCtrlPage)
  35.     m_iAlignment = 0;
  36.     m_bArrowkeys = FALSE;
  37.     m_bAutobuddy = FALSE;
  38.     m_uiRangeFrom = 0;
  39.     m_bNothousands = FALSE;
  40.     m_iOrientation = 0;
  41.     m_bSetbuddyint = FALSE;
  42.     m_uiRangeTo = 100;
  43.     m_bWrap = FALSE;
  44.     //}}AFX_DATA_INIT
  45. }
  46.  
  47. CSpinCtrlPage::~CSpinCtrlPage()
  48. {
  49. }
  50.  
  51. void CSpinCtrlPage::DoDataExchange(CDataExchange* pDX)
  52. {
  53.     CPropertyPage::DoDataExchange(pDX);
  54.     //{{AFX_DATA_MAP(CSpinCtrlPage)
  55.     DDX_CBIndex(pDX, IDC_SPIN_ALIGNMENT, m_iAlignment);
  56.     DDX_Check(pDX, IDC_SPIN_ARROWKEYS, m_bArrowkeys);
  57.     DDX_Check(pDX, IDC_SPIN_AUTOBUDDY, m_bAutobuddy);
  58.     DDX_Text(pDX, IDC_SPIN_FROM, m_uiRangeFrom);
  59.     DDV_MinMaxUInt(pDX, m_uiRangeFrom, 0, 65535);
  60.     DDX_Check(pDX, IDC_SPIN_NOTHOUSANDS, m_bNothousands);
  61.     DDX_CBIndex(pDX, IDC_SPIN_ORIENTATION, m_iOrientation);
  62.     DDX_Check(pDX, IDC_SPIN_SETBUDDYINT, m_bSetbuddyint);
  63.     DDX_Text(pDX, IDC_SPIN_TO, m_uiRangeTo);
  64.     DDV_MinMaxUInt(pDX, m_uiRangeTo, 0, 65535);
  65.     DDX_Check(pDX, IDC_SPIN_WRAP, m_bWrap);
  66.     //}}AFX_DATA_MAP
  67. }
  68.  
  69. BOOL CSpinCtrlPage::OnInitDialog()
  70. {
  71.     CPropertyPage::OnInitDialog();
  72.  
  73.     CWnd* pEdit = GetDlgItem( IDC_SPIN_EDIT );
  74.     pEdit->GetWindowRect( &m_EditRect );
  75.     ScreenToClient( &m_EditRect );
  76.  
  77.     CreateSpinCtrl();
  78.     SetModified(TRUE);  // allow the APPLY button to become active
  79.  
  80.     return TRUE;
  81. }
  82.  
  83. void CSpinCtrlPage::CreateSpinCtrl()
  84. {
  85. DWORD dwStyles=0;
  86.  
  87.     // Build styles mask
  88.     if ( 1 == m_iAlignment )
  89.         dwStyles |= UDS_ALIGNLEFT;        // Control is placed to the left of buddy, if set
  90.                                         // (default = unattached)
  91.     else if ( 2 == m_iAlignment )
  92.         dwStyles |= UDS_ALIGNRIGHT;        // Control is placed to the right of buddy, if set
  93.                                         // (default = unattached)
  94.     if ( m_bArrowkeys )
  95.         dwStyles |= UDS_ARROWKEYS;        // Up/Down arrow keys inc/decrement, if set
  96.  
  97.     if ( m_bAutobuddy )
  98.         dwStyles |= UDS_AUTOBUDDY;        // Previous (in Z-order) edit used as buddy, if set
  99.  
  100.     if ( m_bNothousands )
  101.         dwStyles |= UDS_NOTHOUSANDS;    // No thousands seperator used, if set
  102.  
  103.     if ( 1 == m_iOrientation )
  104.         dwStyles |= UDS_HORZ;            // Control is horizontal, if set (default = vert)
  105.  
  106.     if ( m_bSetbuddyint )
  107.         dwStyles |= UDS_SETBUDDYINT;    // Control updates buddy edit with position, if set
  108.  
  109.     if ( m_bWrap )
  110.         dwStyles |= UDS_WRAP;            // Position wraps when range exceeded, if set
  111.  
  112.     // Get edit control and change Z-order (created controls go at bottom of Z-order)
  113.     CWnd* pEdit = GetDlgItem( IDC_SPIN_EDIT );
  114.     pEdit->SetWindowPos( &wndBottom, m_EditRect.left, m_EditRect.top,
  115.                          m_EditRect.Width(), m_EditRect.Height(), SWP_SHOWWINDOW );
  116.  
  117.     // Create spin (up-down) control
  118.     CWnd* pWnd = GetDlgItem( IDC_SPIN_POS );
  119.     CRect rect;
  120.     pWnd->GetWindowRect( &rect );
  121.     ScreenToClient( &rect );
  122.  
  123.     m_Spin.Create( WS_VISIBLE|WS_CHILD|dwStyles, rect, this, IDC_SPIN );
  124.     m_Spin.SetRange( m_uiRangeFrom, m_uiRangeTo );    // Sends UDM_SETRANGE
  125.  
  126.     // Prime edit control with initial value
  127.     TCHAR buf[32];
  128.     int pos = m_Spin.GetPos();                        // Sends UDM_GETPOS
  129.     wsprintf( buf, _T("%d"), pos );
  130.     pWnd = m_Spin.GetBuddy();                        // Sends UDM_GETBUDDY
  131.     if ( pWnd != NULL )
  132.         pWnd->SetWindowText( buf );
  133. }
  134.  
  135. BEGIN_MESSAGE_MAP(CSpinCtrlPage, CPropertyPage)
  136.     //{{AFX_MSG_MAP(CSpinCtrlPage)
  137.     ON_BN_CLICKED(IDC_SPIN_ARROWKEYS, OnAnyChange)
  138.     ON_BN_CLICKED(IDC_SPIN_AUTOBUDDY, OnAnyChange)
  139.     ON_BN_CLICKED(IDC_SPIN_NOTHOUSANDS, OnAnyChange)
  140.     ON_CBN_SELCHANGE(IDC_SPIN_ORIENTATION, OnAnyChange)
  141.     ON_BN_CLICKED(IDC_SPIN_SETBUDDYINT, OnAnyChange)
  142.     ON_EN_CHANGE(IDC_SPIN_TO, OnAnyChange)
  143.     ON_BN_CLICKED(IDC_SPIN_WRAP, OnAnyChange)
  144.     ON_EN_CHANGE(IDC_SPIN_EDIT, OnAnyChange)
  145.     ON_EN_CHANGE(IDC_SPIN_FROM, OnAnyChange)
  146.     ON_CBN_SELCHANGE(IDC_SPIN_ALIGNMENT, OnAnyChange)
  147.     //}}AFX_MSG_MAP
  148. END_MESSAGE_MAP()
  149.  
  150. /////////////////////////////////////////////////////////////////////////////
  151. // CSpinCtrlPage message handlers
  152.  
  153. BOOL CSpinCtrlPage::OnApply() 
  154. {
  155.     UpdateData();
  156.  
  157.     m_Spin.DestroyWindow();
  158.  
  159.     CreateSpinCtrl();
  160.     return TRUE;
  161. }
  162.  
  163. void CSpinCtrlPage::OnAnyChange() 
  164. {
  165.     SetModified(TRUE);
  166. }
  167.