The Voice Recorder control records and plays sounds in a container application. For example, a developer could incorporate the Inbox and the Voice Recorder control to record a voice mail message in a file. This recording can then be attached to a regular e-mail message. The Voice Recorder application for Palm-size PC uses the Voice Recorder control many times.
The Voice Recorder control offers a user-interface element that is similar to an audio recorder. Pressing the Record button on this UI element starts the Voice Recorder engine. Pressing the Stop button terminates the recording or playback session. Other features exposed through the UI element include the Grip, Cancel and OK buttons. These buttons move the control, interrupt the recording process, and exit the control, respectively.
To program the Voice Recorder, you use one function, two data structures, and a small number of messages.
The following code example shows how to initialize a Voice Recorder control:
// make sure that the owner window exists
if (!IsWindow(hwndMain)) return FALSE;
// initialize the control’s data structure.
CM_VOICE_RECORDER cmvr;
memset( &cmvr, 0, sizeof(cmvr));
cmvr.cb = sizeof(CM_VOICE_RECORDER);
cmvr.dwStyle = VRS_NO_MOVE;
cmvr.xPos = 100; // use -1 to center the control relative to owner
cmvr.yPos = 160;
cmvr.hwndParent = hwndMain;
cmvr.lpszRecordFileName = TEXT("\\My Documents\VoiceRec.wav");
// returns the handle to the control
hwndVoice = VoiceRecorder_Create(&cmvr);
The Voice Recorder control dispatches VRN_* messages to your application window whenever the control changes. These messages are sent in the WM_NOTIFY format. Any WM_NOTIFY message sent from the Voice Recorder application will have the lParam point to a NM_VOICE_RECORDER structure. The NM_VOICE_RECORDER structure holds the VRM_* messages and an optional error code. The following code example shows how to intercept VRM_* messages.
case WM_NOTIFY
{
LPNMHDR pnmh = (LPNMHDR) lParam;
switch (pnmh->code);
{
case VRN_ERROR:
MessageBox(NULL, TEXT("Error…"), NULL, MB_OK);
break;
case VRN_RECORD_START:
MessageBox(NULL, TEXT("Recording…"), NULL, MB_OK);
break;
case VRN_RECORD_STOP:
MessageBox(NULL, TEXT("Stop recording…"), NULL, MB_OK);
break;
case VRN_PLAY_START:
MessageBox(NULL, TEXT("Playing…"), NULL, MB_OK);
break;
case VRN_PLAY_STOP:
MessageBox(NULL, TEXT("Stop playing…"), NULL, MB_OK);
break;
case VRN_CANCEL:
MessageBox(NULL, TEXT("Cancel…"), NULL, MB_OK);
break;
case VRN_OK:
MessageBox(NULL, TEXT("OK…"), NULL, MB_OK);
break;
default:
return DefWindowProc(hwnd, msg, wp,lp);
}
}
Note This example does not use the error code passed in with WM_VOICE_RECORDER. Therefore, the lParam is cast as a LPNHDR.
When you program the Voice Recorder, keep the following points in mind: