📄 112-116.html
字号:
<!--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=112-116//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="109-112.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="116-119.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P>The next interesting part of the application is in the main window’s window procedure, where we handle the control notifications we are interested in (Figure 5.2). In our example, we respond to the MCN_SELCHANGE and MCN_GETDAYSTATE notifications. The pertinent part of the window procedure is shown in Figure 5.2.
</P>
<P><A NAME="Fig2"></A><A HREF="javascript:displayWindow('images/05-02.jpg',568,528 )"><IMG SRC="images/05-02t.jpg"></A>
<BR><A HREF="javascript:displayWindow('images/05-02.jpg',568,528)"><FONT COLOR="#000077"><B>Figure 5.2</B></FONT></A> Handling month calendar control notifications.</P>
<P>The MCN_SELCHANGE notification is sent by the month calendar control to its parent window whenever the date selection in the month calendar control is changed by some user interaction with the control. Furthermore, as the name implies, this notification is only sent when the selected date or dates change. For example, tapping a date in the control and then tapping the same date again results in an MCN_SELCHANGE notification only for the first tap.
</P>
<P>There is a related notification called MCN_SELECT. This notification is sent by the month calendar control only when the user explicitly taps a date or selects a date range. It is not sent any other time, for example when the date changes by selecting a month from the pop-up menu or tapping the month scroll buttons. In the example described above where a user taps the same date multiple times, an MCN_SELECT notification would be sent for each of the taps.</P>
<P>Since the MCN_SELCHANGE notification is sent upon any user interaction that changes the date selection in the control, we only need to respond to MCN_SELCHANGE.</P>
<P>When either the MCN_SELCHANGE or MCN_SELECT notification is sent, the <I>lParam</I> of the parent window’s window procedure is an NMSELCHANGE structure. This structure is defined as:</P>
<!-- CODE SNIP //-->
<PRE>
typedef struct tagNMSELCHANGE
{
NMHDR nmhdr;
SYSTEMTIME stSelStart;
SYSTEMTIME stSelEnd;
} NMSELCHANGE, FAR* LPNMSELCHANGE;
</PRE>
<!-- END CODE SNIP //-->
<P>The two notification-specific members of this structure, <I>stSelStart</I> and <I>stSelEnd</I>, are SYSTEMTIME structures containing date information about the first and last dates in the new date selection range. If the control does not have the MCS_MULTISELECT style, <I>stSelStart</I> and <I>stSelEnd</I> will be the same.</P>
<P>In our sample application, we change title bar text to display the currently selected date in response to these notifications. The application code for handling this notification is the <I>OnSelect</I> function:</P>
<!-- CODE //-->
<PRE>
#define IsMultiSelect(hwnd) \
(GetWindowLong(hwnd, GWL_STYLE) & MCS_MULTISELECT)
void OnSelect(HWND hwndCal,HWND hwndParent,
LPNMSELCHANGE lpsel)
{
TCHAR pszText[64];
//Set caption text only if control is single select
if (!IsMultiSelect(hwndCal))
{
wsprintf(pszText, TEXT("Selected Date: %d\\%d\\%d"),
lpsel->stSelStart.wMonth,
lpsel->stSelStart.wDay,
lpsel->stSelStart.wYear);
SetWindowText(hwndParent, pszText);
}
}
</PRE>
<!-- END CODE //-->
<P>The <I>IsMultiSelect</I> macro just tests if the month calendar control specified has the MCS_MULTISELECT style. <I>OnSelect</I> says if the control only allows single selection, set the current selected date in the application’s main window caption. The selected date in this case is either of the SYSTEMTIME members of the NMSLECHANGE structure sent by the control with the MCN_SELCHANGE notification.</P>
<P>The second notification we respond to is MCN_GETDAYSTATE. This notification is sent by the month calendar control to request the day state information, which it uses to determine which dates to display in bold text.</P>
<P>Along with the MCN_GETDAYSTATE notification, the control sends an NMDAYSTATE structure in the <I>lParam</I> of the parent window’s window procedure. This structure is defined as:</P>
<!-- CODE SNIP //-->
<PRE>
typedef struct tagNMDAYSTATE
{
NMHDR nmhdr;
SYSTEMTIME stStart;
int cDayState;
LPMONTHDAYSTATE prgDayState;
} NMDAYSTATE, FAR* LPNMDAYSTATE;
</PRE>
<!-- END CODE SNIP //-->
<P>The month calendar control requires that applications supply day state information for more than just the current month. For example, if the current month (as determined by the date that the control is currently using as today’s date) is June, the control will want day state information for May, June, and July. The <I>cDayState</I> member of this structure tells the application exactly how many months’ worth of day state information is needed. The <I>stStart</I> member indicates the first month for which the control wants day state information. This month is found in the <I>wMonth</I> member of the <I>stStart</I> SYSTEMTIME structure. <I>prgDayState</I> is an array of MONTHDAYSTATE values that the application fills in with the application specific day state information.</P>
<P>Looking at our sample application’s <I>OnGetDatState</I> function will make this much clearer. As the code in Figure 5.2 previously showed, this function is called in response to the MCN_GETDAYSTATE notification:</P>
<!-- CODE //-->
<PRE>
void OnGetDayState(LPNMDAYSTATE lpds)
{
int i, nStart;
nStart = lpds->stStart.wMonth-1;
for (i=0; i<lpds->cDayState; i++)
{
//Account for month roll over, i.e., nStart > 11.
if (nStart>11)
{
nStart = 0;
}
lpds->prgDayState[i] = mdsHoliday[nStart++];
}
}
</PRE>
<!-- END CODE //-->
<P><I>nStart</I> is the index into our <I>mdsHoliday</I> array. It is initialized to the starting month indicated by the NMDAYSTATE structure, minus 1. The minus 1 accounts for the fact that in <I>mdsHoliday</I>, January corresponds to index 0, but SYSTEMTIME month values are 1-based. Then for each of the months for which the month calendar control is requesting day state information, we assign the holiday day state information for that month to the corresponding MONTHDAYSTATE value in the <I>prgDayState</I> member of the NMDAYSTATE structure.</P>
<P>When the window procedure returns after processing this MCN_GETDAYSTATE notification, the month calendar control uses the day state information in the NMDAYSTATE structure to display the appropriate dates in bold.</P>
<P>Finally, the sample application allows the user to return to today’s date by tapping the Today button. This is done in the <I>OnGotoToday</I> function:</P>
<!-- CODE SNIP //-->
<PRE>
void OnGotoToday(HWND hwndCal)
{
SYSTEMTIME stToday;
SendMessage(hwndCal, MCM_GETTODAY, 0, (LPARAM)&stToday);
SendMessage(hwndCal, MCM_SETCURSEL, 0, (LPARAM)&stToday);
}
</PRE>
<!-- END CODE SNIP //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="109-112.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="116-119.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 + -