Click here to Skip to main content
15,893,622 members
Articles / Desktop Programming / MFC

Effecto Player

Rate me:
Please Sign up or sign in to vote.
4.78/5 (39 votes)
23 Sep 20035 min read 164K   14.8K   97  
Media audio player with 3D and 2D effects and skinning.
///////////////////////////////////////////////////////////////
//
// Dosya Ad�: BitmapSlider.h
// Yazan    : C�neyt EL�BOL
// A��klama : Resimden Trackbar olu�turma
// 
// Detayl� Bilgi i�in 
//       
//    www.celibol.freeservers.com  adresini ziyaret edin
//            veya
//    celibol@hotmail.com adresine mesaj at�n.
//
// Dikkat:
//    Bu program kodlar�n� kullan�rken Aciklama.txt dosyas�ndaki
//  gerekleri yerine getirmeniz gerekir.
//
///////////////////////////////////////////////////////////////

#include "stdafx.h"
#include <afxwin.h>
#include <afxcmn.h>
#include "BitmapSlider.h"

#include "EffectoDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CBitmapSlider

CBitmapSlider::CBitmapSlider()
{
	m_MouseOnThumb = FALSE;
}

CBitmapSlider::~CBitmapSlider()
{
	m_Back.DeleteObject();
	m_ThumbNormal.DeleteObject();
	m_ThumbDown.DeleteObject();
}


BEGIN_MESSAGE_MAP(CBitmapSlider, CSliderCtrl)
	//{{AFX_MSG_MAP(CBitmapSlider)
	ON_WM_PAINT()
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_MOUSEMOVE()
	ON_WM_CAPTURECHANGED()
	ON_WM_ERASEBKGND()
	ON_WM_KEYDOWN()
	ON_WM_KEYUP()	
	ON_WM_CHAR()

	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBitmapSlider message handlers

void CBitmapSlider::SetBitmap(CBitmap& mBack, CBitmap& mTNormal, CBitmap& mTDown)
{
	m_Back.DeleteObject();
	m_ThumbNormal.DeleteObject();
	m_ThumbDown.DeleteObject();
	
	m_Back.Attach(mBack);
	m_ThumbNormal.Attach(mTNormal);
	m_ThumbDown.Attach(mTDown);
	ModifyStyle(WS_TABSTOP, 0);
}

void CBitmapSlider::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	
	// TODO: Add your message handler code here
	CDC memdc;
	memdc.CreateCompatibleDC(NULL);
	memdc.SelectObject(m_Back);

	CRect r;
	GetClientRect(&r);
	dc.BitBlt(0, 0, r.Width(), r.Height(), &memdc, 0, 0, SRCCOPY);
	CRect Tr;
	getThumbRect(Tr);
	if (m_MouseOnThumb)
		memdc.SelectObject(m_ThumbDown);
	else
		memdc.SelectObject(m_ThumbNormal);
	dc.BitBlt(Tr.left, Tr.top, Tr.Width(), Tr.Height(), &memdc, 0, 0, SRCCOPY);
}

void CBitmapSlider::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CSliderCtrl::OnLButtonDown(nFlags, point);
	m_MouseOnThumb = FALSE;
	CRect Tr;
	getThumbRect(Tr);
	if (Tr.PtInRect(point))
		m_MouseOnThumb = TRUE;
	Invalidate();
}

void CBitmapSlider::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CSliderCtrl::OnLButtonUp(nFlags, point);
	m_MouseOnThumb = FALSE;	
	Invalidate();
}

void CBitmapSlider::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CSliderCtrl::OnMouseMove(nFlags, point);
	if(m_MouseOnThumb) Invalidate();
}

void CBitmapSlider::OnCaptureChanged(CWnd *pWnd) 
{
	// TODO: Add your message handler code here
	if(m_MouseOnThumb)
	{
		ReleaseCapture();
		Invalidate();
	}
	CSliderCtrl::OnCaptureChanged(pWnd);
}

BOOL CBitmapSlider::OnEraseBkgnd(CDC* pDC) 
{
	// TODO: Add your message handler code here and/or call default
	
	return FALSE; //CSliderCtrl::OnEraseBkgnd(pDC);
}

void CBitmapSlider::getThumbRect(CRect& r)
{
	BITMAP bm;

	GetObject(m_ThumbNormal, sizeof(bm), &bm);
	
	GetThumbRect(&r);

	if ((GetStyle() & TBS_VERT) == TBS_VERT) 
	{
		CRect mR;
		GetClientRect(&mR);
		int o    = /*mR.Width() - */(r.Height() / 2);

		r.left   = 0;
		r.top    = (r.top + o) - (bm.bmHeight / 2);
		r.right  = r.left + bm.bmWidth;
		if(r.top < 0) r.top = 0;
		r.bottom = r.top + bm.bmHeight;
	}
	else
	{
		int o    = r.Width() / 2;
		r.top = 0;
		r.bottom = r.top + bm.bmHeight;
		r.left = (r.left + o) - (bm.bmWidth / 2);
		r.right = r.left + bm.bmWidth;
	}
}


void CBitmapSlider::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	CWinApp * app = AfxGetApp();
	CEffectoDlg *dlg =(CEffectoDlg *)app->m_pMainWnd;
	dlg->KeyUp (nChar, nRepCnt, nFlags,2);
	CSliderCtrl::OnKeyUp(nChar, nRepCnt, nFlags);
	
}

void CBitmapSlider::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	CWinApp * app = AfxGetApp();
	CEffectoDlg *dlg =(CEffectoDlg *)app->m_pMainWnd;
	dlg->Char (nChar, nRepCnt, nFlags,2);
}


void CBitmapSlider::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	CWinApp * app = AfxGetApp();
	CEffectoDlg *dlg =(CEffectoDlg *)app->m_pMainWnd;
	dlg->KeyDown (nChar, nRepCnt, nFlags,2);
	CSliderCtrl::OnKeyDown(nChar, nRepCnt, nFlags);

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Egypt Egypt
My name is Ahmed Ismaiel Zakaria
i'm programming c++ & visual c++ (MFC )& Visual basic and recently COM,ATL
Student in Faculty of computer and information science in Egypt

Comments and Discussions