XPSliderCtrl.cpp
上传用户:chly668
上传日期:2010-03-08
资源大小:3k
文件大小:7k
- // XPSliderCtrl.cpp : implementation file
- //
- #include "stdafx.h"
- #include "Recorder.h"
- #include "XPSliderCtrl.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CXPSliderCtrl
- CXPSliderCtrl::CXPSliderCtrl()
- {
- bFocus = FALSE;
- m_bFlagChanelHeit = FALSE;
- m_bFlagChanelLen = FALSE;
- m_bFlagThumbWid = FALSE;
- m_bFlagThumbHeit = FALSE;
- m_iChanelLeft = 0;
- m_iChanelRight = 0;
- m_iChanelBottom = 0;
- m_iChanelTop = 0;
- m_iThumWid = 0;
- m_iThumHeit = 0;
-
- pBackBrush.CreateSolidBrush(RGB(192, 192, 192));
- pSelBackBrush.CreateSolidBrush(RGB(160, 160, 192));
-
- nSelThumbPen.CreatePen(PS_SOLID, 1, RGB(166, 202, 240));
- nUnselThumbPen.CreatePen(PS_SOLID, 1, RGB(255, 255, 255));
- nDarkPen.CreatePen(PS_SOLID, 1, RGB(128, 128, 128));
- nGreyBrush.CreateSolidBrush(RGB(204, 204, 204));
- m_WhitBrush.CreateSolidBrush(RGB(255, 255, 255));
- nLastRect.top = nLastRect.left = nLastRect.right = nLastRect.bottom = 0;
- }
- CXPSliderCtrl::~CXPSliderCtrl()
- {
- m_BMPChanel.DeleteObject();
- m_BMPThumb.DeleteObject();
- pBackBrush.DeleteObject();
- pSelBackBrush.DeleteObject();
- nSelThumbPen.DeleteObject();
- nUnselThumbPen.DeleteObject();
- nDarkPen.DeleteObject();
- nGreyBrush.DeleteObject();
- m_WhitBrush.DeleteObject();
- }
- BEGIN_MESSAGE_MAP(CXPSliderCtrl, CSliderCtrl)
- //{{AFX_MSG_MAP(CXPSliderCtrl)
- ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomdraw)
- ON_WM_KILLFOCUS()
- ON_WM_SETFOCUS()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CXPSliderCtrl message handlers
- void CXPSliderCtrl::DrawChannel(CDC *pDC, CRect pRect)
- {
- HDC tempDC = ::CreateCompatibleDC(pDC->m_hDC);
- ::SelectObject(tempDC, m_BMPChanel.m_hObject);
- ::BitBlt(pDC->m_hDC, pRect.left, pRect.top, pRect.right, pRect.bottom, tempDC, 0, 0, SRCCOPY);
- ::DeleteDC(tempDC);
- Invalidate();
- }
- void CXPSliderCtrl::DrawInactiveDC()
- {
- }
- void CXPSliderCtrl::DrawActiveDC()
- {
- }
- void CXPSliderCtrl::DrawHorizontalThumb(CDC *pDC, CRect rect, BOOL hasFocus)
- {
- }
- void CXPSliderCtrl::DrawVerticalThumb(CDC *pDC, CRect pRect, BOOL hasFocus)
- {
- HDC tempDC = ::CreateCompatibleDC(pDC->m_hDC);
- ::SelectObject(tempDC, m_BMPThumb.m_hObject);
- ::TransparentBlt(pDC->m_hDC,
- pRect.left,
- pRect.top,
- pRect.right - pRect.left,
- pRect.bottom - pRect.top,
- tempDC,
- 0,
- 0,
- pRect.right - pRect.left,
- pRect.bottom - pRect.top,
- RGB(255, 0, 255));
- // ::BitBlt(pDC->m_hDC, pRect.left, pRect.top, pRect.right, pRect.bottom, tempDC, 0, 0, SRCCOPY);
- ::DeleteDC(tempDC);
- Invalidate();
- }
- void CXPSliderCtrl::OnCustomdraw(NMHDR* pNMHDR, LRESULT* pResult)
- {
- // TODO: Add your control notification handler code here
-
- LPNMCUSTOMDRAW lpcd = (LPNMCUSTOMDRAW)pNMHDR;
-
- if (lpcd->dwDrawStage == CDDS_PREPAINT)
- {
- // Request prepaint notifications for each item.
- *pResult = CDRF_NOTIFYITEMDRAW;
- return;
- }
-
- if (lpcd->dwDrawStage == CDDS_ITEMPREPAINT)
- {
- CDC *pDC = CDC::FromHandle(lpcd->hdc);
- CRect rect(lpcd->rc);
- int nSavedDC = pDC->SaveDC();
-
- if (lpcd->dwItemSpec == TBCD_TICS)
- {
- *pResult = CDRF_DODEFAULT;
- return;
- } // if drawing tics
-
- else if (lpcd->dwItemSpec == TBCD_THUMB)
- {
- RECT CtrlRect;
- CRect RectTemp(0, 0, m_RectCtrl.Width(), m_RectCtrl.Height());
- *pResult = CDRF_SKIPDEFAULT;
-
- pDC->FillRect(RectTemp,&m_WhitBrush);
- CRect TempChanel(m_iChanelLeft, m_iChanelTop, m_iChanelRight, m_iChanelBottom);
- ::GetClientRect(this->m_hWnd, &CtrlRect);
-
- if (rect.Height() > rect.Width())
- {
- if (m_bFlagThumbHeit)
- {
- rect.top = (CtrlRect.bottom - CtrlRect.top - m_iThumHeit) / 2;
- }
- if (!m_bFlagThumbWid)
- {
- DrawChannel(pDC, TempChanel);
- DrawVerticalThumb(pDC, rect, bFocus);
- return;
- }
- if (rect.left < (m_iThumWid - m_RectThumb.Width()) / 2) //超出左边界
- {
- rect.left = 0;
- rect.right = m_iThumWid;
- }
- else if (rect.right + (m_iThumWid - m_RectThumb.Width()) / 2 > CtrlRect.right - CtrlRect.left) //超出右边界
- {
- rect.left = CtrlRect.right - m_iThumWid;
- rect.right = CtrlRect.right;
- }
- else
- {
- rect.left -= (m_iThumWid - m_RectThumb.Width()) / 2;
- rect.right = rect.left + m_iThumWid;
- }
- DrawChannel(pDC, TempChanel);
- DrawVerticalThumb(pDC, rect, bFocus);
- }
- else
- {
- DrawHorizontalThumb(pDC, rect, bFocus);
- }
-
- return;
- }
- else if (lpcd->dwItemSpec == TBCD_CHANNEL)
- {
- *pResult = CDRF_SKIPDEFAULT;
-
- CRect RectTemp(0, 0, m_RectCtrl.Width(), m_RectCtrl.Height());
- pDC->FillRect(RectTemp, &m_WhitBrush);
- if (m_bFlagChanelLen)
- {
- rect.left = m_iChanelLeft;
- rect.right = m_iChanelRight;
- }
- if (m_bFlagChanelHeit)
- {
- rect.top = m_iChanelTop;
- rect.bottom = m_iChanelBottom;
- }
- DrawChannel(pDC, rect);
- return;
- }
- }
- *pResult = 0;
- }
- void CXPSliderCtrl::OnKillFocus(CWnd* pNewWnd)
- {
- CSliderCtrl::OnKillFocus(pNewWnd);
-
- // TODO: Add your message handler code here
- bFocus = TRUE;
- Invalidate();
- }
- void CXPSliderCtrl::OnSetFocus(CWnd* pOldWnd)
- {
- CSliderCtrl::OnSetFocus(pOldWnd);
-
- // TODO: Add your message handler code here
- bFocus = FALSE;
- Invalidate();
- }
- //DEL void CXPSliderCtrl::SetChanelSiz(int iLen, int iHeit)
- //DEL {
- //DEL RECT CtrlRect;
- //DEL ::GetClientRect(this->m_hWnd, &CtrlRect);
- //DEL if (iLen < CtrlRect.right - CtrlRect.left)
- //DEL {
- //DEL m_iChanelLeft = (CtrlRect.right - CtrlRect.left) / 2;
- //DEL m_iChanelRight = m_iChanelLeft + iLen;
- //DEL m_bFlagChanelLen = TRUE;
- //DEL }
- //DEL if (iHeit < CtrlRect.bottom - CtrlRect.top)
- //DEL {
- //DEL m_iChanelTop = (CtrlRect.top - CtrlRect.bottom) / 2;
- //DEL m_iChanelBottom = m_iChanelTop + iHeit;
- //DEL m_bFlagChanelHeit = TRUE;
- //DEL }
- //DEL return;
- //DEL }
- void CXPSliderCtrl::InitialSiz(UINT nIDBMPChannel, UINT nIDBMPThumb, int iChanelHeit, int iChanelWid, int iThumbHeit, int iThumbWid)
- {
- RECT CtrlRect;
- CRect TempRect;
- m_BMPChanel.LoadBitmap(nIDBMPChannel);
- m_BMPThumb.LoadBitmap(nIDBMPThumb);
- GetThumbRect(&m_RectThumb);
- GetChannelRect(&m_RectChanel);
- GetWindowRect(&m_RectCtrl);
-
- ::GetClientRect(this->m_hWnd, &CtrlRect);
-
- if (iChanelWid < CtrlRect.right - CtrlRect.left)
- {
- m_iChanelLeft = (CtrlRect.right - CtrlRect.left - iChanelWid) / 2;
- m_iChanelRight = m_iChanelLeft + iChanelWid;
- m_bFlagChanelLen = TRUE;
- }
- if (iChanelHeit < CtrlRect.bottom - CtrlRect.top)
- {
- m_iChanelTop = (CtrlRect.bottom - CtrlRect.top - iChanelHeit) / 2;
- m_iChanelBottom = m_iChanelTop + iChanelHeit;
- m_bFlagChanelHeit = TRUE;
- }
-
- if (iThumbWid < (CtrlRect.right - CtrlRect.left) / 2)
- {
- m_bFlagThumbWid = TRUE;
- m_iThumWid = iThumbWid;
- }
- if (iThumbHeit < (CtrlRect.bottom - CtrlRect.top))
- {
- m_bFlagThumbHeit = TRUE;
- m_iThumHeit = iThumbHeit;
- }
- }