This chapter's sample program is—you guessed it—a CD player. Using the CCDPlayer class, this simple Win32 GUI application allows you to play (and even pause!) your favorite CDs. You can also jump between tracks and select different CD devices to play from. Check out Figure 9.4 for a screenshot. Figure 9.4: Screenshot of this sample's chapter program in action. Most of the code in Ch9p1_CDPlayer.cpp is Win32 GUI code. I didn't use any foundation classes—this is bare-bones Win32 API code. As such, it's a bit difficult to snake through, so I thought I'd explain some of the more interesting bits of its operation.The CD player class itself is a global variable, g_CDPlayer. When the main dialog is initialized, it calls the PutAvailableDevicesInComboBox function, which in turn calls the static CCDPlayer::GetAvailableDevices method. This method goes through the drive letter alphabet and returns the device info array, which the program uses to populate the combo box.The CD player class is initialized in response to a combo box selection change message (CBN_SELCHANGE). The OnComboBoxChange function re-initializes the CD player class, passing in the drive letter the user selected. Every combo box item has 32 bits of storage space—the sample program uses eight of these bits to hold the char corresponding to the drive letter, so all it has to do is get these eight bits from whichever combo box item is currently selected, and then pass that drive letter off to the CD player's Init method.There's a timer that fires every second, which calls RefreshGUI. This function does a few things— first, it either enables or disables all of the control buttons, depending on whether there is a CD in the selected drive. Second, it queries the CD player class for the track position, which it displays in the IDC_LCD label. It also sets the caption on the play button to "Play," "Pause," or "Resume," as appropriate.I've included handlers for both WM_DEVICECHANGED and MM_MCINOTIFY messages. The device changed message handler just calls RefreshGUI so that the controls get enabled when a CD is inserted, and disabled when a CD is removed. MM_MCINOTIFY moves to the next track on the CD. Feel free to add some repeat or shuffle code to this handler.Finally, notice that the entire dialog procedure is wrapped in a try block. If the CD player class encounters any MCI errors, it calls its protected HandleError method, which in turn throws a string. The dialog proc catches the string and displays it as a message box to the user. In a real game you probably would want to do something else, but for a simple CD player app this is fine.In summary, if you haven't done any bare-bones Win32 API programming before, learning this program will feel like drinking from a fire hose. You might want to grab a book on the essentials, such as the excellent Windows Programming for Dummies or any other of several books on the Windows API.