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

📄 109-112.html

📁 WindowsCE.[Essential Windows CE Application Programming].Jon Wiley & Son.zip
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<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=5//-->
<!--PAGES=109-112//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="105-109.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="112-116.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P><FONT SIZE="+1"><B>Month Calendar Control Styles</B></FONT></P>
<P>There are five control styles that can be used with the month calendar control:
</P>
<DL>
<DD><B>MCS_DAYSTATE.</B> Indicates that the control is capable of drawing specific dates in bold text.
<DD><B>MCS_MULTISELECT.</B> Indicates that the control can select a range of dates. The default is that month calendar controls can only select one date at a time.
<DD><B>MCS_NOTODAY.</B> Control does not display &#147;Today is&#133;&#148; text at the bottom.
<DD><B>MCS_NOTODAYCIRCLE.</B> Control does not box the current date.
<DD><B>MCS_WEEKNUMBERS.</B> Control displays the number of each week (1&#150;52) to the left of each week.
</DL>
<P><FONT SIZE="+1"><B>Day States</B></FONT></P>
<P>Month calendar controls can be made to display dates of interest in bold text. For example, you may want an appointment calendar application to display holidays in bold to make them easier to identify.
</P>
<P>Highlighting dates in bold in a month calendar control is done using the <I>day state</I> mechanism. A day state is a data type called MONTHDAYSTATE which is simply a DWORD. Each of the 32 bits of a MONTHDAYSTATE is used to represent the state of the corresponding day in a particular month. If, for example, bit 5 is set to 1, day 5 in the corresponding month is displayed in bold on the month calendar control. Zero values in MONTHDAYSTATEs mean the corresponding dates are not bold.</P>
<P>Applications typically tell month calendar controls which dates to display in bold in response to the MCN_GETDAYSTATE notification. We will look at the specifics of responding to this and other month calendar control notifications a little later.</P>
<P><FONT SIZE="+1"><B>An Example</B></FONT></P>
<P>In this example, we create a month calendar control that highlights a limited set of holidays. For the sake of simplicity, the holidays it highlights are among those that always fall on the same date every year. This prevents me from having to implement an algorithm that can do things such as determine what date the third Sunday in June is in any given year (sorry, Dad).
</P>
<P>Our application uses a month calendar control that only allows users to select a single date at a time. It displays the currently selected date in the main application window title bar. Also, the application has a button labeled Today which sets the current selection to today&#146;s date.</P>
<P>To pick the holidays, I sat down with my wife&#146;s &#147;Cat Lover&#148; calendar and chose seven holidays at random (I wouldn&#146;t have picked January 22, &#147;Answer Your Cat&#146;s Question Day,&#148; any other way). Here&#146;s what I came up with:</P>
<DL>
<DD><B>&#149;</B>&nbsp;&nbsp;January 1: New Year&#146;s Day
<DD><B>&#149;</B>&nbsp;&nbsp;January 22: see above
<DD><B>&#149;</B>&nbsp;&nbsp;February 14: Valentine&#146;s Day
<DD><B>&#149;</B>&nbsp;&nbsp;March 17: St. Patrick&#146;s Day
<DD><B>&#149;</B>&nbsp;&nbsp;July 4: Independence Day
<DD><B>&#149;</B>&nbsp;&nbsp;October 31: Halloween
<DD><B>&#149;</B>&nbsp;&nbsp;December 25: Christmas
</DL>
<P>Our month calendar control will display each of these holidays in bold. Therefore, our application needs to use day states. Let&#146;s look first at how to do this.
</P>
<P>Recall that for any given month, a month calendar control uses a MONTHDAYSTATE 32-bit integer to represent the dates to display in bold. The least significant bit represents the first of the month, the next bit represents the second, and so on. Since the control keeps track of the number of days in a given month for a particular year, the last day of the month may be bit 28, 29, 30, or 31. Defining a day state for Christmas, for example, could be done like this:</P>
<!-- CODE SNIP //-->
<PRE>
  MONTHDAYSTATE mdsXMas;
  mdsXMas = (MONTHDAYSTATE)(0x01 &lt;&lt; 24);
</PRE>
<!-- END CODE SNIP //-->
<P>Since bit zero of a MONTHDAYSTATE represents the first of the month, bit 24 corresponds to the 25th. Shifting the number 0x01 24 bits to the left sets that bit.
</P>
<P>The application defines an array of MONTHDAYSTATE values to represent all of the holidays I picked. Notice that the first entry of this array, representing the month of January, has two holidays:</P>
<!-- CODE //-->
<PRE>
  #define ONE   0x01
  MONTHDAYSTATE mdsHoliday[12] = {(ONE | (ONE&lt;&lt;21)), //January
    (ONE&lt;&lt;13), //February
    (ONE&lt;&lt;16), //March
    0,         //April
    0,         //May
    0,         //June
    (ONE&lt;&lt;3),  //July
    0,         //August
    0,         //September
    (ONE&lt;&lt;30), //October
    0,         //November
    (ONE&lt;&lt;24)  //December};
</PRE>
<!-- END CODE //-->
<P>The next interesting thing that the application does is to create the month calendar control and set some of its visual properties. <I>hwndMain</I> and <I>hInstance</I> are the main application window and the application HINSTANCE, respectively.</P>
<!-- CODE //-->
<PRE>
  #define IDC_MONTH  1026
  HWND hwndMonth;
  hwndMonth = CreateWindowEx(
    MONTHCAL_CLASS, NULL,
    WS_VISIBLE|WS_BORDER|WS_CHILD|MCS_DAYSTATE,
    0,0,0,0,
    hwndMain,
    (HMENU)IDC_MONTH,hInstance, NULL);
  OnInitMonthCalendar(hwndMonth, 70, 0);
</PRE>
<!-- END CODE //-->
<P>The MCS_DAYSTATE creates a month calendar control that can use day states, which we need in order to highlight our holidays.
</P>
<P>The only funny thing here is that all of the window position parameters passed to <I>CreateWindowEx</I> are zero. The reason for this is that a month calendar control can be made to display more than one month at a time. The control therefore leaves it to the application to set the size of the control to accommodate the number of months to display.</P>
<P>This is made easier by the MCM_GETMINREQRECT message. This message is sent to a month calendar control to determine the minimum height and width required to display one calendar month. When an application sends this message to a month calendar control, the control returns a RECT through the <I>lParam</I> parameter of <I>SendMessage</I>. The <I>right</I> and <I>bottom</I> members of this RECT contain the minimum width and height required, respectively.</P>
<P>Let&#146;s look at the <I>OnInitMonthCalendar</I> function to see how to use the MCM_GETMINREQRECT message:</P>
<!-- CODE //-->
<PRE>
  void OnInitMonthCalendar(HWND hwndCal, int nLeft, int nTop)
  {
    RECT r;
    SendMessage(hwndCal, MCM_GETMINREQRECT,
     0,(LPARAM)(LPRECT)&r);
    /* Resize the month calendar control window
      to accommodate one full calendar month.
     */
    SetWindowPos(hwndCal, NULL,
     nLeft,nTop,
     r.right, /cx, new width
     r.bottom, /cy, new height
     SWP_NOZORDER);
  }
</PRE>
<!-- END CODE //-->
<P>If an application wanted to display more than one month at a time, it could pass integer multiples of <I>r.right</I> and <I>r.left</I> as the <I>cx</I> and <I>cy</I> parameters of <I>SetWindowPos</I>.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="105-109.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="112-116.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 + -