【VC开源代码栏目提醒】:网学会员--在 VC开源代码编辑为广大网友搜集整理了:CustomScroll.cpp绩等信息,祝愿广大网友取得需要的信息,参考学习。
// CustomScroll.cpp : implementation file
//
#include "stdafx.h"
#include "Skin.h"
#include "CustomScroll.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCustomScroll
CCustomScroll::CCustomScroll()
{
m_ButtonDown = FALSE;
m_IsLeft = FALSE;
m_MinRange = 0;
m_MaxRange = 200;
m_CurPos = 0;
m_IsLeftArrow = FALSE;
m_IsRightArrow = FALSE;
m_IsLeftRange = FALSE;
m_IsRightRange = FALSE;
}
CCustomScroll::~CCustomScroll()
{
}
BEGIN_MESSAGE_MAP(CCustomScroll, CStatic)
//{{AFX_MSG_MAP(CCustomScroll)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCustomScroll message handlers
BOOL CCustomScroll::CreateStatic(CWnd *pParent, DWORD dwStyle, UINT nIDStatic, UINT nID)
{
m_pParent = pParent;
ASSERT(m_pParent);
//获取父窗口中的静态文本
ASSERT(::IsWindow(pParent->GetDlgItem(nIDStatic)->m_hWnd));
CRect recttemp;
pParent->GetDlgItem(nIDStatic)->GetWindowRect(recttemp);
pParent->ScreenToClient(&recttemp);
m_ClientRect = recttemp;
pParent->GetDlgItem(nIDStatic)->ShowWindow(SW_HIDE);
BOOL ret = CStatic::Create("",dwStyle,m_ClientRect,pParent,nID);
pParent->GetDlgItem(nIDStatic)->GetClientRect(m_ClientRect);
if (ret)
{
CBitmap bmp;
bmp.LoadBitmap(m_LeftArrow);
BITMAP bInfo;
bmp.GetBitmap(&bInfo);
m_ThumbHeight = bInfo.bmHeight;
m_ThumbWidth = bInfo.bmWidth;
if (bmp.GetSafeHandle())
bmp.DeleteObject();
bmp.LoadBitmap(IDB_THUMB);
bmp.GetBitmap(&bInfo);
m_ThumbRect.CopyRect(CRect(m_ThumbWidth,0,m_ThumbWidth+bInfo.bmWidth,bInfo.bmHeight));
if (bmp.GetSafeHandle())
bmp.DeleteObject();
SetScrollRange(m_MinRange,m_MaxRange);
}
ShowWindow(SW_SHOW);
return ret;
}
void CCustomScroll::DrawControl()
{
DrawHorScroll();
}
void CCustomScroll::DrawHorScroll()
{
CClientDC dc(this);
CMemDC memdc(&dc,m_ClientRect);
CDC bmpdc;
bmpdc.CreateCompatibleDC(&dc);
CBitmap bmp;
bmp.LoadBitmap(m_LeftArrow);
CBitmap* pOldbmp = bmpdc.SelectObject(&bmp);
CRect LeftArrowRect (m_ClientRect.left,m_ClientRect.top,m_ClientRect.left+m_ThumbWidth,m_ClientRect.bottom);
memdc.StretchBlt(m_ClientRect.left,m_ClientRect.top,m_ThumbWidth,m_ThumbHeight,&bmpdc,0,0,m_ThumbWidth,m_ThumbHeight,SRCCOPY);
if (pOldbmp)
bmpdc.SelectObject(pOldbmp);
if (bmp.GetSafeHandle())
bmp.DeleteObject();
pOldbmp = NULL;
//通道的开始位置和宽度
int nChanelStart = m_ClientRect.left+m_ThumbWidth;
int nChanelWidth = m_ClientRect.Width()- 2*m_ThumbWidth;
//绘制通道
bmp.LoadBitmap(m_ChanelBK);
pOldbmp = bmpdc.SelectObject(&bmp);
memdc.StretchBlt(nChanelStart,m_ClientRect.top,nChanelWidth,m_ClientRect.Height(),&bmpdc,0,0,1,10,SRCCOPY);
if (pOldbmp)
bmpdc.SelectObject(pOldbmp);
if (bmp.GetSafeHandle())
bmp.DeleteObject();
//绘制右箭头
bmp.LoadBitmap(m_RightArrow);
pOldbmp = bmpdc.SelectObject(&bmp);
int nRArrowStart = m_ThumbWidth+nChanelWidth;
memdc.StretchBlt(nRArrowStart,m_ClientRect.top,m_ThumbWidth,m_ClientRect.Height(),&bmpdc,0,0,m_ThumbWidth,m_ThumbHeight,SRCCOPY);
//绘制滚动块
if (bmp.GetSafeHandle())
bmp.DeleteObject();
bmp.LoadBitmap(m_ThumbBK);
pOldbmp = bmpdc.SelectObject(&bmp);
memd