home *** CD-ROM | disk | FTP | other *** search
- // dualrang.cpp : implementation file
- // Copyright (C) 1996 LEAD Technologies, Inc.
- // All rights reserved.
-
- #include "stdafx.h"
- #include "mfcdemo.h"
- #include "dualrang.h"
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CDualRangeDlg dialog
-
-
- CDualRangeDlg::CDualRangeDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CDualRangeDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CDualRangeDlg)
- m_strLabel1 = _T("");
- m_strLabel2 = _T("");
- m_strTitle = _T("");
- m_nValue1 = 0;
- m_nValue2 = 0;
- m_nMin = 0;
- m_nMax = 100;
- m_nStep = 1;
- m_nPage = 10;
- //}}AFX_DATA_INIT
- }
-
-
- void CDualRangeDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CDualRangeDlg)
- DDX_Control(pDX, IDC_SCROLLBAR2, m_ScrollBar2);
- DDX_Control(pDX, IDC_SCROLLBAR1, m_ScrollBar1);
- DDX_Text(pDX, IDC_STATIC1, m_strLabel1);
- DDX_Text(pDX, IDC_STATIC2, m_strLabel2);
- DDX_Text(pDX, IDC_EDIT1, m_nValue1);
- DDV_MinMaxInt(pDX, m_nValue1, m_nMin, m_nMax);
- DDX_Text(pDX, IDC_EDIT2, m_nValue2);
- DDV_MinMaxInt(pDX, m_nValue2, m_nMin, m_nMax);
- //}}AFX_DATA_MAP
- }
-
-
- BEGIN_MESSAGE_MAP(CDualRangeDlg, CDialog)
- //{{AFX_MSG_MAP(CDualRangeDlg)
- ON_WM_HSCROLL()
- ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
- ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
-
- BOOL CDualRangeDlg::GetValue(BOOL fFirst)
- {
- BOOL fTranslated;
- int n;
-
- n = GetDlgItemInt (fFirst ? IDC_EDIT1 : IDC_EDIT2, &fTranslated, TRUE);
- if (!fTranslated || n < m_nMin || n > m_nMax)
- return(FALSE);
- if(fFirst)
- m_nValue1 = n;
- else
- m_nValue2 = n;
- return(TRUE);
- }
-
- void CDualRangeDlg::SetValue(BOOL fFirst)
- {
- if(fFirst)
- SetDlgItemInt (IDC_EDIT1, m_nValue1, TRUE);
- else
- SetDlgItemInt (IDC_EDIT2, m_nValue2, TRUE);
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CDualRangeDlg message handlers
-
-
- void CDualRangeDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- BOOL fFirst;
- int nValue;
-
- fFirst = (pScrollBar->GetDlgCtrlID() == IDC_SCROLLBAR1);
- GetValue(fFirst);
- nValue = (fFirst ? m_nValue1 : m_nValue2);
-
- switch (nSBCode)
- {
- case SB_LEFT:
- nValue = m_nMin;
- break;
- case SB_RIGHT:
- nValue = m_nMax;
- break;
- case SB_THUMBPOSITION:
- case SB_THUMBTRACK:
- nValue = (int) nPos;
- break;
- case SB_LINELEFT:
- nValue = max (nValue - m_nStep, m_nMin);
- break;
- case SB_LINERIGHT:
- nValue = min (nValue + m_nStep, m_nMax);
- break;
- case SB_PAGELEFT:
- nValue = max (nValue - m_nPage, m_nMin);
- break;
- case SB_PAGERIGHT:
- nValue = min (nValue + m_nPage, m_nMax);
- break;
- }
- if(fFirst)
- m_nValue1 = nValue;
- else
- m_nValue2 = nValue;
- pScrollBar->SetScrollPos(nValue);
- SetValue(fFirst);
- }
-
- void CDualRangeDlg::OnChangeEdit1()
- {
- if(GetValue(TRUE))
- m_ScrollBar1.SetScrollPos(m_nValue1);
-
- }
-
- void CDualRangeDlg::OnChangeEdit2()
- {
- if(GetValue(FALSE))
- m_ScrollBar2.SetScrollPos(m_nValue2);
-
- }
-
-
- BOOL CDualRangeDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- SetWindowText(m_strTitle);
- m_ScrollBar1.SetScrollRange(m_nMin, m_nMax, TRUE);
- m_ScrollBar1.SetScrollPos(m_nValue1);
- m_ScrollBar2.SetScrollRange(m_nMin, m_nMax, TRUE);
- m_ScrollBar2.SetScrollPos(m_nValue2);
-
- // TODO: Add extra initialization here
-
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }