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

📄 apf.htm

📁 VC 21天 学习VC 的好东西
💻 HTM
📖 第 1 页 / 共 5 页
字号:
</PRE><P>When this code is run, the resulting rectangle rcDst will hold the coordinates(50,220)-(150,26).</P><P><A HREF="javascript:popUp('33fig02.gif')"><B>FIGURE F.2.</B></A><B> </B><I>Theeffects of a subtraction operation on two partially overlapping rectangles.</I></P><P>You can increase or decrease the size of a rectangle using InflateRect() and DeflateRect().These both have several forms that accept various types of parameters, as shown inTable F.6.</P><P><H4>TABLE F.6.&nbsp;&nbsp;PARAMETER FORMS FOR InflateRect AND DeflateRect.</H4><P><TABLE BORDER="1">	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT"><I>Parameters</I></TD>		<TD ALIGN="LEFT"><I>Description</I></TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">(int x, int y)</TD>		<TD ALIGN="LEFT">Inflate or deflate the left and right sides by the x value and the top and bottom			sides by the y value.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">(SIZE size)</TD>		<TD ALIGN="LEFT">Inflate or deflate the left and right sides by size.cx and the top and bottom sides			by size.cy.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">(LPCRECT lpRect)</TD>		<TD ALIGN="LEFT">Inflate each side by the corresponding left, top, right, and bottom values from lpRect.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">(int l, int t, int r, int b)</TD>		<TD ALIGN="LEFT">Inflate each side by the corresponding left, top, right, and bottom values.</TD>	</TR></TABLE></P><P>For example, the following code inflates rcOne and deflates rcTwo:</P><P><PRE>CRect rcOne(10,10,100,100);CRect rcTwo(50,50,150,200);rcOne.InflateRect(5,5);rcTwo.DeflateRect(10,20,30,40);</PRE><P>After these lines have run, rcOne will be set to the coordinates (5,5)-(105,105)and rcTwo will be set to the coordinates (60,70)-(120,160).</P><P>You can perform hit-testing by determining whether a specified point (perhapsfrom a mouse click) lies within the bounds of a rectangle by calling PtInRect() andpassing the point to be tested. If the point does lie within the rectangle, a TRUEvalue is returned; otherwise a FALSE value is returned.</P><P>In the following lines, the Hit! - ptTest1 message is displayed because ptTest1does lie within the rcTestArea test area, whereas ptTest2 doesn't, so PtInRect()returns TRUE for ptTest1 and FALSE for ptTest2:</P><P><PRE>CRect rcTestArea(10,20,440,450);CPoint ptTest1(200,200), ptTest2(500,500);if (rcTestArea .PtInRect(ptTest1))   &Acirc;AfxMessageBox(&quot;Hit! - ptTest1&quot;);if (rcTestArea .PtInRect(ptTest2)) </PRE><H3><A NAME="Heading9"></A>&Acirc;AfxMessageBox(&quot;Hit! - ptTest2&quot;);</H3><P>There are also several operator overloads for use with CRect objects, as shownin Table F.7.</P><P><H4>TABLE F.7.&nbsp;OPERATOR OVERLOADS USED WITH CRect.</H4><P><TABLE BORDER="1">	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT"><I>Operator</I></TD>		<TD ALIGN="LEFT"><I>Description</I></TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">=</TD>		<TD ALIGN="LEFT">Copies all the coordinates from the right rectangle operand to the left rectangle,			like an ordinary numeric assignment.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">+</TD>		<TD ALIGN="LEFT">Either displaces a rectangle position if a CPoint or CSize object is added to a rectangle			or inflates the coordinates with their corresponding counterparts if a CRect object			is added.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">-</TD>		<TD ALIGN="LEFT">Same as +, except that the coordinates are displaced in a negative direction or deflated			if a CRect is used.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">+=</TD>		<TD ALIGN="LEFT">Same overall effect as + but affects only the current rectangle.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">-=</TD>		<TD ALIGN="LEFT">Same overall effect as - but affects only the current rectangle.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">&amp;</TD>		<TD ALIGN="LEFT">Creates an intersection rectangle from the two rectangle operands.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">|</TD>		<TD ALIGN="LEFT">Creates a union rectangle from the two rectangle operands.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">&amp;=</TD>		<TD ALIGN="LEFT">Same overall effect as &amp; but affects only the current rectangle.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">|=</TD>		<TD ALIGN="LEFT">Same overall effect as | but affects only the current rectangle.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">==</TD>		<TD ALIGN="LEFT">Returns TRUE if the rectangles are identical, otherwise FALSE.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">!=</TD>		<TD ALIGN="LEFT">Returns FALSE if the rectangles are identical; otherwise returns TRUE.</TD>	</TR></TABLE></P><P>The following lines show some of the CRect operator overloads being used to manipulatethe rcStart rectangle:</P><P><PRE>CRect rcStart(10,10,100,100);rcStart = rcStart + CPoint(5,5);rcStart -= CSize(5,5);rcStart    += CRect(1,2,3,4);if (rcStart == CRect(9,8,103,104)) AfxMessageBox(&quot;TRUE&quot;);</PRE><P>The final condition returns TRUE, thus displaying the message box because thefinal coordinates are (9,8)-(103,104).</P><BLOCKQUOTE>	<P><HR><B>USING THE </B>NormalizeRect()<B> FUNCTION</B></P>	<P>Sometimes you might perform an operation that makes the top-left point hold values	greater than the bottom-right point. If this is so, the width or height might be	negative, causing other functions to fail. If you suspect this might happen, you	can call the NormalizeRect() function to correct the coordinates so that the top-left	coordinates have lower values than the bottom-right coordinates. <HR></BLOCKQUOTE><H3><A NAME="Heading10"></A>Using the CSize Class</H3><P>The CSize class encapsulates the SIZE structure and provides several constructorsand operator overloads that manipulate the internal cx and cy values that definea size. The various constructors you can use to create an instance of a CSize objectare shown in Table F.8.</P><P><H4>TABLE F.8.&nbsp;&nbsp;CONSTRUCTOR TYPES FOR THE CSize CLASS.</H4><P><TABLE BORDER="1">	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT"><I>Constructor Definition</I></TD>		<TD ALIGN="LEFT"><I>Description</I></TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">CSize()</TD>		<TD ALIGN="LEFT">Creates an uninitialized CSize object.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">CSize(SIZE sizeInit)</TD>		<TD ALIGN="LEFT">Copies the cx and cy values from another CSize object or SIZE structure.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">CSize(initCX, initCY)</TD>		<TD ALIGN="LEFT">Initializes the object with initCX for the horizontal size and initCY for the vertical			size.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">CSize(POINT ptInit)</TD>		<TD ALIGN="LEFT">Initializes the object with the x and y values from a CPoint object or POINT structure.</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">CSize(DWORD dwSize)</TD>		<TD ALIGN="LEFT">Sets the cx value to the low-word (bottom 16 bits) of dwSize and the cy value to			the high-word (to 16 bits) of dwSize.</TD>	</TR></TABLE></P><P>You can manipulate the cx and cy members directly like this:</P><P><PRE>CSize tstSize(10,10);tstSize.cx = tstSize.cy * 2;</PRE><P>The only functions that the CSize class offers are operator overloads, as shownin Table F.9.</P><P><H4>TABLE F.9.&nbsp;&nbsp;OPERATOR OVERLOADS USED WITH CSize.</H4><P><TABLE BORDER="1" WIDTH="100%">	<TR>		<TD WIDTH="21%"><I>Operator</I></TD>		<TD WIDTH="79%"><I>Description</I></TD>	</TR>	<TR>		<TD WIDTH="21%">+</TD>		<TD WIDTH="79%">Add two size objects</TD>	</TR>	<TR>		<TD WIDTH="21%">-</TD>		<TD WIDTH="79%">Subtract one size object from another</TD>	</TR>	<TR>		<TD WIDTH="21%" HEIGHT="13">+=</TD>		<TD WIDTH="79%" HEIGHT="13">Add a SIZE object</TD>	</TR>	<TR>		<TD WIDTH="21%">-=</TD>		<TD WIDTH="79%">Subtract a SIZE object</TD>	</TR>	<TR>		<TD WIDTH="21%">==</TD>		<TD WIDTH="79%">Determine whether the two sizes are the same and return TRUE if identical</TD>	</TR>	<TR>		<TD WIDTH="21%">!=</TD>		<TD WIDTH="79%">Determine whether the two sizes are different and return TRUE if different</TD>	</TR></TABLE></P><P>These can be used just like normal arithmetic operators and affect both the cxand cy members, as shown in the following lines that manipulate the contents of tstSize:</P><P><PRE>CSize tstSize(10,15);tstSize += tstSize + tstSize - CSize(1,2);if (tstSize == CSize(29,43)) AfxMessageBox(&quot;TRUE&quot;);</PRE><P>When run, this code will display the TRUE message box message because tstSizeends up as the size 29&yen;43.</P><P><H2><A NAME="Heading11"></A>Using the Time-Handling Classes</H2><P>The capability to store dates and times is a common requirement for many applications.You will probably also need to calculate elapsed times and time spans between storeddate and time values and be able to format those into user-readable text strings.</P><P>MFC provides four classes to handle all the aspects of date and time manipulationand storage. Originally, there were just two classes; CTime and CTimeSpan, whichare based on the UNIX time_t (4 byte long value) system (the number of elapsed secondssince 1970). However, granularity of only one second and a limited range of datesbetween 1970 and 2038 proved too restrictive for many applications. Hence, two newreplacement classes, COleDateTime and COleDateTimeSpan, are now also supplied andshould be used in preference to CTime and CTimeSpan in newer applications.</P><P>COleDateTime is based on an underlying DATE structure (which is actually justa double value). This greater capacity of storage type lets COleDateTime cover arange of dates between January 1, 100, and December 31, 9999, and down to an approximateresolution of 1 millisecond. The difference between two COleDateTime values can berepresented and manipulated by the COleDateTimeSpan object.</P><P>Because of the similarity between the CTime class and the newer COleDateTime class,the following sections just describe COleDateTime, although many of the functionsare identical in the CTime versions.</P><BLOCKQUOTE>	<P><HR><B>USING </B>CTime<B> WITH DATABASES</B></P>	<P>You might find it convenient to use CTime when using ODBC-based databases because	the RFX recordset transfer macros know only how to handle CTime objects directly	and don't know how to handle COleDateTime objects without conversion. If you use	DAO databases, COleDateTime can be used directly. <HR></BLOCKQUOTE><H3><A NAME="Heading12"></A>Using the COleDateTime Class</H3><P>COleDateTime is connected with OLE in that it can be used in conjunction withthe VARIANT structure, often used in OLE automation. Because of the wide range ofdate and time storage systems, especially in OLE environments, COleDateTime mustbe capable of converting between all these various types. This support is reflectedin its many constructor forms, as shown in Table F.10.</P><P><H4>TABLE F.10.&nbsp;&nbsp;CONSTRUCTOR TYPES USED WITH COleDateTime.</H4><P><TABLE BORDER="1">	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT"><I>Constructor Definition</I></TD>		<TD ALIGN="LEFT"><I>Description</I></TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">COleDateTime()</TD>		<TD ALIGN="LEFT">Creates an uninitialized COleDateTime object</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">COleDateTime(const COleDateTime&amp; datesrc)</TD>		<TD ALIGN="LEFT">Copies the values from another COleDateTime object</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">COleDateTime(int nYear, int nMonth, int nDay, int nHour, int nMinute, int nSecond)</TD>		<TD ALIGN="LEFT">Initializes the date and time from the values passed</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">COleDateTime(const VARIANT&amp; varSrc)</TD>		<TD ALIGN="LEFT">Converts a date time from a VARIANT structure</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">COleDateTime(DATE dtSrc)</TD>		<TD ALIGN="LEFT">Copies a date time from a DATE structure</TD>	</TR>	<TR ALIGN="LEFT" VALIGN="TOP">		<TD ALIGN="LEFT">COleDateTime(time_t timeSrc)</TD>		<TD ALIGN="LEFT">Copies a date time from a UNIX-style time_t structure</TD>	</TR>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -