Fortune Telling Collection - Ziwei fortune-telling - How to modify the menu option of system time through mfc application? The menu that pops up when you right-click the system time in the lower right corner of the computer. . . 100 has been distributed

How to modify the menu option of system time through mfc application? The menu that pops up when you right-click the system time in the lower right corner of the computer. . . 100 has been distributed

This kind of problem is everywhere.

Use the API function SetLocalTime to set the local time.

1. ParseDateTime, function prototype: boolpparsdatetime (lpctstr lpszdate, dword).

dwFlags = 0,LCID lcid = LANG _ USER _ DEFAULT);

LpszDate is a specified date and time, which can take many forms, such as "25 January1996", "8: 30: 00" and "20: 30: 00".

"1 25th of the month, 1996 8:30:00" "8:30:00"

DwFlags has three values, LOCALE _ NOUSEROVERRIDE, VAR_TIMEVALUEONLY,

Var _ datevalueonly. locale _ nouseroverride is the default way to use the system, and VAR_TIMEVALUEONLY is the ignore day.

Period, under this option, the date will be set to 0, that is, 1899 12.30, and under VAR_DATEVALUEONLY, the time will be set to 0, that is, midnight.

As for the third parameter lcid, it specifies the conversion mode and language support. MSDN has a very detailed table, you can have a look if you are interested.

COleDateTime also provides a function to get the time, such as GetYear ().

Note that if no date is specified, the converted date will automatically become 0, that is, 1899, which is very dangerous. I was going to steal a lazy job, but I didn't specify it. Who knows to be lazy and let me know?

Prototype of SetLocalTime function: bool setlocaltime (const system time

* lpSystemTime);

The input parameter lpSystemTime is a parameter of type SystemTime. If the setting is successful, it will return true, and the local time will be specified by lpSystemTime.

Time, otherwise return false. Look at the format of SYSTEMTIME: typedefstruct _ systemtime {wordwyear;

Word wmonthword wdayofweekword wday word wHourWORD wMinute word

Wsecond word wmilliseconds} systemtime, * PSYSTEMTIME The meaning of each member needs no explanation.

Let's see how to use the SYSTEMTIME structure and the SetLocalTime function to set the local time. SYSTEMTIME st

Saint Wyre = 2007; ST . w month = 1 1; st.wDay = 24ST . whour = 3; ST. WM minutes =

14; ST . w second = 0; ST . wmillseconds = 0; setsystem time(& amp; ST);

Comparing the structure of SYSTEMTIME, we can find that all members except wDayOfWeek are assigned values, even wMilliseconds. Use this

When setting the system time, the wDayOfWeek member will be ignored, and the assignment of this member can be omitted (even if the assignment is not considered), but all other members must be assigned in time, otherwise,

Unable to set the time successfully.

If you only want to set a few items, you can use the GetLocalTime function to get the current local time first, and then modify the corresponding items, as follows:

SYSTEMTIME stGetLocalTime(& amp; ST); ST . whour = 3;

set local time(& amp; ST); This way is much more convenient than the above.

The method mentioned above is to set each item separately. In VC, there is also a way to set all items at once, using the COleDateTime class.

COleDateTime tmSYSTEMTIME sttm。 parse datetime(" 2007- 1 1-24 8:00:00 ");

tm。 GetAsSystemTime(ST); set local time(& amp; ST); This process should be easy to understand, but there are several points to pay attention to.

The difference between SetLocalTime and SetSystemTime

The usage of SetSystemTime is basically the same as that of SetLocalTime, so I won't repeat it here. Almost lies in that the parameter brought by SetSystemTime specifies UTC time (China).

International standard time), that is to say, my computer is designated as the East Eighth District. In this case, after using the SetSystemTime setting, the system time will be eight hours faster than the time set in the parameters.

Time.

In addition, the time set by these two functions is valid for each system of the local machine. I was curious whether I would change the time under windows or linux. It turns out that it is.

Yes

Use COleDateTimeSpan class to add and subtract time. COleDateTime tmCOleDateTimeSpan ts

tm。 parse datetime(" 2007- 1 1-24 8:00:00 "); ts。 SetDateTimeSpan(0,8,0,- 14);

TM+= ts; SYSTEMTIME sttm。 GetAsSystemTime(ST); set local time(& amp; ST);

This program is also easy to understand. Don't say anything You just need to figure out whether to add or subtract this time difference. I often can't turn around.

In addition, there seems to be a permission problem under XP, and people who are not administrators may not be able to modify it like this. I haven't tried this. Let me know who has tried.

Finally, after modifying the system time, it is easy to have problems at compile time. It is best to change the time back every time you compile and recompile, or use rebuild.

All, all recompile, otherwise it is very likely that even if compiled, the executable file will still be unmodified.