📄 105-109.html
字号:
<!-- 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=""> <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=5//-->
<!--PAGES=105-109//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="../ch04/099-104.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="109-112.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H2><A NAME="Heading1"></A><FONT COLOR="#000077">Chapter 5<BR>Windows CE Common Controls
</FONT></H2>
<P><BIG><BIG>T</BIG></BIG>his chapter discusses programming Window CE common controls. It concentrates on the <I>month calendar</I> control, the <I>date time picker</I> control, <I>rebar</I> controls, and <I>command bands</I> (Table 5.1). But the basic common control programming concepts covered here, such as how to respond to common control notifications, can be applied to programming all Windows CE common controls.</P>
<TABLE WIDTH="100%" BORDER RULES="ROWS"><CAPTION ALIGN=LEFT><B>Table 5.1</B> Windows CE Common Controls Covered in This Chapter
<TR>
<TH WIDTH="25%" ALIGN="LEFT">CONTROL
<TH WIDTH="75%" ALIGN="LEFT">USE
<TR>
<TD VALIGN="TOP">Month Calendar
<TD>A complete month view calendar control. User interface allows for easy selection of one or more dates.
<TR>
<TD VALIGN="TOP">Date Time Picker
<TD>Displays dates and times, and provides a convenient user interface for changing the date and time information displayed.
<TR>
<TD>Rebars
<TD>Resizable child control container.
<TR>
<TD VALIGN="TOP">Command Bands
<TD>A special rebar containing close, help, and OK buttons.
</TABLE>
<P>Like the other common controls, each of the controls listed in Table 5.1 resides in COMMCTRL.DLL. To use one or more of them in an application, the COMMCTRL.DLL must be loaded. The application then creates the controls using <I>CreateWindow</I> or <I>CreateWindowEx</I> calls with the appropriate control class name in the <I>lpClassName</I> parameter. Care must be taken to load COMMCTRL.DLL properly. See the section called “Why Are My HWNDs Always NULL?” in this chapter for details.</P>
<P>For any Windows CE common control, there are a number of messages that an application can send to the control to take advantage of various features and control functionality. In addition, there are many notifications that a common control can send to its parent window via the WM_NOTIFY message.</P>
<P>The programming model of all common controls is basically the same. Applications create controls with various control styles to enable various control features. Then parent windows send the controls messages to program their behavior. Controls also send notifications to their parent window to alert the parent that some action has been performed or some other occurrence of interest has taken place. It is therefore more economical to present a sample application for each control that highlights some of the more interesting features of the particular control.</P>
<P>After understanding the sample application, you can delve into other messages, notifications, or styles that might be of interest to you for your specific application programming needs. Using the samples as a model, you should find that taking advantage of the other Windows CE common controls not covered in this chapter will not present any serious challenges.</P>
<P>At the end of each section covering a control, a brief description of all messages and notifications for the particular control is given.</P>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>AFTER COMPLETING THIS CHAPTER YOU WILL KNOW HOW TO…</B>
<DL>
<DD><B>Program month calendar controls</B>
<DD><B>Program date time picker controls</B>
<DD><B>Program rebar controls</B>
<DD><B>Program command band controls</B>
</DL>
<HR></FONT>
</BLOCKQUOTE>
<TABLE BORDER="2" BORDERCOLOR="#0000" ALIGN="CENTER">
<TR><TD><FONT SIZE="+1"><B>Why Are My HWNDs Always NULL?</B></FONT>
<P>There is a serious discrepancy between the on-line documentation and the reality of creating any of the Windows CE common controls covered in this chapter.
</P>
<P>The documentation states that applications can create these controls by loading COMMCTRL.DLL with <I>InitCommonControls</I>, and then calling <I>CreateWindow</I> or <I>CreateWindowEx</I> with the appropriate control window class name. Alternatively, the documentation states, an application can load just the control classes it needs with <I>InitCommonControlsEx</I>, and then proceed with <I>CreateWindow</I> or <I>CreateWindowEx</I>.</P>
<P>It turns out that you <I>must</I> use the latter method with either <I>CreateWindow</I> or <I>CreateWindowEx</I>.</P>
<P>For example, I tried the following:</P>
<!-- CODE SNIP //-->
<PRE>
#include <commctrl.h>
HWND hwndMonth;
InitCommonControls();
//Code to create main application window, etc, removed
hwndMonth = CreateWindowEx(0, MONTHCAL_CLASS,...);
</PRE>
<!-- END CODE SNIP //-->
<P>To my surprise, <I>hwndMonth</I> was NULL after the <I>CreateWindowEx</I> call executed. To try and figure out what was going on, I put a call to <I>GetLastError</I> right after creating the control and got back error code 1407, which stands for ERROR_CANNOT_FIND_WND_CLASS.</P>
<P>This can only mean that <I>InitCommonControls</I> in fact does not register the window class for the month calendar control. This error also occurred for other common control classes covered in this chapter.</P>
<P>When doing the following, however, everything worked as expected:</P>
<!-- CODE SNIP //-->
<PRE>
#include <commctrl.h>
HWND hwndMonth;
INITCOMMONCONTROLSEX icex;
icex.dwSize = sizeof(icex);
icex.dwICC = ICC_DATE_CLASSES;
InitCommonControlsEx(&icex);
hwndMonth = CreateWindowEx(0, MONTHCAL_CLASS,...);
</PRE>
<!-- END CODE SNIP //-->
</TABLE>
<H3><A NAME="Heading2"></A><FONT COLOR="#000077">The Month Calendar Control</FONT></H3>
<P>The month calendar control provides a quick way to include full-featured calendar functionality in your applications. It can display dates over any specified range of dates, and automatically accounts for the day of week variations for dates in different years, as well as for leap years. An example of the month calendar control is shown in Figure 5.1
</P>
<P><A NAME="Fig1"></A><A HREF="javascript:displayWindow('images/05-01.jpg',480,240 )"><IMG SRC="images/05-01t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/05-01.jpg',480,240)"><FONT COLOR="#000077"><B>Figure 5.1</B></FONT></A> The month calendar control.</P>
<P>The control allows users to move backward or forward through the months of the year by clicking the left or right arrow button in the control title. If the device on which the application is running has a keyboard, users can also move through the months using the Page Up (to advance) and Page Down (to go back) keys.
</P>
<P>As an alternative, if the user taps the name of the month in the control title, a pop-up menu appears listing all of the months in the year. Selecting a month from this menu tells the control to display the selected month.</P>
<P>The current year can also be changed. Tapping on the year in the title of the control forces an up-down control to appear that can be used to change the year. On devices with a keyboard, CTRL+Page Up and CTRL+Page Down also move the year forward or back.</P>
<P>A number of features of the month calendar control are programmable, such as whether the control indicates the current date, and various control color options.</P>
<P>Writing personal information management applications such as an appointment book or meeting scheduler is made much easier given the functionality of the month calendar control.</P>
<P>The control class for the month calendar control, which you need to pass to <I>CreateWindow</I> or <I>CreateWindowEx</I> when creating an instance of this control, is MONTHCAL_CLASS.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="../ch04/099-104.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="109-112.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 + -