📄 353-356.html
字号:
<INPUT TYPE="hidden" NAME="Collection" VALUE="ITK">
<INPUT TYPE="hidden" NAME="ResultTemplate" VALUE="itk-simple-intrabook.hts">
<INPUT TYPE="hidden" NAME="ViewTemplate" VALUE="view.hts">
<font face="arial, helvetica" size=2><b>Search this book:</b></font><br>
<INPUT NAME="queryText" size=50 VALUE=""> <input type="submit" name="submitbutton" value="Go!">
<INPUT type=hidden NAME="section_on" VALUE="on">
<INPUT type=hidden NAME="section" VALUE="http://www.itknowledge.com/reference/standard/0471327476/">
</form>
<!-- Empty Reference Subhead -->
<!--ISBN=0471327476//-->
<!--TITLE=Essential Windows CE Application Programming//-->
<!--AUTHOR=Robert Burdick//-->
<!--PUBLISHER=John Wiley & Sons, Inc.//-->
<!--IMPRINT=Wiley Computer Publishing//-->
<!--CHAPTER=13//-->
<!--PAGES=353-356//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="349-352.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="../ch14/357-361.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P><FONT SIZE="+1"><B>Voice Recorder Control Notifications</B></FONT></P>
<P>The voice recorder control can also send notifications to its owner window at various times. If the control is created without the VRS_NO_NOTIFY style, the notifications described in Table 13.16 are sent to the owner window.
</P>
<TABLE WIDTH="100%" BORDER RULES="ROWS"><CAPTION ALIGN=LEFT><B>Table 13.16</B> Voice Recorder Control Notifications
<TR>
<TH WIDTH="40%" ALIGN="LEFT">NOTIFICATION
<TH WIDTH="60%" ALIGN="LEFT">MEANING
<TR>
<TD>VRN_ERROR
<TD>An error has occurred.
<TR>
<TD>VRN_RECORD_START
<TD>The control has begun recording.
<TR>
<TD>VRN_RECORD_STOP
<TD>The control has stopped recording.
<TR>
<TD>VRN_PLAY_START
<TD>The control has begun playback.
<TR>
<TD>VRN_PLAY_STOP
<TD>The control has stopped playback.
<TR>
<TD>VRN_CANCEL
<TD>The Cancel button has been pressed.
<TR>
<TD>VRN_OK
<TD>The OK button has been pressed.
</TABLE>
<P>These notifications are sent via the WM_NOTIFY message just like any other common control notification. Notifications are sent using the NM_VOICE_RECORDER structure. This structure contains the usual NMHDR structure, as well as an error code. The error codes that can be sent are described in Table 13.17.
</P>
<TABLE WIDTH="100%" BORDER RULES="ROWS"><CAPTION ALIGN=LEFT><B>Table 13.17</B> Voice Recorder Control Error Codes
<TR>
<TH WIDTH="40%" ALIGN="LEFT">NOTIFICATION
<TH WIDTH="60%" ALIGN="LEFT">MEANING
<TR>
<TD>ER_SUCCESS
<TD>No error has occurred.
<TR>
<TD>ER_FAIL
<TD>Unknown error.
<TR>
<TD>ER_OUTOFMEMORY
<TD>Out of memory.
<TR>
<TD VALIGN="TOP">ER_INVALIDPARAM
<TD>An invalid parameter has been passed to a control function or message.
<TR>
<TD>ER_WRITE_FILE_FAIL
<TD>Error occurred writing to file.
<TR>
<TD>ER_OOM_STORAGE
<TD>Out of storage memory.
<TR>
<TD>ER_MAX_FILE_SIZE
<TD>Maximum file size reached during record.
<TR>
<TD>ER_BUSY
<TD>Control is busy recording or playing a file.
<TR>
<TD>ER_UNUSED1
<TD>Reserved.
<TR>
<TD>ER_UNUSED2
<TD>Reserved.
<TR>
<TD>ER_UNUSED3
<TD>Reserved.
</TABLE>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B><B>U<SMALL>SING</SMALL> V<SMALL>OICECTL</SMALL>.DLL</B>
<P><B>The voice recorder control is implemented in the library VoiceCtl.DLL. To use the control, an application must include the file VoiceCtl.h and link (either statically or dynamically) with VoiceCtl.DLL.</B><HR></FONT>
</BLOCKQUOTE>
</P>
<H3><A NAME="Heading6"></A><FONT COLOR="#000077">A Real Example</FONT></H3>
<P>Let’s take a look at an example that uses some of the navigation button and voice recorder concepts. We will add some functionality to the INK.EXE application introduced earlier in this chapter.
</P>
<P>Specifically, let’s enhance the application to provide basic voice recording capability. The recording process is started by pressing and releasing the action button. The recording is stopped by pressing and releasing the action button again.</P>
<P>We must therefore make the application respond to the action button, and insert a voice recorder control.</P>
<P>To use the action button, INK.EXE registers the corresponding hot key and responds to subsequent WM_HOTKEY messages. It does so by calling <I>RegisterHotKey</I>:</P>
<!-- CODE SNIP //-->
<PRE>
RegisterHotKey(hwndMain, 0, 0, VK_RETURN);
</PRE>
<!-- END CODE SNIP //-->
<P>The virtual key code associated with the action button is VK_RETURN. Hence, any time the action button is pressed, the main application window is sent a WM_HOTKEY message with the VK_RETURN virtual key code.
</P>
<P>The main application window responds to the action button by turning voice recording on and off. This behavior is implemented by the WM_HOTKEY message handler of the window procedure (refer to Table 13.13 for details about the WM_HOTKEY message):</P>
<!-- CODE //-->
<PRE>
case WM_HOTKEY:
UINT nKey;
nKey = (UINT)HIWORD(lParam);
switch(nKey)
{
case VK_RETURN:
if (!bRecording)
{
bRecording = TRUE;
SendMessage(hwndVoice,
VRM_RECORD,
0,
(LPARAM)TEXT("\\My Documents\\Note.wav"));
}
else
{
bRecording = FALSE;
SendMessage(hwndVoice, VRM_STOP, 0, 0);
}
break;
/* Other message handlers */
</PRE>
<!-- END CODE //-->
<P><I>bRecording</I> is a global BOOL variable that indicates whether the voice recorder control <I>hwndVoice</I> is currently recording. If the action button has been pressed and the control is not recording, the application sends the control a VRM_RECORD message. This begins recording to a file called \\My Documents\Note.wav. If the voice recorder control is already recording, recording is stopped by sending a VRM_STOP message.</P>
<P>The code above of course implies that an instance of the voice recorder control has been created. The INK.EXE <I>WinMain</I> function creates the control, <I>hwndVoice</I>, as follows:</P>
<!-- CODE //-->
<PRE>
CM_VOICE_RECORDER cmvr;
memset(&cmvr, 0, sizeof(cmvr));
cmvr.cb = sizeof(CM_VOICE_RECORDER);
cmvr.dwStyle = VRS_NO_MOVE;
cmvr.xPos = 0;
cmvr.yPos = CommandBar_Height(hwndCB);
cmvr.hwndParent = hwndMain;
cmvr.lpszRecordFileName = TEXT("\\My Documents\\Note.wav");
hwndVoice = VoiceRecorder_Create(&cmvr);
</PRE>
<!-- END CODE //-->
<P>The only style specified is VRS_NO_MOVE, meaning that the user cannot drag the voice recorder control to a new location. The y position is set to the height of the command bar that the INK.EXE application contains. This positions the recorder just below the command bar.
</P>
<P>The action button now controls voice recording in the INK.EXE application. The voice recorder control buttons can of course be used as well.</P>
<P>The voice recording feature of this example is pretty limited. The application can only record and play back one sound file. You could enhance this program into a full-featured voice memo application that can record and play back a choice of files.</P>
<H3><A NAME="Heading7"></A><FONT COLOR="#000077">Concluding Remarks</FONT></H3>
<P>We have reached the end of our discussion of Windows CE user interface programming. The most common techniques for implementing custom Windows CE user interfaces have been covered. At this point, you should be comfortable using owner draw controls and their close relative, the custom draw service. For cases where your applications require completely new controls, you can implement custom Windows CE controls as described in Chapter 11.
</P>
<P>In addition, we have briefly described how to use the HTML viewer control, and how to program some of the unique input options provided by the Palm-size PC platform.</P>
<P>This user interface programming discussion has by no means been exhaustive. As you work with Windows CE and write applications, you will have plenty of opportunities to experiment with the techniques described in the previous five chapters. But these chapters provide what I hope is a good foundation in Windows CE user interface programming.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="349-352.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="../ch14/357-361.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<!-- all of the reference materials (books) have the footer and subfoot reveresed -->
<!-- reference_subfoot = footer -->
<!-- reference_footer = subfoot -->
<!-- BEGIN SUB FOOTER -->
<br><br>
</TD>
</TR>
</TABLE>
<table width="640" border=0 cellpadding=0 cellspacing=0>
<tr>
<td align="left" width=135><img src="/images/white.gif" width=100 height="1" alt="" border="0"></td>
<!-- END SUB FOOTER -->
<!-- all of the books have the footer and subfoot reveresed -->
<!-- reference_subfoot = footer -->
<!-- reference_footer = subfoot -->
<!-- FOOTER -->
<td width="515" align="left" bgcolor="#FFFFFF">
<font face="arial, helvetica" size="1"><b><a href="/products.html"><font color="#006666">Products</font></a> | <a href="/contactus.html"><font color="#006666">Contact Us</font></a> | <a href="/aboutus.html"><font color="#006666">About Us</font></a> | <a href="http://www.earthweb.com/corporate/privacy.html" target="_blank"><font color="#006666">Privacy</font></a> | <a href="http://www.itmarketer.com/" target="_blank"><font color="#006666">Ad Info</font></a> | <a href="/"><font color="#006666">Home</font></a></b>
<br><br>
Use of this site is subject to certain <a href="/agreement.html">Terms & Conditions</a>, <a href="/copyright.html">Copyright © 1996-1999 EarthWeb Inc.</a><br>
All rights reserved. Reproduction whole or in part in any form or medium without express written permision of EarthWeb is prohibited.</font><p>
</td>
</tr>
</table>
</BODY>
</HTML>
<!-- END FOOTER -->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -