Message Beep Function


The real focus of Visual C++ and in Windows is to provide a great deal of interaction with the user. You have already seen the message box function used to facilitate this. Your Windows operating system also gives you plenty of audio feedback. There are a variety of different sounds for different purposes, including error messages. In Visual C++, you have access to many of these system sounds, and you can incorporate them into your own programs. You do this via the message beep function. The message beep function takes a single parameter, an integer constant that tells it which sound to activate. You will then hear the default system sound for that activity. Table 15.6 shows these constants. An example demonstrating the use of the message beep function follows.

Table 15.6: Message Beep Constants

Constant

Sound

MB_ICONASTERISK

The system asterisk sound.

MB_ICONHAND

The system hand sound.

MB_ICONQUESTION

The system question sound.

MB_OK

The system default sound.

MB_ICONEXCLAMATION

The system exclamation.

Example 15.3

Step 1: Start the Application Wizard (exe.) Use default settings for everything except the name, which should be example15_03.

Step 2: Place three buttons on the dialog labeled “Exclamation,” “Question,” and “OK.” It should look like what you see in Figure 15.22.

click to expand
Figure 15.22: Message beep demo.

Step 3: We are now going to place the message beep function call to the appropriate sound in each of those buttons. The code should look like the following.

void CExample1_03Dlg::OnButton1()  {  MessageBeep(MB_ICONEXCLAMATION); } void CExample1_03Dlg::OnButton2()  { MessageBeep(MB_ICONQUESTION);      } void CExample1_03Dlg::OnButton3()  {   MessageBeep(MB_OK);      }

When you execute the program and click on each of the buttons, you will hear a sound. Of course, if, for some reason, your system has no default sound associated with a given activity, then you will not hear any sound.




C++ Programming Fundamentals
C++ Programming Fundamentals (Cyberrookies)
ISBN: 1584502371
EAN: 2147483647
Year: 2005
Pages: 197
Authors: Chuck Easttom

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net