[ Pobierz całość w formacie PDF ]
.Format( Today is %a %b %d, %Y ));When run, the time will then be displayed in a message box in the following format:Today is Sat Apr 04, 1998 034 31240-9 APP F 4/27/00 1:13 PM Page 722722 Appendix FYou can get COleDateTime to attempt to determine a date and time by callingParseDateTime() and passing a string for it to parse and a flag value to specify that onlythe date or the time component is required.ParseDateTime() will then scan the stringfor time in the format HH:MM:SS, and a date in the format DD/MM/YYYY, or in a longformat such as January 18th, 1998.If you only want to scan for the time, youcan pass VAR_TIMEVALUEONLY for the second parameter flag value, alternativelyVAR_DATEVALUEONLY for just the date.If you don t want the users locale preferences tobe used to indicate the string format to check for, you can pass LOCALE_NOUSEROVERRIDEas this flag value.There are also several operator overloads you can use to add and subtractCOleDateTimeSpans and to compare date and time values with other date and time val-ues as shown in Table F.12.TABLE F.12.OPERATOR OVERLOADS USED IN COleDateTime.Operator Description= Copy a date/time value from another COleDateTime object, VARIANT structure, DATEstructure, time_t structure, SYSTEMTIME structure, or FILETIME structure.+ Add a COleDateTimeSpan value to a COleDateTime value.- Subtract a COleDateTimeSpan from a COleDateTime value or two COleDateTimeobjects from each other to yield a COleDateTimeSpan result.+= Add a COleDateTimeSpan value to the current COleDateTime object.-= Subtract a COleDateTimeSpan value from the current COleDateTime object.== Check whether two COleDateTime objects hold an identical date and time.!= Check whether two COleDateTime objects hold different dates and times.Check whether one COleDateTime object is greater than another.= Check whether one COleDateTime object is greater than or equal to another.Using the COleDateTimeSpan ClassACOleDateTimeSpan object can hold the difference between two COleDateTime objects.You can create one by subtracting one COleDateTime object from another or by usingone of the COleDateTimeSpan constructor forms shown in Table F.13. 034 31240-9 APP F 4/27/00 1:13 PM Page 723Using MFC s Helper Classes 723TABLE F.13.CONSTRUCTOR TYPES USED WITH COleDateTimeSpan.Constructor Definition DescriptionCOleDateTimeSpan() Create a time span set to zero.COleDateTimeSpan(const Copy the time span fromCOleDateTimeSpan& srcSpan) another COleDateTimeSpan object.COleDateTimeSpan(long Initialize the time span withlDays, int nHours, the passed parameter values.int nMins, int nSecs)COleDateTimeSpan(double Initialize the time span withdSpanSrc) the number of days passed value.After you have a COleDateTimeSpan object, you can check or set its status using theGetStatus() and SetStatus() functions just like the COleDateTime object.The onlydifferences are that the flag values are COleDateTimeSpan::valid andCOleDateTimeSpan::invalid.You can also set a time span by passing the number of days, hours, minutes, and secondsas integer parameters to SetDateTimeSpan().You can then retrieve these values from avalid COleDateTimeSpan object by calling the GetDays(), GetHours(), GetMinutes(),and GetSeconds() functions that all return long values representing each portion of thetime span value.If you want to retrieve the overall time span expressed in days, hours,minutes, or seconds in one double value, you can call GetTotalDays(),GetTotalHours(), GetTotalMinutes(), or GetTotalSeconds(), respectively.You can format COleDateTimeSpan values as strings in the same way as COleDateTimevalues by passing a format string using the codes appropriate to time spans fromTable F.11.Several operator overloads help you use COleDateTimeSpan objects arithmetically to addand subtract time spans to and from each other and also use them in conditions, as shownin Table F.14.FTABLE F.14.OPERATOR OVERLOADS USED IN COleDateTimeSpan.Operator Description= Copies time spans from other time span values+ Adds two time spans- Subtracts one time span from anothercontinues 034 31240-9 APP F 4/27/00 1:13 PM Page 724724 Appendix FTABLE F.14.CONTINUEDOperator Description+= Adds a time span to the current object-= Subtracts a time span from the current object== Checks to see whether two time spans are identical!= Checks to see whether two time spans are differentChecks to see whether one time span is greater than another= Checks to see whether one time span is greater than or equal to anotherThe following sample code shows how two COleDateTime objects can be subtracted toyield a COleDateTimeSpan using the minus (-) operator overload:COleDateTime dtMoonwalk;dtMoonwalk = COleDateTime(1969,7,20,0,0,0);COleDateTimeSpan dtDiff =COleDateTime::GetCurrentTime()- dtMoonwalk;CString strMessage;strMessage.Format( Days since first moonwalk: %d  ,(int)dtDiff.GetTotalDays());AfxMessageBox(strMessage);Using the String Manipulation ClassFor several years C programmers secretly envied one (and only one) tool that BASICprogrammers had at their disposal: sophisticated and easy string handling.With C++,that functionality can be naturally replicated, and has been with MFC s CString class.String handling is a very common application requirement, and Visual C++ applicationstend to be littered with instances of CString-based objects to accomplish the task.Using the CString ClassYou can easily construct CString objects as an empty string or initialized by passing oneof many differing types of text representation systems to the constructor.The variousforms of CString construction are shown in Table F.15. 034 31240-9 APP F 4/27/00 1:13 PM Page 725Using MFC s Helper Classes 725TABLE F.15.CONSTRUCTOR TYPES USED WITH CString [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • swpc.opx.pl
  •