📄 116-119.html
字号:
<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=116-119//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="112-116.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="119-124.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<TABLE BORDER="2" BORDERCOLOR="#0000" ALIGN="CENTER">
<TR><TD><FONT SIZE="+1"><B>The Today Button Doesn’t Work, Right?</B></FONT>
<P>Click on the Today button in the sample application. The month calendar control switches to today’s date, but the application caption text doesn’t change. This “bug” was left in the sample application to highlight a subtle undesirable feature of the month calendar control.
</P>
<P>It turns out that programmatic changes to the current selection in a month calendar control do not trigger MCN_SELECT or MCN_SELCHANGE notifications. Therefore, the MCM_SETCURSEL message sent in the <I>OnGotoToday</I> function does not cause the MCN_SELECT or MCN_SELCHANGE notifications to be sent. Hence, the main application caption text does not change when the Today button is pressed.</P>
<P>This is a serious oversight in the design of the month calendar control. The application developer must manually trigger the notification handlers for each of these notifications.</P>
<P>One method for fixing this bug is presented in the next section.</P>
</TABLE>
<P>This function simply determines the date that the control currently uses as today’s date with the MCM_GETTODAY message, and then sets the current month calendar control selection by sending MCM_SETCURSEL. MCM_GETTODAY returns a SYSTEMTIME structure representing today’s date. MCM_SETCURSEL takes a SYSTEMTIME telling the control what day to set the current selection to.
</P>
<P><FONT SIZE="+1"><B><I>Before We Move On, Let’s Fix the Bug</I></B></FONT></P>
<P>In the previous section, we pointed out a small bug with the Today button in the month calendar control sample application. This section describes one way to fix this bug.
</P>
<P>The caption text in the main window of the application is changed by the <I>OnSelect</I> function. Pressing the Today button results in a call to the <I>OnGotoToday</I> function. Fixing the bug is as simple as making <I>OnGotoToday</I> appropriately call <I>OnSelect</I>.</P>
<P><I>OnSelect</I> requires handles to the month calendar control and the parent window. These are global variables available to any function in the application. Additionally, <I>OnSelect</I> needs a pointer to an NMSELCHANGE structure. Actually, it only needs the <I>wMonth</I>, <I>wDay</I>, and <I>wYear</I> components of the <I>stSelStart</I> member of such a structure. <I>OnGotoToday</I> already obtains this information by sending an MCM_GETTODAY message. The bug can thus be fixed by replacing the original <I>OnGotoToday</I> function with the following:</P>
<!-- CODE //-->
<PRE>
void OnGotoToday(HWND hwndCal)
{
SYSTEMTIME stToday;
NMSELCHANGE nmsel;
memset(&nmsel, 0, sizeof(nmsel));
SendMessage(hwndCal, MCM_GETTODAY, 0, (LPARAM)&stToday);
SendMessage(hwndCal, MCM_SETCURSEL, 0, (LPARAM)&stToday);
nmsel.stSelStart = stToday;
OnSelect(hwndMonth, hwndMain, &nmsel);
}
</PRE>
<!-- END CODE //-->
<P>There are very few changes to the <I>OnGotoToday</I> function here. We declare an NMSELCHANGE structure, <I>nmsel</I>, and initialize its contents to zero. After sending the MCM_SETCURSEL message to the month calendar control, we assign the <I>stSelStart</I> member of <I>nmsel</I> to the DATETIME structure retrieved by the MCM_GETTODAY message.</P>
<P><I>hwndMonth</I> and <I>hwndMain</I> are the global variables containing the window handles of the month calendar control and the main application window, respectively. The <I>OnSelect</I> call therefore has all the information it needs to update the main window caption correctly.</P>
<P><FONT SIZE="+1"><B>Month Calendar Control Messages and Notifications</B></FONT></P>
<P>The complete list of the control messages and notifications associated with the month calendar control are described in Tables 5.2 and 5.3.
</P>
<TABLE WIDTH="100%" BORDER RULES="ROWS"><CAPTION ALIGN=LEFT><B>Table 5.2</B> Month Calendar Control Messages
<TR>
<TH ALIGN="LEFT" WIDTH="25%">MESSAGE
<TH ALIGN="LEFT" WIDTH="75%">MEANING
<TR>
<TD VALIGN="TOP">MCM_GETCOLOR
<TD>Retrieves the color of the specified part of the control.
<TR>
<TD VALIGN="TOP">MCM_GETCURSEL
<TD>Gets the SYSTEMTIME structure corresponding to the currently selected date.
<TR>
<TD VALIGN="TOP">MCM_GETFIRSTDAYOFWEEK
<TD>Returns the first day of the week displayed for each week in the control.
<TR>
<TD VALIGN="TOP">MCM_GETMAXSELCOUNT
<TD>Returns the maximum number of days that can be selected at one time in the control.
<TR>
<TD VALIGN="TOP">MCM_GETMAXTODAYWIDTH
<TD>Returns the maximum width of the Today string displayed at the bottom of month calendar controls.
<TR>
<TD VALIGN="TOP">MCM_GETMINREQRECT
<TD>Returns the minimum width and height required to display one full calendar month.
<TR>
<TD VALIGN="TOP">MCM_GETMONTHDELTA
<TD>Returns the number of months that the control advances or retreats when the user taps the right or left month scroll button.
<TR>
<TD VALIGN="TOP">MCM_GETMONTHRANGE
<TD>Returns SYSTEMTIME structures representing the maximum and minimum dates that can be displayed by the control.
<TR>
<TD VALIGN="TOP">MCM_GETRANGE
<TD>Retrieves the maximum and minimum allowable dates set for the control.
<TR>
<TD VALIGN="TOP">MCM_GETSELRANGE
<TD>Gets the range of dates currently selected in a control with the MCS_MULTISELECT style.
<TR>
<TD VALIGN="TOP">MCM_GETTODAY
<TD>Retrieves the date currently set as today’s date in the control
<TR>
<TD VALIGN="TOP">MCM_HITTEST
<TD>Determines which part of the control contains the specified point.
<TR>
<TD VALIGN="TOP">MCM_SETCOLOR
<TD>Sets the color of the specified part of the control.
<TR>
<TD VALIGN="TOP">MCM_SETCURSEL
<TD>Sets the current date selection in the control. Cannot be used with controls with the MCS_MULTISELECT style.
<TR>
<TD VALIGN="TOP">MCM_SETDAYSTATE
<TD>Sets the day state information for days that are currently visible in the control.
<TR>
<TD VALIGN="TOP">MCM_SETFIRSTDAYOFWEEK
<TD>Sets the day (Monday, Tuesday, etc.) to use as the first day of each week displayed in the control.
<TR>
<TD VALIGN="TOP">MCM_SETMAXSELCOUNT
<TD>Sets the maximum number of days that can be selected in a control.
<TR>
<TD VALIGN="TOP">MCM_SETMONTHDELTA
<TD>Sets the number of months the control advances or retreats when a user taps the right or left month scroll button.
<TR>
<TD VALIGN="TOP">MCM_SETRANGE
<TD>Sets the maximum and minimum dates for a control.
<TR>
<TD VALIGN="TOP">MCM_SETSELRANGE
<TD>Sets the range of currently selected dates for a control. Message only applies to controls with the MCS_MULTISELECT style.
<TR>
<TD VALIGN="TOP">MCM_SETTODAY
<TD>Sets the date that the control specifies as today’s date.
</TABLE>
<P>
</P>
<TABLE WIDTH="100%" BORDER RULES="ROWS"><CAPTION ALIGN=LEFT><B>Table 5.3</B> Month Calendar Control Notifications
<TR>
<TH WIDTH="25%" ALIGN="LEFT">NOTIFICATION
<TH WIDTH="75%" ALIGN="LEFT">MEANING
<TR>
<TD VALIGN="TOP">MCN_GETDAYSTATE
<TD>Sent by a control to request day state information used to determine which dates to display in bold.
<TR>
<TD VALIGN="TOP">MCN_SELCHANGE
<TD>Sent by a control anytime the currently selected date or range of dates changes.
<TR>
<TD VALIGN="TOP">MCN_SELECT
<TD>Sent by a control whenever the user explicitly selects a new current date or range of dates, i.e., the user taps a specific date in the calendar.
</TABLE>
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="112-116.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="119-124.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 + -