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

📄 bcgpslider.cpp

📁 远程网络监视程序的源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// BCGPSlider.cpp : implementation file
//

#include "stdafx.h"

#include "BCGGlobals.h"
#include "BCGPSlider.h"
#include "BCGPDockingControlBar.h"
#include "BCGPBarContainerManager.h"
#include "BCGPBarContainer.h"
#include "BCGPGlobalUtils.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

IMPLEMENT_DYNCREATE(CBCGPSlider,CBCGPBaseControlBar)

int CBCGPSlider::m_nDefaultWidth = 4;

/////////////////////////////////////////////////////////////////////////////
// CBCGPSlider
//--------------------------------------------------------------------------//
CBCGPSlider::CBCGPSlider (BOOL bDefaultSlider, CWnd* pParentWnd) : m_nID ((UINT)-1), m_dwSliderStyle (0), 
												 m_nWidth (0), 
												 m_bCaptured (false), 
												 m_pContainerManager (NULL),
												 m_bDefaultSlider (bDefaultSlider)
{
	m_rectLastDragRect.SetRectEmpty ();	
	m_rectDragBounds.SetRectEmpty ();
	m_nMinOffset = 0;  
	m_nMaxOffset = 0; 
	m_nStep		 = -1;
	m_bAutoHideMode = FALSE;
	m_pParentWndForSerialize = pParentWnd;
	
}
//--------------------------------------------------------------------------//
CBCGPSlider::~CBCGPSlider()
{
	
}
//--------------------------------------------------------------------------//
BEGIN_MESSAGE_MAP(CBCGPSlider, CBCGPBaseControlBar)
	//{{AFX_MSG_MAP(CBCGPSlider)
	ON_WM_SIZE()
	ON_WM_SETCURSOR()
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_MOUSEMOVE()
	ON_WM_PAINT()
	ON_WM_ERASEBKGND()
	ON_WM_NCDESTROY()
	ON_WM_DESTROY()
	ON_WM_CREATE()
	ON_WM_CANCELMODE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBCGPSlider message handlers
