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

📄 time.c

📁 wince下的源代码集合打包
💻 C
📖 第 1 页 / 共 2 页
字号:
    Minutes = Seconds / 60;    lpst->wSecond = (WORD)(Seconds % 60);    lpst->wHour = (WORD)(Minutes / 60);    lpst->wMinute = (WORD)(Minutes % 60);    lpst->wYear = (WORD)(Years + 1601);    lpst->wDay = (WORD)(Days + 1);    return TRUE;}/*	@doc BOTH EXTERNAL		@func BOOL | FileTimeToLocalFileTime | Converts a file time based on the 	Coordinated Universal Time (UTC) to a local file time.     @parm CONST FILETIME * | lpFileTime | address of UTC file time to convert      @parm LPFILETIME | lpLocalFileTime | address of converted file time 	@comm Follows the Win32 reference description without restrictions or modifications. */BOOL WINAPI FileTimeToLocalFileTime(const FILETIME * lpft, LPFILETIME lpftLocal) {	FILETIME bias;	bias.dwHighDateTime = 0;	if (UserKInfo[KINX_TIMEZONEBIAS] < 0)		bias.dwLowDateTime = - UserKInfo[KINX_TIMEZONEBIAS];	else		bias.dwLowDateTime = UserKInfo[KINX_TIMEZONEBIAS];	mul64_32_64(&bias,600000000L,&bias);	if (UserKInfo[KINX_TIMEZONEBIAS] < 0)		add64_64_64(lpft,&bias,lpftLocal);	else		sub64_64_64(lpft,&bias,lpftLocal);	return TRUE;}/*	@doc BOTH EXTERNAL		@func BOOL | LocalFileTimeToFileTime | Converts a local file time to a file time based 	on the Coordinated Universal Time (UTC).     @parm CONST FILETIME * | lpftLocal | address of local file time to convert     @parm LPFILETIME | lpft | address of converted file time 	@comm Follows the Win32 reference description without restrictions or modifications. */BOOL WINAPI LocalFileTimeToFileTime(const FILETIME *lpftLocal, LPFILETIME lpft) {	FILETIME bias;	bias.dwHighDateTime = 0;	if (UserKInfo[KINX_TIMEZONEBIAS] < 0)		bias.dwLowDateTime = - UserKInfo[KINX_TIMEZONEBIAS];	else		bias.dwLowDateTime = UserKInfo[KINX_TIMEZONEBIAS];	mul64_32_64(&bias,600000000L,&bias);	if (UserKInfo[KINX_TIMEZONEBIAS] < 0)		sub64_64_64(lpftLocal,&bias,lpft);	else		add64_64_64(lpftLocal,&bias,lpft);	return TRUE;}/*	@doc BOTH EXTERNAL		@func VOID | GetSystemTime | Retrieves the current system date and time. 	The system time is expressed in Coordinated Universal Time (UTC).     @parm LPSYSTEMTIME | lpst | address of system time structure  	@comm Follows the Win32 reference description without restrictions or modifications. */VOID WINAPI GetSystemTime (LPSYSTEMTIME lpSystemTime) {	FILETIME ft;	GetRealTime(lpSystemTime);	SystemTimeToFileTime(lpSystemTime,&ft);	LocalFileTimeToFileTime(&ft,&ft);	FileTimeToSystemTime(&ft,lpSystemTime);}/*	@doc BOTH EXTERNAL		@func BOOL | SetSystemTime | Sets the current system time and date. The system time 	is expressed in Coordinated Universal Time (UTC).     @parm CONST SYSTEMTIME * | lpst | address of system time to set 	@comm Follows the Win32 reference description without restrictions or modifications. */BOOL WINAPI SetSystemTime (const SYSTEMTIME *lpSystemTime) {	SYSTEMTIME st;	FILETIME ft;	if (!SystemTimeToFileTime(lpSystemTime,&ft) || 		!FileTimeToLocalFileTime(&ft,&ft) ||		!FileTimeToSystemTime(&ft,&st) ||		!SetRealTime(&st)) {		SetLastError(ERROR_INVALID_PARAMETER);		return FALSE;	}	if (IsAPIReady(SH_WMGR))		CeEventHasOccurred(NOTIFICATION_EVENT_TIME_CHANGE, NULL);	RefreshKernelAlarm();	return TRUE;}/*	@doc BOTH EXTERNAL		@func VOID | GetLocalTime | Retrieves the current local date and time.     @parm LPSYSTEMTIME |lpst | address of system time structure  	@comm Follows the Win32 reference description without restrictions or modifications. */VOID WINAPI GetLocalTime (LPSYSTEMTIME lpSystemTime) {	FILETIME ft;	GetRealTime(lpSystemTime);	SystemTimeToFileTime(lpSystemTime,&ft);	FileTimeToSystemTime(&ft,lpSystemTime);}// Internal file system function - gets current UMT file timeVOID GetCurrentFT(LPFILETIME lpFileTime) {	SYSTEMTIME st;	GetRealTime(&st);	SystemTimeToFileTime(&st,lpFileTime);	LocalFileTimeToFileTime(lpFileTime,lpFileTime);}/*	@doc BOTH EXTERNAL		@func BOOL | SetLocalTime | Sets the current local time and date.    @parm CONST SYSTEMTIME * | lpst | address of local time to set 	@comm Follows the Win32 reference description without restrictions or modifications. */BOOL WINAPI SetLocalTime (const SYSTEMTIME *lpSystemTime) {	SYSTEMTIME st;	FILETIME ft;	if (!SystemTimeToFileTime(lpSystemTime,&ft) || 		!FileTimeToSystemTime(&ft,&st) ||		!SetRealTime(&st)) {		SetLastError(ERROR_INVALID_PARAMETER);		return FALSE;	}	if (IsAPIReady(SH_WMGR))		CeEventHasOccurred(NOTIFICATION_EVENT_TIME_CHANGE, NULL);	RefreshKernelAlarm();	return TRUE;}/*	@doc BOTH EXTERNAL		@func DWORD | GetTimeZoneInformation | Retrieves the current time-zone parameters. 	These parameters control the translations between Coordinated Universal Time (UTC) 	and local time.     @parm LPTIME_ZONE_INFORMATION | lptzi | address of time-zone settings 	@devnote CHOOSE COMM TAG FOR ONLY ONE OF THE FOLLOWING:	@comm Follows the Win32 reference description with the following restrictions:			Always return TIME_ZONE_ID_UNKNOWN;*/#define TZIStrCpyW(D,S) memcpy(D,S,sizeof(S))#define GetKeyHKLM(valname,keyname,lptype,data,lplen)   RegQueryValueExW(HKEY_LOCAL_MACHINE,valname,(LPDWORD)keyname,lptype,(LPBYTE)data,lplen)#define OpenKeyHKLM(keyname,pkeyret)                    RegOpenKeyExW(HKEY_LOCAL_MACHINE,keyname,0, 0,pkeyret)#define GetKey(keyin,valname,lptype,data,lplen)         RegQueryValueExW(keyin,valname,0,lptype,(LPBYTE)data,lplen)#define OpenKey(keyin,keyname,pkeyret)                  RegOpenKeyExW(keyin,keyname,0, 0,pkeyret)typedef struct tagTZREG {    LONG    Bias;    LONG    StandardBias;    LONG    DaylightBias;    SYSTEMTIME StandardDate;    SYSTEMTIME DaylightDate;} TZREG;const TCHAR cszTimeZones[] = L"Time Zones";void GetDefaultTimeZoneInformation (LPTIME_ZONE_INFORMATION lpTzi) {	DWORD type, size1, size2;	HKEY hk1=0, hk2=0;	TZREG tzr;	memset(lpTzi, 0, sizeof(TIME_ZONE_INFORMATION));	memset(&tzr, 0, sizeof(tzr));	size1 = sizeof(lpTzi->StandardName);	size2 = sizeof(tzr);	// see if we have a value "Default" under HKLM\Time Zones	if(	(ERROR_SUCCESS==OpenKeyHKLM(L"Time Zones", &hk1)) &&		(ERROR_SUCCESS==GetKey(hk1, L"Default",&type,lpTzi->StandardName,&size1)) &&		(ERROR_SUCCESS==OpenKey(hk1, lpTzi->StandardName, &hk2)) &&    	(ERROR_SUCCESS==GetKey(hk2,L"TZI",&type,&tzr,&size2)) )    {		// Read the value "TZI" and "Dlt" under HKLM\Time Zones\<time zone std name>		size1 = sizeof(lpTzi->DaylightName);	    GetKey(hk2,L"Dlt",&type,lpTzi->DaylightName,&size1);   		lpTzi->Bias = tzr.Bias;        lpTzi->StandardBias = tzr.StandardBias;        lpTzi->DaylightBias = tzr.DaylightBias;        lpTzi->StandardDate = tzr.StandardDate;		lpTzi->DaylightDate = tzr.DaylightDate;	}	else	{		// Default to Redmond, WA for now		lpTzi->Bias = 480;		TZIStrCpyW(lpTzi->StandardName,L"Pacific Standard Time");		lpTzi->StandardDate.wYear = 0;		lpTzi->StandardDate.wMonth = 10;		lpTzi->StandardDate.wDayOfWeek = 0;		lpTzi->StandardDate.wDay = 5;		lpTzi->StandardDate.wHour = 2;		lpTzi->StandardDate.wMinute = 0;		lpTzi->StandardDate.wSecond = 0;		lpTzi->StandardDate.wMilliseconds = 0;		lpTzi->StandardBias = 0;		TZIStrCpyW(lpTzi->DaylightName,L"Pacific Daylight Time");		lpTzi->DaylightDate.wYear = 0;		lpTzi->DaylightDate.wMonth = 4;		lpTzi->DaylightDate.wDayOfWeek = 0;		lpTzi->DaylightDate.wDay = 1;		lpTzi->DaylightDate.wHour = 2;		lpTzi->DaylightDate.wMinute = 0;		lpTzi->DaylightDate.wSecond = 0;		lpTzi->DaylightDate.wMilliseconds = 0;		lpTzi->DaylightBias = -60;	}	if(hk1) RegCloseKey(hk1);	if(hk2) RegCloseKey(hk2);	ASSERT(lpTzi->StandardName && lpTzi->DaylightName);}DWORD WINAPI GetTimeZoneInformation (LPTIME_ZONE_INFORMATION lpTzi) {	DWORD type;	DWORD size = sizeof(TIME_ZONE_INFORMATION);	// check for existing time-zone struct	if (GetKeyHKLM(L"TimeZoneInformation",L"Time",&type,(LPBYTE)lpTzi,&size)) 	{		// fallback to default		GetDefaultTimeZoneInformation(lpTzi);	}	if (lpTzi->Bias + lpTzi->StandardBias == UserKInfo[KINX_TIMEZONEBIAS])		return TIME_ZONE_ID_STANDARD;	else if (lpTzi->Bias + lpTzi->DaylightBias == UserKInfo[KINX_TIMEZONEBIAS])		return TIME_ZONE_ID_DAYLIGHT;	return TIME_ZONE_ID_UNKNOWN;}BOOL IsValidTZISystemTime(const SYSTEMTIME *lpst) {	if (IsValidSystemTime(lpst))		return TRUE;	if (!lpst->wYear && (lpst->wDayOfWeek <= 6) && (lpst->wDay >= 1) && (lpst->wDay <= 5))		return TRUE;	if (!lpst->wMonth)		return TRUE;	return FALSE;}/*	@doc BOTH EXTERNAL		@func BOOL | SetTimeZoneInformation | Sets the current time-zone parameters. 	These parameters control translations from Coordinated Universal Time (UTC) to local time.    @parm CONST TIME_ZONE_INFORMATION * | lptzi | address of time-zone settings  	@comm Follows the Win32 reference description without restrictions or modifications. */BOOL WINAPI SetTimeZoneInformation (const TIME_ZONE_INFORMATION *lpTzi) {	DWORD dwDisp;	HKEY  hKey=NULL;		if (!IsValidTZISystemTime(&lpTzi->StandardDate) ||		!IsValidTZISystemTime(&lpTzi->DaylightDate)) {		SetLastError(ERROR_INVALID_PARAMETER);		return FALSE;	}	SetTimeZoneBias(lpTzi->Bias+lpTzi->StandardBias,lpTzi->Bias+lpTzi->DaylightBias);	if(ERROR_SUCCESS==RegCreateKeyExW(HKEY_LOCAL_MACHINE, L"Time", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, &dwDisp) && hKey) {		if(ERROR_SUCCESS==RegSetValueExW(hKey, L"TimeZoneInformation", 0, REG_BINARY, (LPBYTE)lpTzi,sizeof(TIME_ZONE_INFORMATION))) {			if (IsAPIReady(SH_WMGR))				CeEventHasOccurred(NOTIFICATION_EVENT_TZ_CHANGE, NULL);			RegCloseKey(hKey);			return TRUE;		}		RegCloseKey(hKey);	}	SetLastError(ERROR_OUTOFMEMORY);	return FALSE;}

⌨️ 快捷键说明

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