// BitmapSlider.cpp : implementation file
//
#include "stdafx.h"
#include "BitmapSlider.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
//
// CBitmapSlider v1.5
//
// It's free for everywhere - 16/September/2003 - Joon-ho Ryu
//
/////////////////////////////////////////////////////////////////////////////
CBitmapSlider::CBitmapSlider()
{
m_nPos = m_nMin = 0;
m_nMax = 100;
m_nPage = 20;
m_nMarginLeft = m_nMarginRight = m_nMarginTop = m_nMarginBottom = 0;
m_nThumbWidth = m_nThumbHeight = 0;
m_bChannel = m_bVertical = m_bThumb = m_bLButtonDown = m_bThumbDisable = FALSE;
m_bFocusRect = m_bFocus = FALSE;
m_bDrawFocusRect = FALSE;
m_bCustomerSetLength = FALSE;
m_bEnable = TRUE;
m_nThumbBgX = m_nThumbBgY = -1;
}
CBitmapSlider::~CBitmapSlider()
{
}
BEGIN_MESSAGE_MAP(CBitmapSlider, CStatic)
//{{AFX_MSG_MAP(CBitmapSlider)
ON_WM_ERASEBKGND()
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
ON_WM_GETDLGCODE()
ON_WM_KEYDOWN()
ON_WM_KILLFOCUS()
ON_WM_SETFOCUS()
ON_WM_CREATE()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBitmapSlider message handlers
BOOL CBitmapSlider::OnEraseBkgnd(CDC* pDC)
{
// Do not erase background for the transparency effect
return TRUE;
}
// Draw channel and thumb
//
void CBitmapSlider::OnPaint()
{
CPaintDC dcOrigin(this);
// "Flicker Free Drawing In MFC" by Keith Rule
CMemDC dc( &dcOrigin, &m_rect, m_bTransparentChannel );
CDC dcMem;
dcMem.CreateCompatibleDC( &dc );
CBitmap *pbmTmp;
// Delete focus rectangle for transparent channel
if( m_bFocusRect && ( m_bTransparentChannel || !m_bChannel ) ) {
dc.DrawFocusRect( m_rect );
m_bFocusRect = FALSE;
}
// Draw channel
if( m_bChannel ) {
pbmTmp = dcMem.SelectObject( &m_bmChannel );
// There is a bitmap for active channel
if( m_bChannelActive && (m_bEnable || (m_bThumbDisable && !m_bEnable))) {
// Vertical slider
if( m_bVertical ) {
// Lower part
DrawBitmap( &dc, 0, Pos2Pixel(m_nPos),
m_nWidth, m_nHeight - Pos2Pixel(m_nPos),
&dcMem, 0, Pos2Pixel(m_nPos),
&m_bmChannelActiveMask, m_bTransparentChannel );
dcMem.SelectObject( &m_bmChannelActive );
// Upper part
DrawBitmap( &dc, 0, 0, m_nWidth, Pos2Pixel(m_nPos),
&dcMem, 0, 0, &m_bmChannelMask, m_bTransparentChannel );
// Horizontal slider
} else {
// Right side
DrawBitmap( &dc, Pos2Pixel(m_nPos), 0,
m_nWidth - Pos2Pixel(m_nPos), m_nHeight,
&dcMem, Pos2Pixel(m_nPos), 0,
&m_bmChannelActiveMask, m_bTransparentChannel );
dcMem.SelectObject( &m_bmChannelActive );
// Left side
DrawBitmap( &dc, 0, 0, Pos2Pixel(m_nPos), m_nHeight,
&dcMem, 0, 0, &m_bmChannelMask, m_bTransparentChannel );
}
// Only one bitmap for channel
} else {
DrawBitmap( &dc, 0, 0, m_nWidth, m_nHeight,
&dcMem, 0, 0, &m_bmChannelMask, m_bTransparentChannel );
}
dcMem.SelectObject( pbmTmp );
}
// If there is a bitmap to restore background image of a thumb
if( m_nThumbBgX != -1 ) {
RestoreBackground(
&dc, m_nThumbBgX, m_nThumbBgY,
m_nThumbWidth, m_nThumbHeight, &m_bmThumbBg );
m_nThumbBgX = -1;
}
// Draw thumb
if( m_bThumb && (m_bEnable || (m_bThumbDisable && !m_bEnable))) {
//if( m_bThumb ) {
if( m_bThumbActive && m_bLButtonDown && m_bEnable)
pbmTmp = dcMem.SelectObject( &m_bmThumbActive ); // Active thumb
else if(m_bThumbDisable && !m_bEnable)
pbmTmp = dcMem.SelectObject( &m_bmThumbDisable ); // Disable thumb
else
pbmTmp = dcMem.SelectObject( &m_bmThumb ); // Normal thumb
// Vertical slider
if( m_bVertical ) {
// Background image is need to be restored
if( m_bTransparentChannel || !m_bChannel ) {
m_nThumbBgX = m_nMarginLeft;
m_nThumbBgY = Pos2Pixel(m_nPos) - m_nThumbHeight/2;
CopyBackground(
&dc, m_nThumbBgX, m_nThumbBgY,
m_nThumbWidth, m_nThumbHeight, &m_bmThumbBg );
}
DrawBitmap(
&dc, m_nMarginLeft, Pos2Pixel(m_nPos) - m_nThumbHeight/2,
m_nThumbWidth, m_nThumbHeight,
&dcMem, 0, 0, &m_bmThumbMask, m_bTransparentThumb );
// Horizontal slider
} else {
// Background image is need to be restored
if( m_bTransparentChannel || !m_bChannel ) {
m_nThumbBgX = Pos2Pixel(m_nPos) - m_nThumbWidth/2;
m_nThumbBgY = m_nMarginTop;
CopyBackground(
&dc, m_nThumbBgX, m_nThumbBgY,
m_nThumbWidth, m_nThumbHeight, &m_bmThumbBg );
}
DrawBitmap(
&dc, Pos2Pixel(m_nPos) - m_nThumbWidth/2, m_nMarginTop,
m_nThumbWidth, m_nThumbHeight,
&dcMem, 0, 0, &m_bmThumbMask, m_bTransparentThumb );
} // if horizontal
dcMem.SelectObject( pbmTmp );
} // if draw thumb
// Draw focus rectangle
if( m_bDrawFocusRect && m_bFocus && m_bEnable ) {
dc.DrawFocusRect( m_rect );
m_bFocusRect = TRUE;
}
dcMem.DeleteDC();
}
// Sets the maximum range for the slider.
//
// Parameters:
// [IN] nMax
// Maximum position for the slider.
// [IN] bRedraw
// TRUE to redraw after the range is set.
// FALSE to only change maximum position.
//
void CBitmapSlider::SetRangeMax(int nMax, BOOL bRedraw)
{
m_nMax = nMax;
if( bRedraw )
Invalidate();
}
// Sets the minimum range for the slider.
//
// Parameters:
// [IN] nMin
// Minimum position for the slider.
// [IN] bRedraw
// TRUE to redraw after the range is set.
// FALSE to only change minimum position.
//
void CBitmapSlider::SetRangeMin(int nMin, BOOL bRedraw)
{
m_nMin = nMin;
if( bRedraw )
Invalidate();
}
// Sets the range (minimum and maximum positions) for the slider.
//
// Parameters:
// [IN] nMin
// Minimum position for the slider.
// [IN] nMax
// Maximum position for the slider.
// [IN] bRedraw
// TRUE to redraw after the range is set.
// FALSE to only change the range.
//
void CBitmapSlider::SetRange(int nMin, int nMax, BOOL bRedraw)
{
SetRangeMin( nMin, FALSE );
SetRangeMax( nMax, bRedraw );
}
// Sets the current position of the slider.
//
// Parameters:
// [IN] nPos
// Specifies the new slider position.
//
void CBitmapSlider::SetPos(int nPos)
{
m_nPos = nPos;
// Boundary check
if( m_nPos > m_nMax )
m_nPos = m_nMax;
if( m_nPos < m_nMin )
m_nPos = m_nMin;
Invalidate();
}
// Sets the size of the page for a control.
//
// Parameters:
// [IN] nSize
// The new page size of the control.
//
// Return value:
// The previous page size.
//
int CBitmapSlider::SetPageSize(int nSize)
{
int nRet = m_nPage;
m_nPage = nSize;
return nRet;
}
// Sets the left, top, right, and bottom margins for a control
//
void CBitmapSlider::SetMargin(int nLeft, int nTop, int nRight, int nBottom )
{
SetMarginLeft( nLeft );
SetMarginTop( nTop );
SetMarginRight( nRight );
SetMarginBottom( nBottom );
}
// Enables or disables control.
//
// [IN] bEnable
// TRUE to enable control.
// FALSE to disable control.
//
void CBitmapSlider::Enable(BOOL bEnable)
{
m_bEnable = bEnable;
// If control is disabled during dragging
if( !m_bEnable && m_bLButtonDown ) {
m_bLButtonDown = FALSE;
ReleaseCapture();
}
Invalidate();
}
// Specify whether draw focus rectangle or not.
//
// [IN] bDraw
// TRUE to draw focus rectangle.
// FALSE to hide focus rectangle.
//
// [IN] bRedraw
// TRUE to redraw status is changed.
// FALSE to only change the status.
//
void CBitmapSlider::DrawFocusRect(BOOL bDraw, BOOL bRedraw)
{
m_bDrawFocusRect = bDraw;
if( bRedraw )
Invalidate();
}
// Load bitmaps for a channel
//
//
任意贴图的slider控件
4星 · 超过85%的资源 需积分: 9 192 浏览量
2009-07-28
11:40:53
上传
评论
收藏 181KB RAR 举报
zpf82118
- 粉丝: 35
- 资源: 39
最新资源
- 最全空间计量实证方法(空间杜宾模型和检验以及结果解释文档).txt
- 5uonly.apk
- 蓝桥杯Python组的历年真题
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 前端开发技术实验报告:内含4四实验&实验报告
- Highlight Plus v20.0.1
- 林周瑜-论文.docx
- 基于MIC+NE555光敏电阻的声光控电路Multisim仿真原理图
- 基于JSP毕业设计-基于WEB操作系统课程教学网站的设计与实现(源代码+论文).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
前往页