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

📄 wizard.c

📁 ReactOS是一些高手根据Windows XP的内核编写出的类XP。内核实现机理和API函数调用几乎相同。甚至可以兼容XP的程序。喜欢研究系统内核的人可以看一看。
💻 C
📖 第 1 页 / 共 5 页
字号:
  while (Entry != NULL)
    {
      if (Entry->Index >= Index)
	return Entry;

      Entry = Entry->Next;
    }

  return NULL;
}


static VOID
CreateTimeZoneList(PSETUPDATA SetupData)
{
  TCHAR szKeyName[256];
  DWORD dwIndex;
  DWORD dwNameSize;
  DWORD dwValueSize;
  LONG lError;
  HKEY hZonesKey;
  HKEY hZoneKey;

  PTIMEZONE_ENTRY Entry;
  PTIMEZONE_ENTRY Current;

  if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
		   _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones"),
		   0,
		   KEY_ALL_ACCESS,
		   &hZonesKey))
    return;

  dwIndex = 0;
  while (TRUE)
    {
      dwNameSize = 256 * sizeof(TCHAR);
      lError = RegEnumKeyEx(hZonesKey,
			    dwIndex,
			    szKeyName,
			    &dwNameSize,
			    NULL,
			    NULL,
			    NULL,
			    NULL);
      if (lError != ERROR_SUCCESS && lError != ERROR_MORE_DATA)
	break;

      if (RegOpenKeyEx(hZonesKey,
		       szKeyName,
		       0,
		       KEY_ALL_ACCESS,
		       &hZoneKey))
	break;

      Entry = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(TIMEZONE_ENTRY));
      if (Entry == NULL)
	{
	  RegCloseKey(hZoneKey);
	  break;
	}

      dwValueSize = 64 * sizeof(TCHAR);
      if (RegQueryValueEx(hZoneKey,
			  _T("Display"),
			  NULL,
			  NULL,
			  (LPBYTE)&Entry->Description,
			  &dwValueSize))
	{
	  RegCloseKey(hZoneKey);
	  break;
	}

      dwValueSize = 32 * sizeof(TCHAR);
      if (RegQueryValueEx(hZoneKey,
			  _T("Std"),
			  NULL,
			  NULL,
			  (LPBYTE)&Entry->StandardName,
			  &dwValueSize))
	{
	  RegCloseKey(hZoneKey);
	  break;
	}

      dwValueSize = 32 * sizeof(WCHAR);
      if (RegQueryValueEx(hZoneKey,
			  _T("Dlt"),
			  NULL,
			  NULL,
			  (LPBYTE)&Entry->DaylightName,
			  &dwValueSize))
	{
	  RegCloseKey(hZoneKey);
	  break;
	}

      dwValueSize = sizeof(DWORD);
      if (RegQueryValueEx(hZoneKey,
			  _T("Index"),
			  NULL,
			  NULL,
			  (LPBYTE)&Entry->Index,
			  &dwValueSize))
	{
	  RegCloseKey(hZoneKey);
	  break;
	}

      dwValueSize = sizeof(TZ_INFO);
      if (RegQueryValueEx(hZoneKey,
			  _T("TZI"),
			  NULL,
			  NULL,
			  (LPBYTE)&Entry->TimezoneInfo,
			  &dwValueSize))
	{
	  RegCloseKey(hZoneKey);
	  break;
	}

      RegCloseKey(hZoneKey);

      if (SetupData->TimeZoneListHead == NULL &&
	  SetupData->TimeZoneListTail == NULL)
	{
	  Entry->Prev = NULL;
	  Entry->Next = NULL;
	  SetupData->TimeZoneListHead = Entry;
	  SetupData->TimeZoneListTail = Entry;
	}
      else
	{
	  Current = GetLargerTimeZoneEntry(SetupData, Entry->Index);
	  if (Current != NULL)
	    {
	      if (Current == SetupData->TimeZoneListHead)
		{
		  /* Prepend to head */
		  Entry->Prev = NULL;
		  Entry->Next = SetupData->TimeZoneListHead;
		  SetupData->TimeZoneListHead->Prev = Entry;
		  SetupData->TimeZoneListHead = Entry;
		}
	      else
		{
		  /* Insert before current */
		  Entry->Prev = Current->Prev;
		  Entry->Next = Current;
		  Current->Prev->Next = Entry;
		  Current->Prev = Entry;
		}
	    }
	  else
	    {
	      /* Append to tail */
	      Entry->Prev = SetupData->TimeZoneListTail;
	      Entry->Next = NULL;
	      SetupData->TimeZoneListTail->Next = Entry;
	      SetupData->TimeZoneListTail = Entry;
	    }
	}

      dwIndex++;
    }

  RegCloseKey(hZonesKey);
}


