⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tbarctrlbase.cpp

📁 BCAM 1394 Driver
💻 CPP
字号:
//-----------------------------------------------------------------------------
//  (c) 2002 by Basler Vision Technologies
//  Section:  Vision Components
//  Project:  BCAM
//  $Header: TBarCtrlBase.cpp, 2, 02.10.2002 14:31:28, Nebelung, H.$
//-----------------------------------------------------------------------------
/**
\file     TBarCtrlBase.cpp
\brief    implementation of the CTBarCtrlBase class.
*/
//////////////////////////////////////////////////////////////////////

#include <atlbase.h>
#include <atlapp.h>
extern  CAppModule _Module;
#include <atlwin.h>

#include "math.h"
#include "float.h"
#include "stdio.h"
#include "limits.h"

#include "TBarCtrlBase.h"
#include "ChkRecursion.h"

//////////////////////////////////////////////////////////////////////
// 

CTBarCtrlBase::CTBarCtrlBase()
{
  m_nRangeMin              = 0;
  m_nRangeMax              = SHRT_MAX;
  m_nRangeAbs    = SHRT_MAX;
  
  m_dRangeMinRnd = m_dRangeMin = 0.0;
  m_dRangeMaxRnd = m_dRangeMax = SHRT_MAX;
  m_dRangeAbs    = SHRT_MAX;
  
  m_nScaleFactor = 1;
  m_dScaleFactor = 1.0;
  
  m_hTBarCtrl                             = NULL;
  m_nTBarCtrlID                   = 0;
  m_nTxtLCtrlID                   = 0;
  m_hTxtL                                         = NULL;
  m_nTxtRCtrlID                   = 0;
  m_hTxtR                                         = NULL;
  m_nTxtThumbCtrlID = 0;
  m_hTxtThumb                             = NULL;
}

//////////////////////////////////////////////////////////////////////
// 

/**********
* UpdateThumb - Update thumb of assigned TrackBar and Thumb Static control
* 
* \param       nValue                          Thumb position and thumb text will be set to this value
* \param       bTrackThumb             if false, the thumb position will not be changed. Only
*                                                                                      the thumb text will be changed
*/
void CTBarCtrlBase::UpdateThumb(int nValue, bool bTrackThumb /*= true*/)
{
  static                          int     nRecursivCalls = 0;
  CChkRecursion   cChkRecursion(&nRecursivCalls);
  ATLASSERT( cChkRecursion.Check(2) == false );
  
  // update the thumb text
  if ( m_ctrlTxtThumb.IsWindow() )
  {
    char    szBuf[256];
    FmtValue(szBuf, nValue);
    m_ctrlTxtThumb.SetWindowText(szBuf);
  }
  
  // update the thumb position
  if ( CTBarCtrlBase::IsWindow() && bTrackThumb )
  {
    int     nThumbPosNew = nValue / m_nScaleFactor;
    int nThumbPosCur = CTBarCtrlBase::GetPos();
    
    //              ATLTRACE("CTBarEditCtrl::TrackThumb n=%d v=%d\n", nThumbPosNew, nValue);
    
    nThumbPosNew = (nValue <= m_nRangeMin) ? m_nRangeMin : nThumbPosNew;
    nThumbPosNew = (nValue >= m_nRangeMax) ? m_nRangeMax : nThumbPosNew;
    
    nThumbPosNew = (nThumbPosNew < m_nRangeMin) ? m_nRangeMin : nThumbPosNew;
    nThumbPosNew = (nThumbPosNew > m_nRangeMax) ? m_nRangeMax : nThumbPosNew;
    
    if ( nThumbPosNew != nThumbPosCur )
      CTrackBarCtrl::SetPos(nThumbPosNew);
  }
}

/**********
* UpdateThumb - Update thumb of assigned TrackBar and Thumb Static control
* 
* \param       dValue                          Thumb position and thumb text will be set to this value
* \param       bTrackThumb             if false, the thumb position will not be changed. Only
*                                                                                      the thumb text will be changed
*/
void CTBarCtrlBase::UpdateThumb(double dValue, bool bTrackThumb /*= true*/)
{
  static                          int     nRecursivCalls = 0;
  CChkRecursion   cChkRecursion(&nRecursivCalls);
  ATLASSERT( cChkRecursion.Check(2) == false );
  
  // update the thumb text
  if ( m_ctrlTxtThumb.IsWindow() )
  {
    char    szBuf[256];
    FmtValue(szBuf, dValue);
    m_ctrlTxtThumb.SetWindowText(szBuf);
  }
  
  // update the thumb position
  if ( CTBarCtrlBase::IsWindow() && bTrackThumb )
  {
    int     nThumbPosNew = (int)(dValue / m_dScaleFactor);
    int nThumbPosCur = CTBarCtrlBase::GetPos();
    
    // don't update thumb position if difference is less than...
    if ( fabs((nThumbPosNew * m_dScaleFactor) - (nThumbPosCur * m_dScaleFactor)) < (m_dScaleFactor + DBL_EPSILON) )
      return ;
    
    ATLTRACE("CTBarEditCtrl::TrackThumb n=%d v=%g\n", nThumbPosNew, dValue);
    
    // if dValue is near or greater than the range borders...
    if ( dValue <= m_dRangeMinRnd || fabs(dValue - m_dRangeMinRnd) <= DBL_EPSILON )
      nThumbPosNew = m_nRangeMin;
    
    if ( dValue >= m_dRangeMaxRnd || fabs(dValue - m_dRangeMaxRnd) <= DBL_EPSILON )
      nThumbPosNew = m_nRangeMax;
    
    nThumbPosNew = (nThumbPosNew < m_nRangeMin) ? m_nRangeMin : nThumbPosNew;
    nThumbPosNew = (nThumbPosNew > m_nRangeMax) ? m_nRangeMax : nThumbPosNew;
    
    if ( nThumbPosNew != nThumbPosCur )
      CTrackBarCtrl::SetPos(nThumbPosNew);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -