home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 6 / mastvb6.iso / leadtools / ocx32.lt / RESIZEDL.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-10  |  5.3 KB  |  195 lines

  1. // resizedl.cpp : implementation file
  2. // Copyright (C) 1996 LEAD Technologies, Inc.
  3. // All rights reserved.
  4.  
  5. #include "stdafx.h"
  6. #include "mfcdemo.h"
  7. #include "resizedl.h"
  8.  
  9. #ifdef _DEBUG
  10. #undef THIS_FILE
  11. static char BASED_CODE THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CResizeDlg dialog
  16.  
  17.  
  18. CResizeDlg::CResizeDlg(CWnd* pParent /*=NULL*/)
  19.     : CDialog(CResizeDlg::IDD, pParent)
  20. {
  21.     //{{AFX_DATA_INIT(CResizeDlg)
  22.     m_nWidth = 0;
  23.     m_nHeight = 0;
  24.         m_nOrgWidth = 0;        
  25.         m_nOrgHeight = 0;        
  26.     m_fResample = FALSE;
  27.         m_nMin = 1;
  28.         m_nMax = 16384;
  29.         m_nStep = 10;
  30.         m_nPage = 100;
  31.     m_fAspect = TRUE;
  32.     //}}AFX_DATA_INIT
  33. }
  34.  
  35.  
  36. void CResizeDlg::DoDataExchange(CDataExchange* pDX)
  37. {
  38.     CDialog::DoDataExchange(pDX);
  39.     //{{AFX_DATA_MAP(CResizeDlg)
  40.     DDX_Control(pDX, IDC_SCROLLBAR2, m_ScrollBar2);
  41.     DDX_Control(pDX, IDC_SCROLLBAR1, m_ScrollBar1);
  42.     DDX_Text(pDX, IDC_EDIT1, m_nWidth);
  43.     DDV_MinMaxInt(pDX, m_nWidth, m_nMin, m_nMax);
  44.     DDX_Text(pDX, IDC_EDIT2, m_nHeight);
  45.     DDV_MinMaxInt(pDX, m_nHeight, m_nMin, m_nMax);
  46.     DDX_Check(pDX, IDC_CHECK2, m_fResample);
  47.     DDX_Check(pDX, IDC_CHECK1, m_fAspect);
  48.     //}}AFX_DATA_MAP
  49. }
  50.  
  51.  
  52. BEGIN_MESSAGE_MAP(CResizeDlg, CDialog)
  53.     //{{AFX_MSG_MAP(CResizeDlg)
  54.     ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
  55.     ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2)
  56.     ON_WM_HSCROLL()
  57.     ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
  58.     //}}AFX_MSG_MAP
  59. END_MESSAGE_MAP()
  60.  
  61.  
  62. BOOL CResizeDlg::GetValue(LPINT pValue, int nEditID, int nMin, int nMax)
  63. {
  64.         BOOL fTranslated;
  65.         int n;
  66.         n = GetDlgItemInt (nEditID, &fTranslated, TRUE);
  67.         if (!fTranslated || n < nMin || n > nMax)
  68.                 return(FALSE);
  69.         *pValue = n;
  70.         return(TRUE);
  71. }
  72.  
  73. void CResizeDlg::SetValue(int nValue, int nEditID, CScrollBar *pScrollBar)
  74. {
  75.         pScrollBar->SetScrollPos(nValue);
  76.         SetDlgItemInt (nEditID, nValue, TRUE);
  77. }
  78.  
  79. void CResizeDlg::DoScroll(LPINT pValue, UINT nSBCode, UINT nPos, int nMin, int nMax, int nStep, int nPage)
  80. {
  81.       switch (nSBCode)
  82.       {
  83.       case SB_LEFT:
  84.          *pValue = nMin;
  85.          break;
  86.       case SB_RIGHT:
  87.          *pValue = nMax;
  88.          break;
  89.       case SB_THUMBPOSITION:
  90.       case SB_THUMBTRACK:
  91.          *pValue = (int) nPos;
  92.          break;
  93.       case SB_LINELEFT:
  94.          *pValue = max (*pValue - nStep, nMin);
  95.          break;
  96.       case SB_LINERIGHT:
  97.          *pValue = min (*pValue + nStep, nMax);
  98.          break;
  99.       case SB_PAGELEFT:
  100.          *pValue = max (*pValue - nPage, nMin);
  101.          break;
  102.       case SB_PAGERIGHT:
  103.          *pValue = min (*pValue + nPage, nMax);
  104.          break;
  105.       }
  106. }
  107.  
  108. /////////////////////////////////////////////////////////////////////////////
  109. // CResizeDlg message handlers
  110.  
  111. void CResizeDlg::OnChangeEdit1() 
  112. {
  113.       if(GetValue(&m_nWidth, IDC_EDIT1, m_nMin, m_nMax))
  114.       {
  115.                 m_ScrollBar1.SetScrollPos(m_nWidth);
  116.                 if(m_fAspect)
  117.                 {
  118.                   m_fAspect = FALSE;
  119.                   m_nHeight = MulDiv(m_nWidth, m_nOrgHeight, m_nOrgWidth);
  120.                   SetValue(m_nHeight, IDC_EDIT2, &m_ScrollBar2);
  121.                   m_fAspect = TRUE;
  122.                 }
  123.       }
  124. }
  125.  
  126. void CResizeDlg::OnChangeEdit2() 
  127. {
  128.       if(GetValue(&m_nHeight, IDC_EDIT2, m_nMin, m_nMax))
  129.       {
  130.                 m_ScrollBar2.SetScrollPos(m_nHeight);
  131.                 if(m_fAspect)
  132.                 {
  133.                   m_fAspect = FALSE;
  134.                   m_nWidth = MulDiv(m_nHeight, m_nOrgWidth, m_nOrgHeight);
  135.                   SetValue(m_nWidth, IDC_EDIT1, &m_ScrollBar1);
  136.                   m_fAspect = TRUE;
  137.                 }
  138.      }
  139. }
  140.  
  141.  
  142.  
  143. void CResizeDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  144. {
  145.  
  146.       if(pScrollBar->GetDlgCtrlID() == IDC_SCROLLBAR1)
  147.       {
  148.          GetValue(&m_nWidth, IDC_EDIT1, m_nMin, m_nMax);
  149.          DoScroll(&m_nWidth, nSBCode, nPos, m_nMin, m_nMax, m_nStep, m_nPage);
  150.          SetValue(m_nWidth, IDC_EDIT1, pScrollBar);
  151.          if(m_fAspect)
  152.          {
  153.             m_nHeight = MulDiv(m_nWidth, m_nOrgHeight, m_nOrgWidth);
  154.             SetValue(m_nHeight, IDC_EDIT2, &m_ScrollBar2);
  155.          }
  156.       }
  157.       else
  158.       {
  159.          GetValue(&m_nHeight, IDC_EDIT2, m_nMin, m_nMax);
  160.          DoScroll(&m_nHeight, nSBCode, nPos, m_nMin, m_nMax, m_nStep, m_nPage);
  161.          SetValue(m_nHeight, IDC_EDIT2, pScrollBar);
  162.          if(m_fAspect)
  163.          {
  164.             m_nWidth = MulDiv(m_nHeight, m_nOrgWidth, m_nOrgHeight);
  165.             SetValue(m_nWidth, IDC_EDIT1, &m_ScrollBar1);
  166.          }
  167.       }
  168. }
  169.  
  170. void CResizeDlg::OnCheck1() 
  171. {
  172.         m_fAspect = !m_fAspect;
  173.         if(m_fAspect)
  174.         {
  175.            m_nHeight = MulDiv(m_nWidth, m_nOrgHeight, m_nOrgWidth);
  176.            SetValue(m_nHeight, IDC_EDIT2, &m_ScrollBar2);
  177.         }
  178. }
  179.  
  180.  
  181. BOOL CResizeDlg::OnInitDialog() 
  182. {
  183.     CDialog::OnInitDialog();
  184.     
  185.         m_nOrgWidth = m_nWidth;
  186.         m_nOrgHeight = m_nHeight;
  187.         m_ScrollBar1.SetScrollRange(m_nMin, m_nMax, TRUE);
  188.         m_ScrollBar1.SetScrollPos(m_nWidth);
  189.         m_ScrollBar2.SetScrollRange(m_nMin, m_nMax, TRUE);
  190.         m_ScrollBar2.SetScrollPos(m_nHeight);
  191.     
  192.     return TRUE;  // return TRUE unless you set the focus to a control
  193.                   // EXCEPTION: OCX Property Pages should return FALSE
  194. }
  195.