static VOID
DestroyTimeZoneList(PSETUPDATA SetupData)
{
  PTIMEZONE_ENTRY Entry;

  while (SetupData->TimeZoneListHead != NULL)
    {
      Entry = SetupData->TimeZoneListHead;

      SetupData->TimeZoneListHead = Entry->Next;
      if (SetupData->TimeZoneListHead != NULL)
	{
	  SetupData->TimeZoneListHead->Prev = NULL;
	}

      HeapFree(GetProcessHeap(), 0, Entry);
    }

  SetupData->TimeZoneListTail = NULL;
}

#if 0
static BOOL
GetTimeZoneListIndex(LPDWORD lpIndex)
{
  TCHAR szLanguageIdString[9];
  HKEY hKey;
  DWORD dwValueSize;
  DWORD Length;
  LPTSTR Buffer;
  LPTSTR Ptr;
  LPTSTR End;
  BOOL bFound;

  if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
		   _T("SYSTEM\\CurrentControlSet\\Control\\NLS\\Language"),
		   0,
		   KEY_ALL_ACCESS,
		   &hKey))
    return FALSE;

  dwValueSize = 9 * sizeof(TCHAR);
  if (RegQueryValueEx(hKey,
		      _T("Default"),
		      NULL,
		      NULL,
		      (LPBYTE)szLanguageIdString,
		      &dwValueSize))
    {
      RegCloseKey(hKey);
      return FALSE;
    }

  RegCloseKey(hKey);

  if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
		   _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones"),
		   0,
		   KEY_ALL_ACCESS,
		   &hKey))
    return FALSE;

  dwValueSize = 0;
  if (RegQueryValueEx(hKey,
		      _T("IndexMapping"),
		      NULL,
		      NULL,
		      NULL,
		      &dwValueSize))
    {
      RegCloseKey(hKey);
      return FALSE;
    }

  Buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, dwValueSize);
  if (Buffer == NULL)
    {
      RegCloseKey(hKey);
      return FALSE;
    }

  if (RegQueryValueEx(hKey,
		      _T("IndexMapping"),
		      NULL,
		      NULL,
		      (LPBYTE)Buffer,
		      &dwValueSize))
    {
      HeapFree(GetProcessHeap(), 0, Buffer);
      RegCloseKey(hKey);
      return FALSE;
    }

  RegCloseKey(hKey);

  Ptr = Buffer;
  while (*Ptr != 0)
    {
      Length = _tcslen(Ptr);
      if (_tcsicmp(Ptr, szLanguageIdString) == 0)
        bFound = TRUE;

      Ptr = Ptr + Length + 1;
      if (*Ptr == 0)
        break;

      Length = _tcslen(Ptr);

      if (bFound)
        {
          *lpIndex = _tcstoul(Ptr, &End, 10);
          HeapFree(GetProcessHeap(), 0, Buffer);
          return FALSE;
        }

      Ptr = Ptr + Length + 1;
    }

  HeapFree(GetProcessHeap(), 0, Buffer);

  return FALSE;
}
#endif


static VOID
ShowTimeZoneList(HWND hwnd, PSETUPDATA SetupData, DWORD dwEntryIndex)
{
  PTIMEZONE_ENTRY Entry;
  DWORD dwIndex = 0;
  DWORD dwCount;

#if 0
  GetTimeZoneListIndex(&dwEntryIndex);
#endif

  Entry = SetupData->TimeZoneListHead;
  while (Entry != NULL)
    {
      dwCount = SendMessage(hwnd,
			    CB_ADDSTRING,
			    0,
			    (LPARAM)Entry->Description);

      if (dwEntryIndex != 0 && dwEntryIndex == Entry->Index)
        dwIndex = dwCount;

      Entry = Entry->Next;
    }

  SendMessage(hwnd,
	      CB_SETCURSEL,
	      (WPARAM)dwIndex,
	      0);
}


