Wave File Editor Control | CodeGuru

Wave File Editor Control

This WaveFile manipulation control provides a  basic interface for displaying and editing wave files within a commercial audio-processing application. The app contains code on displaying the graphical data, using button logic and rudimentary mouse input to manipulate the waveform data. Thanks go to Ken C. Len’s Histogram Control for providing much of the underlying control code. […]

Written By
CodeGuru Staff
CodeGuru Staff
Sep 15, 1998
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

WaveEdit.gif (4565 bytes)

This WaveFile manipulation control provides a  basic interface for displaying and
editing wave files within a commercial audio-processing application. The app contains code
on displaying the graphical data, using button logic and rudimentary mouse input to
manipulate the waveform data. Thanks go to Ken C. Len’s Histogram
Control
for providing much of the underlying control code.

In this sample I simply use random values to generate the waveform amplitude. In a
real-world application you would load/record a wave file and gain access to the individual
sound samples through the waveform audio or other low-level audio API. Mouse input is
still basic at this point but could be easily embellished to allow caret dragging across
portions of the waveform – for cut/copy/paste etc..

The header and implementation code for the CWaveEditCtrl class are in WaveEditCtrl.h
and WaveEditCtrl.cpp

How to use

In your dialog box, dialog derived, or CFromView MDI/SDI derived app – create a static
picture control. Give it a meaningful name and set its’ properties to Rectangle and give
it a Background color (sorry, we’re limited to Ford colors from the 1930’s here). Add the
.h and .cpp files to your project and #include the .h in your app’s header file.

Declare an object of type CWaveEditCtrl like so:

class CWaveEditorView : public CFormView
{
protected:
	CWaveEditCtrl m_WaveEditCtrl;
...
};


and in your view’s OnInitialUpdate() function (this
will differ for dialog-based apps) add the following control creation code:

void CWaveEditorView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();

	CRect rect;
	GetDlgItem(IDC_WAVE_EDIT)->GetWindowRect(rect);
	ScreenToClient(rect);
	m_WaveEditCtrl.Create(WS_VISIBLE | WS_CHILD, rect, this, 1000);

Don’t forget to add OnSetFocus() and OnKillFocus()
handlers to your view with the appropriate CWaveEditCtrl member function calls  –
this will enable system-wide sharing of  the caret resource.


Note – When using the CWaveEdit class within a Dialog-based
application I had some problems getting OnSetFocus() to respond. If anyone knows how to
fix this, please let me know.

Download source and demo project
– 50KB

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.