SPEAKN Sample: Demonstrates Multimedia Sound Using User-Defined Resources

The SPEAKN sample brings together graphics output and sound output. The SPEAKN sample illustrates multimedia extensions with the following programming techniques:

  • Implementing sound output using the multimedia APIs defined in the Windows SDK MMSYSTEM.H header file.

  • Using user-defined resources to store multimedia data like sounds and bitmaps. See Technical Note 35: Using Multiple Resource Files and Header Files with Visual C++ for a discussion of maintaining user-defined resources in a separate .rc file not maintained directly by Microsoft Visual C++.

  • Using bitmap buttons. (The CTRLTEST sample application provides a more exhaustive illustration of using CBitmapButton.)

A sound card is required if you want to hear the sound output, but you can run the application without a sound card.

Security noteSecurity Note

This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties.

To get samples and instructions for installing them:

To access samples from Visual Studio

  • On the Help menu, click Samples.

    By default, these samples are installed in drive:\Program Files\Microsoft Visual Studio 10.0\Samples\.

  • For the most recent version of this sample and a list of other samples, see Visual Studio Samples on the MSDN Web site.

Building and Running the Sample

To build and run the SPEAKN sample

  1. Open the solution Speakn.sln.

  2. On the Build menu, click Build.

  3. On the Debug menu, click Start Without Debugging.

When you first run SPEAKN, it plays a "welcome" sound and displays a What is this dialog box. When the sound play completes, SPEAKN displays the first of a series of images — a picture of a dog. Type "dog" into the edit box. When you enter the correct word, SPEAKN rewards you with a sound and moves on to the next image.

The happy-face bitmap initially has no smile or frown. If the first character you type is correct, the face turns to a smile; if it is incorrect, the face turns to a frown.

Keywords

This sample demonstrates the following keywords:

AfxGetResourceHandle; AfxMessageBox; CBitmapButton::AutoLoad; CBitmapButton::LoadBitmaps; CDialog::DoModal; CDialog::EndDialog; CDialog::OnInitDialog; CDialog::OnOK; CFont::CreateFontIndirect; CString::GetLength; CString::IsEmpty; CString::LoadString; CString::MakeUpper; CWinApp::InitInstance; CWnd::DoDataExchange; CWnd::EnableWindow; CWnd::GetDlgItem; CWnd::GetWindowText; CWnd::Invalidate; CWnd::SetFocus; CWnd::SetFont; CWnd::SetWindowText; CWnd::ShowWindow; CWnd::SubclassDlgItem; CWnd::UpdateData; CWnd::UpdateWindow; DestroyIcon; FindResource; FreeResource; LoadIcon; LoadResource; LockResource; MAKEINTRESOURCE; PlaySound; PostQuitMessage; lstrcpy; mbstowcs; memset; sndPlaySound; strnlen

Note

Some samples, such as this one, have not been modified to reflect the changes in the Visual C++ wizards, libraries, and compiler, but still demonstrate how to complete your desired task.

See Also

Other Resources

MFC Samples