Dela via


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 provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

To get samples and instructions for installing them:

  • On the Visual Studio Help menu, click Samples.

    For more information, see Visual Studio Samples.

  • The most recent version and complete list of samples is available online from the Visual Studio 2008 Samples page.

  • You can also locate samples on your computer's hard disk. By default, samples and a Readme file are copied into a folder under \Program Files\Visual Studio 9.0\Samples\. For Express editions of Visual Studio, all samples are located online.

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