//--------------------------------------------------------------------------//
BOOL CBCGPSlider::Create (DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, 
						 CCreateContext* pContext) 
{
	ASSERT_VALID (this);

	
	return CBCGPSlider::CreateEx(0L, dwStyle, rect, pParentWnd, nID, pContext);
}
//--------------------------------------------------------------------------//
BOOL CBCGPSlider::CreateEx(DWORD dwStyleEx, DWORD dwStyle, const RECT& rect, 
						  CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
	ASSERT_VALID (this);

	//-----------------------------
	// Register a new window class:
	//-----------------------------
	HINSTANCE hInst = AfxGetInstanceHandle();
	UINT uiClassStyle = CS_DBLCLKS;
	HCURSOR hCursor = ::LoadCursor (NULL, IDC_ARROW);
	HBRUSH hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);

	CString strClassName;
	strClassName.Format (_T("BCGSlider:%x:%x:%x:%x"), 
		(UINT)hInst, uiClassStyle, (UINT)hCursor, (UINT)hbrBackground);

	//---------------------------------
	// See if the class already exists:
	//---------------------------------
	WNDCLASS wndcls;
	if (::GetClassInfo (hInst, strClassName, &wndcls))
	{
		//-----------------------------------------------
		// Already registered, assert everything is good:
		//-----------------------------------------------
		ASSERT (wndcls.style == uiClassStyle);
	}
	else
	{
		//-------------------------------------------
		// Otherwise we need to register a new class:
		//-------------------------------------------
		wndcls.style = uiClassStyle;
		wndcls.lpfnWndProc = ::DefWindowProc;
		wndcls.cbClsExtra = wndcls.cbWndExtra = 0;
		wndcls.hInstance = hInst;
		wndcls.hIcon = NULL;
		wndcls.hCursor = hCursor;
		wndcls.hbrBackground = hbrBackground;
		wndcls.lpszMenuName = NULL;
		wndcls.lpszClassName = strClassName;
		
		if (!AfxRegisterClass (&wndcls))
		{
			AfxThrowResourceException();
		}
	}

	m_nID = nID;
	m_dwSliderStyle = dwStyle;

	if (m_dwSliderStyle & SS_VERT)
	{
		m_nWidth = rect.right - rect.left;
	}
	else if (m_dwSliderStyle & SS_HORZ)
	{
		m_nWidth = rect.bottom - rect.top;
	}

	DWORD dwSliderStyle = m_dwSliderStyle | WS_CHILDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;

	if (m_bDefaultSlider)
	{
		m_pContainerManager = new CBCGPBarContainerManager;
		m_pContainerManager->Create (pParentWnd, this);
	}

	m_pDockSite = DYNAMIC_DOWNCAST (CFrameWnd, pParentWnd);

	if (m_pDockSite == NULL)
	{
		m_pDockSite = BCGPGetParentFrame (pParentWnd);
	}

	if (m_pDockSite == NULL)
	{
		ASSERT (FALSE);
	}

	return CWnd::CreateEx (dwStyleEx, strClassName, NULL, dwSliderStyle, rect, pParentWnd, nID, pContext);
}
//--------------------------------------------------------------------------//
void CBCGPSlider::Serialize (CArchive& ar)
{
	ASSERT_VALID (this);
	CBCGPBaseControlBar::Serialize (ar);

	CRect rect;
	
	if (ar.IsStoring ())
	{
		GetWindowRect (rect);
		GetParent ()->ScreenToClient (rect);

		ar << m_nID;
		ar << m_nStep;
		ar << rect;
		ar << IsWindowVisible ();	
		ar << m_dwSliderStyle;
		ar << m_nWidth;
		ar << m_bDefaultSlider;
		ar << m_nMinOffset;
		ar << m_nMaxOffset;
	}
	else
	{
		BOOL bVisible = FALSE;

		ar >> m_nID;
		ar >> m_nStep;
		ar >> rect;
		ar >> bVisible;
		ar >> m_dwSliderStyle;
		ar >> m_nWidth;
		ar >> m_bDefaultSlider;
		ar >> m_nMinOffset;
		ar >> m_nMaxOffset;

		if (bVisible)
		{
			m_dwSliderStyle |= WS_VISIBLE;
		}
		else
		{
			m_dwSliderStyle &= ~WS_VISIBLE;
		}

		if (!CreateEx (0, m_dwSliderStyle, rect, m_pParentWndForSerialize, m_nID, NULL))
		{
			TRACE0 ("Unable to create slider from archive");
		}
	}

	if (m_pContainerManager != NULL && m_bDefaultSlider)
	{
		m_pContainerManager->Serialize (ar);
	}

}
//--------------------------------------------------------------------------//
CBCGPDockingControlBar* CBCGPSlider::FindTabbedBar (UINT nID)
{
	ASSERT_VALID (this);
	if (m_pContainerManager != NULL)
	{
		return m_pContainerManager->FindTabbedBar (nID);
	}
	return NULL;
}
//--------------------------------------------------------------------------//
void CBCGPSlider::OnSize(UINT nType, int cx, int cy) 
{
	ASSERT_VALID (this);
	CWnd::OnSize(nType, cx, cy);
}
//--------------------------------------------------------------------------//
BOOL CBCGPSlider::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
{
	ASSERT_VALID (this);

	switch (nHitTest)
	{
	case HTCLIENT:
		if (m_dwSliderStyle & SS_HORZ)
		{
			SetCursor (globalData.m_hcurStretchVert);
		}
		else if (m_dwSliderStyle & SS_VERT) 
		{
			SetCursor (globalData.m_hcurStretch);
		}
		return TRUE;
	}

	return CWnd::OnSetCursor(pWnd, nHitTest, message);
}
//--------------------------------------------------------------------------//
void CBCGPSlider::OnLButtonDown(UINT nFlags, CPoint point) 
{
	ASSERT_VALID (this);
	if (!m_bCaptured)
	{
		m_bCaptured = true;
		SetCapture ();

		CRect rectSlider;
		GetWindowRect (rectSlider);
		CSize size (m_nWidth / 2, m_nWidth / 2);
		CWindowDC dc (GetDesktopWindow ());
		dc.DrawDragRect (&rectSlider, size, NULL, size);

		m_rectLastDragRect = rectSlider;

		m_pContainerManager->GetMinMaxOffset (this, m_nMinOffset, m_nMaxOffset, m_nStep);
		m_rectDragBounds = rectSlider;
		if (IsHorizontal ())
		{
			m_rectDragBounds.top = rectSlider.top + m_nMinOffset;
			m_rectDragBounds.bottom = rectSlider.bottom + m_nMaxOffset;
		}
		else
		{
			m_rectDragBounds.left = rectSlider.left + m_nMinOffset;
			m_rectDragBounds.right = rectSlider.right + m_nMaxOffset;
		}

		if (m_pContainerManager != NULL)
		{
			m_pContainerManager->SetResizeMode (TRUE);
		}
	}
	
	CWnd::OnLButtonDown(nFlags, point);
}
//--------------------------------------------------------------------------//
void CBCGPSlider::OnLButtonUp(UINT nFlags, CPoint point) 
{
	ASSERT_VALID (this);
	
	StopTracking (TRUE);
	CWnd::OnLButtonUp(nFlags, point);
}
//--------------------------------------------------------------------------//
void CBCGPSlider::OnMouseMove(UINT nFlags, CPoint point) 
{
	ASSERT_VALID (this);
	if (m_bCaptured)
	{
		CRect rectNew = m_rectLastDragRect;

		CPoint ptNew;
		GetCursorPos (&ptNew);

		if (m_dwSliderStyle & SS_VERT)
		{
			rectNew.left = ptNew.x - m_nWidth / 2;
			rectNew.right = rectNew.left + m_nWidth;
			if (rectNew.left < m_rectDragBounds.left)
			{
				rectNew.left = m_rectDragBounds.left;
				rectNew.right = rectNew.left + m_rectLastDragRect.Width ();
			}

			if (rectNew.right > m_rectDragBounds.right)
			{
				rectNew.right = m_rectDragBounds.right;
				rectNew.left = rectNew.right - m_rectLastDragRect.Width ();
			}
		}
		else
		{
			rectNew.top = ptNew.y - m_nWidth / 2;
			rectNew.bottom = rectNew.top + m_nWidth;
			if (rectNew.top < m_rectDragBounds.top)
			{
				rectNew.top = m_rectDragBounds.top;
				rectNew.bottom = rectNew.top + m_nWidth;
			}

			if (rectNew.bottom > m_rectDragBounds.bottom)
			{
				rectNew.bottom = m_rectDragBounds.bottom;
				rectNew.top = rectNew.bottom - m_nWidth;
			}
		}
		
		CSize size (m_nWidth / 2, m_nWidth / 2);
		CWindowDC dc (GetDesktopWindow ());
		dc.DrawDragRect (&rectNew, size, &m_rectLastDragRect, size);
		m_rectLastDragRect = rectNew;
	}
	
	CWnd::OnMouseMove(nFlags, point);
}
//--------------------------------------------------------------------------//
void CBCGPSlider::OnCancelMode ()
{
	StopTracking (FALSE);
	CBCGPBaseControlBar::OnCancelMode ();
}
//--------------------------------------------------------------------------//
void CBCGPSlider::StopTracking (BOOL bMoveSlider)
{
	if (m_bCaptured)
	{
		CRect rectSlider;
		GetWindowRect (rectSlider);

		CPoint ptOffset = m_rectLastDragRect.TopLeft () - rectSlider.TopLeft ();

		CRect rectEmpty;
		rectEmpty.SetRectEmpty ();	

		CWindowDC dc (NULL);
		CSize size (m_nWidth / 2, m_nWidth / 2);
		dc.DrawDragRect (&rectEmpty, size, &m_rectLastDragRect, size);
		
		if (bMoveSlider)
		{
			MoveSlider (ptOffset);	
		}
		
		m_rectLastDragRect.SetRectEmpty ();

		ReleaseCapture ();
		m_bCaptured = false;

		if (m_pContainerManager != NULL)
		{
			m_pContainerManager->SetResizeMode (FALSE);
		}
	}
}
//--------------------------------------------------------------------------//
void CBCGPSlider::OnPaint() 
{
	ASSERT_VALID (this);
	CPaintDC dc(this); // device context for painting

	CRect rectClient;
	GetClientRect (rectClient);
	CBCGPVisualManager::GetInstance ()->OnDrawSlider (&dc, this, rectClient, m_bAutoHideMode);
}
//--------------------------------------------------------------------------//
void CBCGPSlider::MoveSlider (CPoint& ptOffset, BOOL bAdjustLayout)
{
	ASSERT_VALID (this);
	
	CRect rectSlider;
	GetWindowRect (rectSlider);

	int nOffset = 0;
	if (m_dwSliderStyle & SS_VERT)
	{
		nOffset = ptOffset.x;
		rectSlider.OffsetRect (nOffset, 0);
	}
	else if (m_dwSliderStyle & SS_HORZ)
	{
		nOffset = ptOffset.y;
		rectSlider.OffsetRect (0, nOffset);
	}
	else
	{

⌨️ 快捷键说明

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