⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 338-342.html

📁 WindowsCE.[Essential Windows CE Application Programming].Jon Wiley & Son.zip
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<INPUT TYPE="hidden" NAME="Action" VALUE="Search">
<INPUT TYPE="hidden" NAME="SearchPage" VALUE="http://search.earthweb.com/search97/samples/forms/srchdemo.htm">
<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="">&nbsp;<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=338-342//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="333-338.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="342-345.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P><FONT SIZE="+1"><B><I>Saving Inking Data</I></B></FONT></P>
<P>The portion of the <I>OnOpenSave</I> function that saves .ink files is shown below. All of the code that fills the OPENFILENAME structure has been left out for brevity.</P>
<!-- CODE //-->
<PRE>
  DWORD dwLen, dwSize;
  HANDLE hFile, hFind;
  LPBYTE lpByte;
  OPENFILENAME ofn;
  if (GetSaveFileName(&#38;ofn))
  &#123;
    dwLen = SendMessage(hwndInk, IM_GETDATALEN, 0, 0);
    /* Get the ink data if there is any
     (i.e., if dwLen != 0) */
    if (dwLen)
    &#123;
     lpByte = (LPBYTE)LocalAlloc(LPTR, dwLen&#43;1);
     SendMessage(hwndInk, IM_GETDATA,
      (WPARAM)dwLen, (LPARAM)lpByte);
    &#125;
    /* Now we revisit all of the file system API stuff
      as we create a file and write the ink data to it.
     */
    hFile = CreateFile(
     ofn.lpstrFile,
     GENERIC_READ|GENERIC_WRITE,
     0,
     NULL,
     CREATE_ALWAYS,
     FILE_ATTRIBUTE_ARCHIVE,
     NULL
     );
     WriteFile(hFile, lpByte, dwLen, &#38;dwSize, NULL);
     CloseHandle(hFile);
     LocalFree(lpByte);
  &#125;   //End of if (GetSaveFileName(&#38;ofn)) block
</PRE>
<!-- END CODE //-->
<P>The first thing the function does when saving a file is to get the length in bytes of the inking data from the rich ink control. This is accomplished in a single line of code:
</P>
<!-- CODE SNIP //-->
<PRE>
  dwLen = SendMessage(hwndInk, IM_GETDATALEN, 0, 0);
</PRE>
<!-- END CODE SNIP //-->
<P>The IM_GETDATALEN message returns the number of bytes of inking data contained by the specified rich ink control. If the control has inking data, the value returned by the IM_GETDATALEN message will be non-zero. The IM_GETDATALEN message is detailed in Table 13.5.
</P>
<TABLE WIDTH="100%" BORDER RULES="ROWS"><CAPTION ALIGN=LEFT><B>Table 13.5</B> The IM_GETDATALEN Message
<TR>
<TH WIDTH="40%" ALIGN="LEFT">PARAMETER
<TH WIDTH="60%" ALIGN="LEFT">MEANING
<TR>
<TD>wParam
<TD>Not used, should be 0.
<TR>
<TD>lParam
<TD>Not used, should be 0.
</TABLE>
<P>The function next allocates <I>dwLen</I> bytes to the array <I>lpByte</I> and retrieves the control&#146;s inking data by sending an IM_GETDATA message:</P>
<!-- CODE SNIP //-->
<PRE>
  lpByte = (LPBYTE)LocalAlloc(LPTR, dwLen&#43;1);
  SendMessage(hwndInk, IM_GETDATA,
    (WPARAM)dwLen, (LPARAM)lpByte);
</PRE>
<!-- END CODE SNIP //-->
<P>When the IM_GETDATA message returns, <I>lpByte</I> will be filled with the inking data currently stored in the rich ink control <I>hwndInk</I>. The IM_GETDATA message also returns the actual number of bytes written to <I>lpByte</I> as the return value of the <I>SendMessage</I> function call.</P>
<P>Once the inking data has been extracted from the rich ink control, <I>OnOpenSave</I> proceeds by storing the data in the file specified by <I>ofn.lpstrFile</I>. This file name is specified by the user in the File Save common dialog box that is invoked by the <I>GetSaveFileName</I> function call. Since we covered the file system API in detail in Chapter 6, the preceding code that saves the data to the data file should not be mysterious.</P>
<P><FONT SIZE="+1"><B><I>Reading Inking Data Files</I></B></FONT></P>
<P>Reading and displaying an existing .ink file is very similar to saving an .ink file. As mentioned above, <I>OnOpenSave</I> both saves and reads .ink files. The portion of the function that reads existing inking data files is given below. As was the case with the presentation of the file save code, all logic required to initialize the OPENFILENAME structure has been left out.</P>
<!-- CODE //-->
<PRE>
  if (GetOpenFileName(&#38;ofn))
  &#123;
    WIN32_FIND_DATA fd;
    hFind = FindFirstFile(ofn.lpstrFile, &#38;fd);
    if (hFind)
    &#123;
     CEOIDINFO oidInfo;
     CeOidGetInfo(fd.dwOID, &#38;oidInfo);
     dwLen = oidInfo.infFile.dwLength;
     dwSize = 0;
     lpByte = (LPBYTE)LocalAlloc(LPTR, dwLen&#43;1);
    &#125;
    hFile = CreateFile(
     ofn.lpstrFile,
     GENERIC_READ|GENERIC_WRITE,
     0,
     NULL,
     OPEN_EXISTING,
     FILE_ATTRIBUTE_NORMAL,
     NULL
     );
    ReadFile(hFile, lpByte, dwLen, &#38;dwSize, NULL);
    SendMessage(hwndInk, IM_SETDATA,
     (WPARAM)dwSize, (LPARAM)lpByte);
    CloseHandle(hFile);
    FindClose(hFind);
  &#125;  //End of if (GetOpenFileName(&#38;ofn) block
</PRE>
<!-- END CODE //-->
<P><I>FindFirstFile</I> is called with the file name selected by the user to get WIN32_FIND_DATA information about the file to be opened. In particular, the <I>dwOID</I> member of this structure is necessary for getting further information about the file, such as the file size.</P>
<P>Note that <I>CeOidGetInfo</I> is called to get the length of the file in bytes. Compare this with using the IM_GETDATALEN message when the .ink file was saved. In the case of saving files, the application can ask the rich ink control for the length of the inking data it contains. But when reading files, the file must be queried for this information. The rich ink control only knows the length of the data it contains.</P>
<P>After getting the length of the file, the array <I>lpByte</I> is allocated. The file is then opened and all of the inking data is read into <I>lpByte</I>.</P>
<P>Finally, <I>OnOpenSave</I> must display the data read from the .ink file in the rich ink control. It does this by sending the control an IM_SETDATA message:</P>
<!-- CODE SNIP //-->
<PRE>
  SendMessage(hwndInk, IM_SETDATA,
    (WPARAM)dwSize, (LPARAM)lpByte);
</PRE>
<!-- END CODE SNIP //-->
<P><I>dwSize</I> tells the control how many bytes of data to expect. <I>lpByte </I>points to the array of inking data. The rich ink control responds to the IM_SETDATA message by displaying the new data.</P>
<P><FONT SIZE="+1"><B>The IM_CLEARALL Message</B></FONT></P>
<P>The last rich ink control message to discuss is IM_CLEARALL.
</P>
<P>This message removes all inking data from a rich edit control. IM_CLEARALL is a very simple message. As Table 13.6 shows, both message parameters are zero.</P>
<TABLE WIDTH="100%" BORDER RULES="ROWS"><CAPTION ALIGN=LEFT><B>Table 13.6</B> The IM_CLEARALL Message
<TR>
<TH WIDTH="40%" ALIGN="LEFT">PARAMETER
<TH WIDTH="60%" ALIGN="LEFT">MEANING
<TR>
<TD>wParam
<TD>Not used, should be 0.
<TR>
<TD>lParam
<TD>Not used, should be 0.
</TABLE>
<P>As an example, the INK.EXE application sends this message in response to the Clear Page option of the Ink menu. This single line erases the contents of the rich ink control <I>hwndInk</I>:</P>
<!-- CODE SNIP //-->
<PRE>
  SendMessage(hwndInk, IM_CLEARALL, 0, 0);
</PRE>
<!-- END CODE SNIP //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="333-338.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="342-345.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>&nbsp;|&nbsp; <a href="/contactus.html"><font color="#006666">Contact Us</font></a>&nbsp;|&nbsp; <a href="/aboutus.html"><font color="#006666">About Us</font></a>&nbsp;|&nbsp; <a href="http://www.earthweb.com/corporate/privacy.html" target="_blank"><font color="#006666">Privacy</font></a> &nbsp;|&nbsp; <a href="http://www.itmarketer.com/" target="_blank"><font color="#006666">Ad Info</font></a> &nbsp;|&nbsp; <a href="/"><font color="#006666">Home</font></a></b>
		<br><br>
		
		Use of this site is subject to certain <a href="/agreement.html">Terms &amp; Conditions</a>, <a href="/copyright.html">Copyright &copy; 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 + -