// PointSlider.cpp : implementation file // #include "stdafx.h" #include "effecteditor.h" #include "PointSlider.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CPointSlider CPointSlider::CPointSlider() { m_nPointSize = 10; m_nBoundaryMax = 100; m_nBoundaryMin = 0; m_nSelectPoint = -1; } CPointSlider::~CPointSlider() { } BEGIN_MESSAGE_MAP(CPointSlider, CStatic) //{{AFX_MSG_MAP(CPointSlider) ON_WM_PAINT() ON_WM_MOUSEMOVE() ON_WM_LBUTTONDOWN() ON_WM_LBUTTONUP() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CPointSlider message handlers int CPointSlider::GetWidth() { RECT rcRect; GetClientRect(&rcRect); return rcRect.right - rcRect.left; } int CPointSlider::GetHeight() { RECT rcRect; GetClientRect(&rcRect); return rcRect.bottom - rcRect.top; } void CPointSlider::SetPoint(int nPoint) { list::iterator it; BOOL bExist = FALSE; for(it = m_lstPoint.begin(); it != m_lstPoint.end(); it++) { if((*it) == nPoint) { bExist = TRUE; break; } } if(!bExist) { m_lstPoint.push_back(nPoint); Invalidate(TRUE); } } void CPointSlider::SetBoundary(int nMin, int nMax) { m_nBoundaryMax = nMax; m_nBoundaryMin = nMin; } void CPointSlider::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here CDC memDC; CBitmap memBmp, *oldBmp; list::iterator it; int nPoint, nCenter, nSize = m_nPointSize / 2; memDC.CreateCompatibleDC(&dc); memBmp.CreateCompatibleBitmap(&dc, GetWidth(), GetHeight()); oldBmp = (CBitmap *)memDC.SelectObject(&memBmp); memDC.FillSolidRect(0, 0, GetWidth(), GetHeight(), 0x00444444); HBRUSH red, white, *old; red = CreateSolidBrush(0x000000FF); white = CreateSolidBrush(0x00FFFFFF); old = (HBRUSH *)memDC.SelectObject(white); for(it = m_lstPoint.begin(); it != m_lstPoint.end(); it++) { nPoint = *(it); nCenter = (int)(((float)GetWidth() / (float)(m_nBoundaryMax - m_nBoundaryMin)) * nPoint); if(m_nSelectPoint > -1 && m_nSelectPoint == nPoint) { memDC.SelectObject(red); memDC.Ellipse(nCenter - nSize, 0, nCenter + nSize, GetHeight()); } else { memDC.SelectObject(white); memDC.Ellipse(nCenter - nSize, 0, nCenter + nSize, GetHeight()); } } memDC.SelectObject(old); DeleteObject(white); DeleteObject(red); dc.BitBlt(0, 0, GetWidth(), GetHeight(), &memDC, 0, 0, SRCCOPY); memDC.SelectObject(oldBmp); // Do not call CStatic::OnPaint() for painting messages } void CPointSlider::DeletePoint(int nPoint) { list::iterator it; for(it = m_lstPoint.begin(); it != m_lstPoint.end(); it++) { if((*it) == nPoint) { m_lstPoint.erase(it); break; } } } void CPointSlider::OnMouseMove(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CStatic::OnMouseMove(nFlags, point); } void CPointSlider::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default list::iterator it; int nSize = m_nPointSize / 2, nCenter; BOOL bSelect = FALSE; for(it = m_lstPoint.begin(); it != m_lstPoint.end(); it++) { nCenter = (int)(((float)GetWidth() / (float)(m_nBoundaryMax - m_nBoundaryMin)) * (*it)); if(nCenter - nSize <= point.x && point.x <= nCenter + nSize) { m_nSelectPoint = (*it); bSelect = TRUE; Invalidate(TRUE); long wP = ((short)m_nSelectPoint << 16) | 0x0000FFFF; long lP = (long)this->m_hWnd; ::SendMessage(this->GetParent()->m_hWnd, WM_HSCROLL, wP, lP); break; } } if(!bSelect) { m_nSelectPoint = -1; Invalidate(TRUE); } CStatic::OnLButtonDown(nFlags, point); } void CPointSlider::OnLButtonUp(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CStatic::OnLButtonUp(nFlags, point); } BOOL CPointSlider::PreTranslateMessage(MSG* pMsg) { // TODO: Add your specialized code here and/or call the base class if(pMsg->message == WM_KEYDOWN) { MessageBox("!423","135"); } return CStatic::PreTranslateMessage(pMsg); }