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

📄 034-036.html

📁 WindowsCE.[Essential Windows CE Application Programming].Jon Wiley & Son.zip
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!-- end of ITK left NAV -->

<!-- begin main content -->
<td width="100%" valign="top" align="left">


<!-- END SUB HEADER -->

<!--Begin Content Column -->

<FONT FACE="Arial,Helvetica" SIZE="-1">
To access the contents, click the chapter and section titles.
</FONT>
<P>
<B>Essential Windows CE Application Programming</B>
<FONT SIZE="-1">
<BR>
<I>(Publisher: John Wiley & Sons, Inc.)</I>
<BR>
Author(s): Robert Burdick
<BR>
ISBN: 0471327476
<BR>
Publication Date: 03/01/99
</FONT>
<P>
<form name="Search" method="GET" action="http://search.earthweb.com/search97/search_redir.cgi">

<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=2//-->
<!--PAGES=034-036//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="031-033.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="037-040.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>

<TABLE BORDER="2" BORDERCOLOR="#0000" ALIGN="CENTER">
<TR><TD><FONT SIZE="+1"><B>Windows CE Non-Client Messages</B></FONT>
<P>Unlike other Win32-based platforms, Windows CE does not expose any of the non-client area window messages to the application programmer. Non-client area operations, such as painting the non-client area and non-client area stylus tap hit testing, are all performed exclusively by the operating system.
</P>
<P>This means that your Windows CE applications cannot include handling for any non-client messages. For example, the following code in the window procedure of a main application window would result in a compilation error:</P>
<!-- CODE SNIP //-->
<PRE>
  switch(message)
  &#123;
  case WM_NCPAINT:
  //Custom window border drawing code
     return (0);
  ...
  &#125;
</PRE>
<!-- END CODE SNIP //-->
<P>Specifically, the compiler will issue an error 2065 (undeclared identifier) when it tries to compile the line that contains WM_NCPAINT. Not only are the non-client messages not forwarded to the window procedure, they are actually excluded from the WINUSER.H public header file.
</P>
</TABLE>

<P><I>lpCmdLine</I> is a null-terminated Unicode string containing the command line with which the application was launched, if any.</P>
<P><I>nCmdShow</I> specifies how the main application window is to be shown.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE:&nbsp;&nbsp;</B><B><I>W<SMALL>IN</SMALL>M<SMALL>AIN</SMALL></I> S<SMALL>IGNATURE</SMALL> I<SMALL>S A</SMALL> B<SMALL>IT</SMALL> D<SMALL>IFFERENT IN</SMALL> W<SMALL>INDOWS</SMALL> CE</B>
<P><B>Please note this subtle difference between the Windows CE <I>WinMain</I> signature and that for other Win32 platforms: The <I>lpCmdLine</I> parameter under Windows CE is a LPTSTR, whereas on Windows NT and Windows 98 it is an LPSTR.</B><HR></FONT>
</BLOCKQUOTE>
</P>
<H3><A NAME="Heading5"></A><FONT COLOR="#000077">The Message Loop</FONT></H3>
<P>How do Windows CE messages end up getting to your window procedure if you never call your window procedure directly?
</P>
<P>Messages can get to windows in a couple of different ways. One common way is for an application or Windows CE to send messages directly to a window using the <I>SendMessage</I> function:</P>
<!-- CODE SNIP //-->
<PRE>
  SendMessage(hwnd, uMsg, wParam, lParam);
</PRE>
<!-- END CODE SNIP //-->
<P>Does this look familiar? The parameters of <I>SendMessage</I> are the same as the parameters of any Windows CE window procedure. This is because <I>SendMessage</I> immediately turns around and calls the window procedure of the window class of which <I>hwnd</I> is an instance.</P>
<P>For example, if I wish to change the text in a button in one of my applications, I can do something like this:</P>
<!-- CODE SNIP //-->
<PRE>
  SendMessage(hwndButton, WM_SETTEXT, 0,
    (LPARAM)(LPCTSTR)TEXT(&#147;New Text&#148;));
</PRE>
<!-- END CODE SNIP //-->
<P><I>SendMessage</I> has the same function signature as a window procedure. In fact, <I>SendMessage</I> calls the window procedure for the specified window. It does not return until the message specified in the second parameter is processed by the window procedure of the window to which the message is sent.</P>
<P><I>SendMessage</I> processes messages <I>synchronously</I>. That is, the message is processed by the window it is sent to immediately. The other way that Windows CE handles messages is <I>asynchronously</I>. Many messages, such as requests to update or repaint a window or notifications that the user has tapped the touch screen, are often sent by the operating system to an application faster than the application can process them.</P>
<P>For this reason, when an application starts running, Windows CE creates a <I>message queue</I> for that application.<SUP><SMALL><B>2</B></SMALL></SUP> The message queue is a place where messages can be put by the operating system or an application to be processed asynchronously, that is, when the application gets around to it.</P>

<BLOCKQUOTE>
<HR>
<SUP><SMALL><B>2</B></SMALL></SUP><FONT SIZE="-1">Actually, Windows CE creates a message queue for every thread created by an application. But for the sake of this discussion, we&#146;ll think of each application as having only its main thread. The meaning of the application&#146;s message queue is therefore unambiguous.
</FONT>
<HR>
</BLOCKQUOTE>

<P>To process asynchronous messages, an application implements a <I>message loop</I>. This is a simple piece of code that continuously looks for messages in the application&#146;s message queue. When the message loop finds a message, it gets processed. Otherwise the message loop just keeps on looping.</P>
<P>A typical message loop looks like this:</P>
<!-- CODE SNIP //-->
<PRE>
  while (GetMessage(&#38;msg, NULL, 0, 0) == TRUE)
  &#123;
    TranslateMessage(&#38;msg);
    DispatchMessage(&#38;msg);
  &#125;
</PRE>
<!-- END CODE SNIP //-->
<P>That&#146;s a pretty short while loop for processing a whole lot of messages. The <I>GetMessage</I> function gets a message from the message queue. This message is contained in a message structure of type MSG. This structure includes information such as which message was sent and which window it was intended for. Once a message is retrieved, <I>DispatchMessage</I> calls the window procedure corresponding to the window class of the window specified in the message structure.</P>
<P><I>GetMessage</I> returns TRUE until it receives a WM_QUIT message from the message queue. The <I>GetMessage</I> function has the following syntax:</P>
<!-- CODE SNIP //-->
<PRE>
  GetMessage(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax);
</PRE>
<!-- END CODE SNIP //-->
<P>The lpMsg parameter to <I>GetMessage</I> is a pointer to a message structure that receives the information about the message retrieved from the message queue. <I>hwnd</I> specifies the window for which messages are to be retrieved. In other words, only messages sent to the specified window are removed from the message queue. If this parameter is NULL, messages for any window created by the calling thread are retrieved. <I>wMsgFilterMin</I> and <I>wMsgFilterMax</I> specify a range of window message identifiers to look for. Setting these both to zero tells <I>GetMessage</I> to look for all messages.</P>
<P>We skipped over the <I>TranslateMessage</I> step. This function converts virtual key messages into regular key messages before they are dispatched by <I>DispatchMessage</I>. We glossed over this because the main point of the discussion is how messages get pulled from the message queue and sent off to the proper window procedure. Once translated, virtual key messages get handled just like any other messages. The use of the <I>TranslateMessage</I> function is discussed when we introduce the concept of accelerator tables in Chapter 4.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="031-033.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="037-040.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 + -