static VOID
SetLocalTimeZone(HWND hwnd, PSETUPDATA SetupData)
{
  TIME_ZONE_INFORMATION TimeZoneInformation;
  PTIMEZONE_ENTRY Entry;
  DWORD dwIndex;
  DWORD i;

  dwIndex = SendMessage(hwnd,
			CB_GETCURSEL,
			0,
			0);

  i = 0;
  Entry = SetupData->TimeZoneListHead;
  while (i < dwIndex)
    {
      if (Entry == NULL)
	return;

      i++;
      Entry = Entry->Next;
    }

  _tcscpy(TimeZoneInformation.StandardName,
	  Entry->StandardName);
  _tcscpy(TimeZoneInformation.DaylightName,
	  Entry->DaylightName);

  TimeZoneInformation.Bias = Entry->TimezoneInfo.Bias;
  TimeZoneInformation.StandardBias = Entry->TimezoneInfo.StandardBias;
  TimeZoneInformation.DaylightBias = Entry->TimezoneInfo.DaylightBias;

  memcpy(&TimeZoneInformation.StandardDate,
	 &Entry->TimezoneInfo.StandardDate,
	 sizeof(SYSTEMTIME));
  memcpy(&TimeZoneInformation.DaylightDate,
	 &Entry->TimezoneInfo.DaylightDate,
	 sizeof(SYSTEMTIME));

  /* Set time zone information */
  SetTimeZoneInformation(&TimeZoneInformation);
}


static BOOL
GetLocalSystemTime(HWND hwnd, PSETUPDATA SetupData)
{
  SYSTEMTIME Date;
  SYSTEMTIME Time;

  if (DateTime_GetSystemtime(GetDlgItem(hwnd, IDC_DATEPICKER), &Date) != GDT_VALID)
    {
      return FALSE;
    }

  if (DateTime_GetSystemtime(GetDlgItem(hwnd, IDC_TIMEPICKER), &Time) != GDT_VALID)
    {
      return FALSE;
    }

  SetupData->SystemTime.wYear = Date.wYear;
  SetupData->SystemTime.wMonth = Date.wMonth;
  SetupData->SystemTime.wDayOfWeek = Date.wDayOfWeek;
  SetupData->SystemTime.wDay = Date.wDay;
  SetupData->SystemTime.wHour = Time.wHour;
  SetupData->SystemTime.wMinute = Time.wMinute;
  SetupData->SystemTime.wSecond = Time.wSecond;
  SetupData->SystemTime.wMilliseconds = Time.wMilliseconds;

  return TRUE;
}


static VOID
SetAutoDaylightInfo(HWND hwnd)
{
  HKEY hKey;
  DWORD dwValue = 1;

  if (SendMessage(hwnd, BM_GETCHECK, 0, 0) == BST_UNCHECKED)
    {
      if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
		       _T("SYSTEM\\CurrentControlSet\\Control\\TimeZoneInformation"),
		       0,
		       KEY_SET_VALUE,
		       &hKey))
	  return;

      RegSetValueEx(hKey,
		    _T("DisableAutoDaylightTimeSet"),
		    0,
		    REG_DWORD,
		    (LPBYTE)&dwValue,
		    sizeof(DWORD));
      RegCloseKey(hKey);
    }
}


static BOOL
SetSystemLocalTime(HWND hwnd, PSETUPDATA SetupData)
{
  HANDLE hToken;
  DWORD PrevSize;
  TOKEN_PRIVILEGES priv, previouspriv;
  BOOL Ret = FALSE;

  /*
   * enable the SeSystemtimePrivilege privilege
   */

  if(OpenProcessToken(GetCurrentProcess(),
                      TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
                      &hToken))
  {
    priv.PrivilegeCount = 1;
    priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

    if(LookupPrivilegeValue(NULL,
                            SE_SYSTEMTIME_NAME,
                            &priv.Privileges[0].Luid))
    {
      if(AdjustTokenPrivileges(hToken,

⌨️ 快捷键说明

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