/** * @file XTPCalendarTimeZoneHelper.h * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ #if !defined(_XTPCALENDARTIMEZONEHELPER_H__) # define _XTPCALENDARTIMEZONEHELPER_H__ # if _MSC_VER > 1000 # pragma once # endif // _MSC_VER > 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" /** @cond */ class CXTPCalendarTimeZone; XTP_DEFINE_SMART_PTR_INTERNAL(CXTPCalendarTimeZone) /** @endcond */ /** * @brief * This class extends the TIME_ZONE_INFORMATION structure. * * @details * It has additional data members to represent full information about * time zone. * Also it implements some helper functions and OLE interface methods. * * @see TIME_ZONE_INFORMATION * @see CXTPCalendarTimeZones * * MSDN Articles: * INFO: Retrieving Time-Zone Information * KB115231, Q115231 * * HOWTO: Change Time Zone Information Using Visual Basic * KB221542, Q221542 */ class _XTP_EXT_CLASS CXTPCalendarTimeZone : public CXTPCmdTarget , public TIME_ZONE_INFORMATION { /** @cond */ friend class CXTPCalendarTimeZones; DECLARE_DYNAMIC(CXTPCalendarTimeZone) /** @endcond */ public: /** * @brief * Default object constructor. * * @param pTZInfo Pointer to a TIME_ZONE_INFORMATION data to initialize * created object data. * * @see ~CXTPCalendarTimeZone() * @see TIME_ZONE_INFORMATION */ CXTPCalendarTimeZone(const TIME_ZONE_INFORMATION* pTZInfo = NULL); /** * @brief * Default object constructor. * * @param pTZInfoEx Pointer to a source data object. * * @see ~CXTPCalendarTimeZone() * @see TIME_ZONE_INFORMATION */ CXTPCalendarTimeZone(const CXTPCalendarTimeZone* pTZInfoEx); /** * @brief * Default object destructor. * * @see CXTPCalendarTimeZone() */ virtual ~CXTPCalendarTimeZone(); /** * @brief * Get a time zone display string value. * * @return A string value like: "(GMT+02:00) Athens, Beirut, Istanbul, Minsk" */ CString GetDisplayString() const; /** * @brief * Get a time zone order index value. * * @details * This index value is used to sort time zones in the right order. * * @return A time zone order index value. */ DWORD GetIndex() const; /** * @brief * Compare 2 time zones data. * * @param pTZI2 Points to a TIME_ZONE_INFORMATION object. * * @return TRUE if time zones data related to the same time zone, * otherwise - FALSE. */ BOOL IsEqual(const TIME_ZONE_INFORMATION* pTZI2) const; /** * @brief * Copy operator. * * @param rTZInfo Pointer to a source data object. * * @return A Constant reference to updated object * * @see CXTPCalendarTimeZone() */ const CXTPCalendarTimeZone& operator=(const CXTPCalendarTimeZone& rTZInfo); /** * @brief * Get full information about the specified time zone. * * @param pTZIdata Pointer to a time zone data object. * * @details * Retrieve additional information from the registry. * * @return A smart pointer to a CXTPCalendarTimeZone object. * * @see CXTPCalendarTimeZones */ static CXTPCalendarTimeZonePtr AFX_CDECL GetTimeZoneInfo(const TIME_ZONE_INFORMATION* pTZIdata); protected: CString m_strDisplayString; /**< A time zone display string stored value. */ DWORD m_dwIndex; /**< A time zone order index stored value. */ # ifdef _XTP_ACTIVEX BSTR OleGetStandardName(); void OleSetStandardName(LPCTSTR bstrStandardName); BSTR OleGetDaylightName(); void OleSetDaylightName(LPCTSTR bstrDaylightName); LPDISPATCH OleGetStandardDate(); void OleSetStandardDate(LPDISPATCH pDispStandardDate); LPDISPATCH OleGetDaylightDate(); void OleSetDaylightDate(LPDISPATCH pDispDaylightDate); BSTR OleGetDisplayString(); BOOL OleIsEqual(LPDISPATCH pDispTZI2); protected: DECLARE_DISPATCH_MAP() DECLARE_INTERFACE_MAP() DECLARE_OLETYPELIB_EX(CXTPCalendarTimeZone); # endif }; /** * @brief * This class represents a simple array collection of CXTPCalendarTimeZone * objects. * * @details * Array indexes always start at position 0. * An InitFromRegistry() method is used to read all time zones from the * registry and add them to the collection. * Also it implements some helper functions and OLE interface methods. * * @see TIME_ZONE_INFORMATION * @see CXTPCalendarTimeZone. * * MSDN Articles: * INFO: Retrieving Time-Zone Information * KB115231, Q115231 * * HOWTO: Change Time Zone Information Using Visual Basic * KB221542, Q221542 */ class _XTP_EXT_CLASS CXTPCalendarTimeZones : public CXTPCmdTarget { /** @cond */ DECLARE_DYNAMIC(CXTPCalendarTimeZones) /** @endcond */ public: /** * @brief * Default object constructor. * * @see ~CXTPCalendarTimeZones() */ CXTPCalendarTimeZones(); /** * @brief * Default object destructor. * * @see CXTPCalendarTimeZones() */ virtual ~CXTPCalendarTimeZones(); /** * @brief * Reads all time zones from the registry and adds them to the * collection. * * @return TRUE - if all time zones were successfully read, * otherwise - FALSE. */ BOOL InitFromRegistry(); /** * @brief * This member function is used to obtain the number of elements in * this collection. * * @return An int that contains the number of items in the collection. * * @see GetAt() */ int GetCount() const; /** * @brief * Call this method to get an element at the specified numeric index. * * @param nIndex An integer index that is greater than or equal to 0 * and less than the value returned by GetCount. * * @return The pointer to the CXTPCalendarTimeZone element currently at this * index. * * @see GetCount() */ CXTPCalendarTimeZone* GetAt(long nIndex) const; /** * @brief * This method is used to find time zone information using a * specified time zone's data. * * @param pTZI2 Pointer to a time zone data object. * * @return The pointer to the first object in the collection * that matches the requested time zone. * NULL if the such object is not found. */ CXTPCalendarTimeZone* Find(const TIME_ZONE_INFORMATION* pTZI2) const; public: /** * @brief * This structure represents a format of binary data stored in the * "TZI" registry key. * * @see Microsoft KB115231, TIME_ZONE_INFORMATION * @see XTP_CALENDAR_TZIRegValName_DATA * @see XTP_CALENDAR_TIMEZONESKEY_NT * @see XTP_CALENDAR_TIMEZONESKEY_9X */ struct REGISTRY_TIMEZONE_INFORMATION { LONG Bias; /**< Current bias for local time translation on this computer, in minutes.*/ LONG StandardBias; /**< Bias value to be used during local time translations that occur during standard time.*/ LONG DaylightBias; /**< Bias value to be used during local time translations that occur during daylight saving time.*/ SYSTEMTIME StandardDate; /**< A SYSTEMTIME structure that contains a date and local time when the transition from daylight saving time to standard time occurs on this operating system.*/ SYSTEMTIME DaylightDate; /**< A SYSTEMTIME structure that contains a date and local time when the transition from standard time to daylight saving time occurs on this operating system.*/ }; /** * @brief * This method is used to read a string value from the registry. * * @param hKey [in] Parent key handle. * @param pcszValueName [in] Value key name. * @param rstrValue [out] CString object reference to store value. * * @return TRUE if successful, otherwise - FALSE. * * @see GetRegBSTR() */ static BOOL AFX_CDECL GetRegStr(HKEY hKey, LPCTSTR pcszValueName, CString& rstrValue); /** * @brief * This method is used to read a UNICODE string value from the registry. * * @param hKey [in] Parent key handle. * @param pcszValueNameW [in] Value key name in the UNICODE format. * @param rbstrValue [out] BSTR object reference to store value. * * @details * It is used to get UNICODE strings without conversion to MBCS. * If the rbstrValue parameter is not NULL, the SysFreeString() * API function is called to erase value. * * @return TRUE if successful, otherwise - FALSE. * * @see GetRegStr() */ static BOOL AFX_CDECL GetRegBSTR(HKEY hKey, LPCWSTR pcszValueNameW, BSTR& rbstrValue); /** * @brief * This method is used to read a DWORD value from the registry. * * @param hKey [in] Parent key handle. * @param pcszValueName [in] Value key name. * @param rdwValue [out] DWORD variable reference to store value. * * @return TRUE - if successful, otherwise - FALSE. */ static BOOL AFX_CDECL GetRegDWORD(HKEY hKey, LPCTSTR pcszValueName, DWORD& rdwValue); /** * @brief * This method is used to read a time zone's information stored as a * binary value in the registry. * * @param hKey [in] Parent key handle. * @param pcszValueName [in] Value key name. * @param rRegTZI [out] REGISTRY_TIMEZONE_INFORMATION object * reference to store value. * * @return TRUE - if successful, otherwise - FALSE. */ static BOOL AFX_CDECL GetRegTZI(HKEY hKey, LPCTSTR pcszValueName, REGISTRY_TIMEZONE_INFORMATION& rRegTZI); protected: //-------------------------------------------------------------- CXTPCalendarPtrCollectionT m_arTZInfo; /**< Collection to store CXTPCalendarTimeZone object pointers;*/ private: int CompareTZI(const CXTPCalendarTimeZone* pTZI1, const CXTPCalendarTimeZone* pTZI2, BOOL bUseIndex) const; void ParseDisplayStr(LPCTSTR str, int& rnBias, CString& rstrPlace) const; int GetDigit(TCHAR ch) const; protected: # ifdef _XTP_ACTIVEX int OleGetItemCount(); LPDISPATCH OleGetItem(long nIndex); DECLARE_DISPATCH_MAP() DECLARE_INTERFACE_MAP() DECLARE_OLETYPELIB_EX(CXTPCalendarTimeZones); DECLARE_ENUM_VARIANT(CXTPCalendarTimeZones); # endif }; //================================================================ # ifdef _XTP_ACTIVEX class _XTP_EXT_CLASS CXTPCalendarSystemTime : public CXTPCmdTarget , public SYSTEMTIME { public: CXTPCalendarSystemTime(const SYSTEMTIME* pTime = NULL); virtual ~CXTPCalendarSystemTime(); protected: DECLARE_DYNAMIC(CXTPCalendarSystemTime) DECLARE_DISPATCH_MAP() DECLARE_INTERFACE_MAP() DECLARE_OLETYPELIB_EX(CXTPCalendarSystemTime); }; # endif //////////////////////////////////////////////////////////////////////////// # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" #endif // !defined(_XTPCALENDARTIMEZONEHELPER_H__)