Click here to Skip to main content
15,895,084 members
Articles / Desktop Programming / MFC

Playing Midi Files with DirectMusic

Rate me:
Please Sign up or sign in to vote.
4.83/5 (17 votes)
30 Dec 2010LGPL34 min read 377.8K   6.4K   64  
A DirectX 8 class to perform Midi music playback
/*
Module : Panel.cpp
Purpose: Defines the code implementation for the CDisplay class
Created: CJP / 20-09-2001
History: CJP / 21-10-2001 
Copyright (c) 2001 by C. Jim�nez de Parga  
All rights reserved.
*/

#include "stdafx.h"
#include "panel.h"

// The constructor of the class
CDisplay::CDisplay()
{
}

// Initialize the display from a rectangle coordinates
// Asociate to it a memory bitmap
// Show the display in black background
void CDisplay::InitDisplay(CWnd *Wnd,int xp,int yp,int wp,int hp)
{
	m_x=xp;
	m_y=yp;
	m_h=hp;
	m_w=wp;
	CClientDC dc(Wnd);
	m_memDC.CreateCompatibleDC(&dc);
	m_bmp.CreateCompatibleBitmap(&dc,m_w,m_h);
	m_memDC.SelectObject(&m_bmp);
	m_bkbrush.CreateStockObject(BLACK_BRUSH);
	m_memDC.SelectObject(&m_bkbrush);
	m_memDC.PatBlt(0,0,m_w,m_h,PATCOPY);
	m_memDC.SetBkColor(RGB(0,0,0));
	m_memDC.SelectStockObject(ANSI_VAR_FONT);
}

// Member function to put text on the display 
void CDisplay::SetText(CWnd *Wnd,CString strText,int x,int y,COLORREF crColor)
{
	CRect rect;
	rect.left=x;
	rect.top=y;
	m_memDC.SetTextColor(crColor);
	m_memDC.DrawText(strText,&rect,DT_CALCRECT|DT_SINGLELINE);   
	m_memDC.DrawText(strText,&rect,DT_NOCLIP|DT_SINGLELINE);
	rect.left+=m_x;
	rect.top+=m_y;
	rect.bottom+=m_y;
	rect.right+=m_x;
	// invalidate only the affected area
	Wnd->InvalidateRect(&rect,FALSE);
}


// Member function to erase text on the display 
void CDisplay::EraseText(CWnd *Wnd,CString strText,int x,int y)
{
	CRect rect;
	rect.left=x;
	rect.top=y;
	m_memDC.DrawText(strText,&rect,DT_CALCRECT|DT_SINGLELINE); 
	m_memDC.FillSolidRect(&rect,RGB(0,0,0));
	rect.left+=m_x;
	rect.top+=m_y;
	rect.bottom+=m_y;
	rect.right+=m_x;
	// invalidate only the affected area
	Wnd->InvalidateRect(&rect);
}

// Destroy the GDI objects
CDisplay::~CDisplay()
{
	m_bmp.DeleteObject();
	m_bkbrush.DeleteObject();
}

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, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Software Developer
Spain Spain
I obtained my PhD degree in Computer Graphics at the National Distance Education University (UNED) in October 2019. I also hold a Ms. degree in Software Engineering and Computer Systems and a Bs. degree in Computer Science from the National Distance Education University (UNED).
I have been employed as a C++ software developer in several companies since year 2000.
I currently work as a Tutor-Professor of Symbolic Logic, Discrete Math and Java Object-Oriented Programming at UNED-Cartagena (Spain) since 2015.

Comments and Discussions