home *** CD-ROM | disk | FTP | other *** search
- // resizedl.cpp : implementation file
- // Copyright (C) 1996 LEAD Technologies, Inc.
- // All rights reserved.
-
- #include "stdafx.h"
- #include "mfcdemo.h"
- #include "resizedl.h"
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CResizeDlg dialog
-
-
- CResizeDlg::CResizeDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CResizeDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CResizeDlg)
- m_nWidth = 0;
- m_nHeight = 0;
- m_nOrgWidth = 0;
- m_nOrgHeight = 0;
- m_fResample = FALSE;
- m_nMin = 1;
- m_nMax = 16384;
- m_nStep = 10;
- m_nPage = 100;
- m_fAspect = TRUE;
- //}}AFX_DATA_INIT
- }
-
-
- void CResizeDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CResizeDlg)
- DDX_Control(pDX, IDC_SCROLLBAR2, m_ScrollBar2);
- DDX_Control(pDX, IDC_SCROLLBAR1, m_ScrollBar1);
- DDX_Text(pDX, IDC_EDIT1, m_nWidth);
- DDV_MinMaxInt(pDX, m_nWidth, m_nMin, m_nMax);
- DDX_Text(pDX, IDC_EDIT2, m_nHeight);
- DDV_MinMaxInt(pDX, m_nHeight, m_nMin, m_nMax);
- DDX_Check(pDX, IDC_CHECK2, m_fResample);
- DDX_Check(pDX, IDC_CHECK1, m_fAspect);
- //}}AFX_DATA_MAP
- }
-
-
- BEGIN_MESSAGE_MAP(CResizeDlg, CDialog)
- //{{AFX_MSG_MAP(CResizeDlg)
- ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
- ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2)
- ON_WM_HSCROLL()
- ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
-
- BOOL CResizeDlg::GetValue(LPINT pValue, int nEditID, int nMin, int nMax)
- {
- BOOL fTranslated;
- int n;
- n = GetDlgItemInt (nEditID, &fTranslated, TRUE);
- if (!fTranslated || n < nMin || n > nMax)
- return(FALSE);
- *pValue = n;
- return(TRUE);
- }
-
- void CResizeDlg::SetValue(int nValue, int nEditID, CScrollBar *pScrollBar)
- {
- pScrollBar->SetScrollPos(nValue);
- SetDlgItemInt (nEditID, nValue, TRUE);
- }
-
- void CResizeDlg::DoScroll(LPINT pValue, UINT nSBCode, UINT nPos, int nMin, int nMax, int nStep, int nPage)
- {
- switch (nSBCode)
- {
- case SB_LEFT:
- *pValue = nMin;
- break;
- case SB_RIGHT:
- *pValue = nMax;
- break;
- case SB_THUMBPOSITION:
- case SB_THUMBTRACK:
- *pValue = (int) nPos;
- break;
- case SB_LINELEFT:
- *pValue = max (*pValue - nStep, nMin);
- break;
- case SB_LINERIGHT:
- *pValue = min (*pValue + nStep, nMax);
- break;
- case SB_PAGELEFT:
- *pValue = max (*pValue - nPage, nMin);
- break;
- case SB_PAGERIGHT:
- *pValue = min (*pValue + nPage, nMax);
- break;
- }
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CResizeDlg message handlers
-
- void CResizeDlg::OnChangeEdit1()
- {
- if(GetValue(&m_nWidth, IDC_EDIT1, m_nMin, m_nMax))
- {
- m_ScrollBar1.SetScrollPos(m_nWidth);
- if(m_fAspect)
- {
- m_fAspect = FALSE;
- m_nHeight = MulDiv(m_nWidth, m_nOrgHeight, m_nOrgWidth);
- SetValue(m_nHeight, IDC_EDIT2, &m_ScrollBar2);
- m_fAspect = TRUE;
- }
- }
- }
-
- void CResizeDlg::OnChangeEdit2()
- {
- if(GetValue(&m_nHeight, IDC_EDIT2, m_nMin, m_nMax))
- {
- m_ScrollBar2.SetScrollPos(m_nHeight);
- if(m_fAspect)
- {
- m_fAspect = FALSE;
- m_nWidth = MulDiv(m_nHeight, m_nOrgWidth, m_nOrgHeight);
- SetValue(m_nWidth, IDC_EDIT1, &m_ScrollBar1);
- m_fAspect = TRUE;
- }
- }
- }
-
-
-
- void CResizeDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
-
- if(pScrollBar->GetDlgCtrlID() == IDC_SCROLLBAR1)
- {
- GetValue(&m_nWidth, IDC_EDIT1, m_nMin, m_nMax);
- DoScroll(&m_nWidth, nSBCode, nPos, m_nMin, m_nMax, m_nStep, m_nPage);
- SetValue(m_nWidth, IDC_EDIT1, pScrollBar);
- if(m_fAspect)
- {
- m_nHeight = MulDiv(m_nWidth, m_nOrgHeight, m_nOrgWidth);
- SetValue(m_nHeight, IDC_EDIT2, &m_ScrollBar2);
- }
- }
- else
- {
- GetValue(&m_nHeight, IDC_EDIT2, m_nMin, m_nMax);
- DoScroll(&m_nHeight, nSBCode, nPos, m_nMin, m_nMax, m_nStep, m_nPage);
- SetValue(m_nHeight, IDC_EDIT2, pScrollBar);
- if(m_fAspect)
- {
- m_nWidth = MulDiv(m_nHeight, m_nOrgWidth, m_nOrgHeight);
- SetValue(m_nWidth, IDC_EDIT1, &m_ScrollBar1);
- }
- }
- }
-
- void CResizeDlg::OnCheck1()
- {
- m_fAspect = !m_fAspect;
- if(m_fAspect)
- {
- m_nHeight = MulDiv(m_nWidth, m_nOrgHeight, m_nOrgWidth);
- SetValue(m_nHeight, IDC_EDIT2, &m_ScrollBar2);
- }
- }
-
-
- BOOL CResizeDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- m_nOrgWidth = m_nWidth;
- m_nOrgHeight = m_nHeight;
- m_ScrollBar1.SetScrollRange(m_nMin, m_nMax, TRUE);
- m_ScrollBar1.SetScrollPos(m_nWidth);
- m_ScrollBar2.SetScrollRange(m_nMin, m_nMax, TRUE);
- m_ScrollBar2.SetScrollPos(m_nHeight);
-
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }