📄 045-049.html
字号:
<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=""> <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=3//-->
<!--PAGES=045-049//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="041-045.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="049-053.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H3><A NAME="Heading3"></A><FONT COLOR="#000077">Programming Common Controls</FONT></H3>
<P>Back in the days before there were 32-bit versions of Windows, the Windows user interface was limited to the child controls. Custom controls could be implemented by ambitious programmers. But the core control set was the child controls.
</P>
<P>When Windows 95 and Windows NT came out, however, a brand new set of controls was included with the operating systems. The common control library contains the controls that were added to Windows for Windows 95 and NT. Today, this library is still around, and there is a version of it for Windows CE. The library includes controls like list view controls and tree view controls. Table 3.3 lists the Windows CE common control classes. Note that Table 3.3 does not include those controls that have their own unique API. Such controls are not created using <I>CreateWindow</I>, and hence the window class names of these controls are not included.</P>
<TABLE WIDTH="100%" BORDER RULES="ROWS"><CAPTION ALIGN=LEFT><B>Table 3.3</B> The Windows CE Common Control Classes
<TR>
<TH WIDTH="50%" ALIGN="LEFT">CONTROL
<TH WIDTH="50%" ALIGN="LEFT">WINDOW CLASS NAME
<TR>
<TD>Date Time Picker
<TD>DATETIMEPICK_CLASS
<TR>
<TD>Header control
<TD>WC_HEADER
<TR>
<TD>Month calendar control
<TD>MONTHCAL_CLASS
<TR>
<TD>Progress bar
<TD>PROGRESS_CLASS
<TR>
<TD>Rebar control
<TD>REBARCLASSNAME
<TR>
<TD>Tab control
<TD>WC_TABCONTROL
<TR>
<TD>Trackbar control
<TD>TRACKBAR_CLASS
<TR>
<TD>Tree view control
<TD>WC_TREEVIEW
</TABLE>
<P>Programming these controls is very similar to using the child controls. However, you must link with the common control library and initialize this library from your application. Also, the common controls do not communicate with their parent windows via WM_COMMAND messages. These controls send notifications by means of the WM_NOTIFY message.
</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B><B>W<SMALL>INDOWS</SMALL> CE C<SMALL>OMMON</SMALL> C<SMALL>ONTROLS</SMALL> P<SMALL>ROGRAMMING</SMALL> D<SMALL>ETAILS</SMALL></B>
<P><B>This section is only intended as an introduction to the mechanism by which common controls communicate with applications. Refer to Chapter 5 for a more detailed description of programming the Windows CE common controls.</B></P>
<HR></FONT>
</BLOCKQUOTE>
<P><FONT SIZE="+1"><B>Using the Common Controls Library</B></FONT></P>
<P>To use any of the Windows CE common controls, an application must link with the library COMMCTRL.LIB. It must then initialize the library by calling the function <I>InitCommonControls</I>.</P>
<P>Calling <I>InitCommonControls</I> further requires the application to include the header file COMMCTRL.H. <I>InitCommonControls</I> is typically called in an application’s <I>WinMain</I> function.</P>
<P><FONT SIZE="+1"><B>Responding to Common Control Notifications</B></FONT></P>
<P>Common control notifications are a bit more complex than notifications sent by child controls. Notifications are sent in the form of the WM_NOTIFY message. This message includes a pointer to an NMHDR structure, which contains information about the notification being sent.
</P>
<!-- CODE SNIP //-->
<PRE>
typedef struct tagNMHDR {
HWND hwndFrom;
UINT idFrom;
UINT code;
} NMHDR;
</PRE>
<!-- END CODE SNIP //-->
<P><I>hwndFrom</I> is the window handle of the common control sending the notification. <I>idFrom</I> is the identifier of the control.</P>
<P><I>code</I> indicates the notification code identifying the particular notification being sent. This value is used like the notification code sent by a child control.</P>
<P>Let’s look at a typical example of how an application responds to common control notifications. Assume that a main window wants to know when the selected tab of a tab control in that window is changed. The main window procedure would respond to the WM_NOTIFY message as follows:</P>
<!-- CODE //-->
<PRE>
LRESULT CALLBACK WndProc(
HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
switch(message)
{
//Other window messages
//…
case WM_NOTIFY:
LPNMHDR lpnmhdr;
lpnmhdr = (LPNMHDR)lParam;
switch(lpnmhdr->idFrom)
{
case IDC_TAB:
switch(lpnmhdr->code)
{
case TCN_SELCHANGE:
//Perform some action
break;
default:
break;
} //End of switch(lpnmhdr->code) statement
break;
default:
break;
} //End of switch(lpnmhdr->idFrom) statement
return (0);
default:
return (DefWindowProc(hwnd, message, wParam, lParam));
} //End of switch(message) statement
}
</PRE>
<!-- END CODE //-->
<P>The window procedure determines which control is sending the notification by looking at the command identifier in <I>lpnmhdr->idFrom</I>. It then checks the notification code and responds accordingly to the tab control notification it is interested in.</P>
<P>The complete sample application from which this code sample comes is found on the companion CD in the directory \Samples\tab.</P>
<H3><A NAME="Heading4"></A><FONT COLOR="#000077">Dialog Boxes</FONT></H3>
<P>Many operations in Windows CE applications require user input to perform properly. Opening or saving files generally requires that the user specify a file name. To search a file for a specific string, a user enters text that the application uses to perform the search. A <I>dialog box</I> is a window through which users enter information required by an application to perform some task.</P>
<P>Dialog boxes can be either <I>modal</I> or <I>modeless</I>. A modal dialog box is displayed temporarily to accept user input (Figure 3.1). An important characteristic of a modal dialog box is that its owner window is disabled while the dialog box is present. Thus a modal dialog gives the effect of suspending an application until the user dismisses it.</P>
<P><A NAME="Fig1"></A><A HREF="javascript:displayWindow('images/03-01.jpg',480,240 )"><IMG SRC="images/03-01t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/03-01.jpg',480,240)"><FONT COLOR="#000077"><B>Figure 3.1</B></FONT></A> A modal dialog box example.</P>
<P>A modeless dialog box, on the other hand, does not prevent users from interacting with the owner window (Figure 3.2). Modeless dialog boxes are often used in cases where the application may require frequent user input. Reopening the dialog box in such cases would be needlessly inconvenient. The dialogs that many applications use to provide text searching capability are often implemented as modeless dialog boxes.
</P>
<P><A NAME="Fig2"></A><A HREF="javascript:displayWindow('images/03-02.jpg',480,240 )"><IMG SRC="images/03-02t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/03-02.jpg',480,240)"><FONT COLOR="#000077"><B>Figure 3.2</B></FONT></A> A modeless dialog box example.<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="041-045.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="049-053.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 + -