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

📄 wizard.c

📁 ReactOS是一些高手根据Windows XP的内核编写出的类XP。内核实现机理和API函数调用几乎相同。甚至可以兼容XP的程序。喜欢研究系统内核的人可以看一看。
💻 C
📖 第 1 页 / 共 5 页
字号:
/*
 * COPYRIGHT:       See COPYING in the top level directory
 * PROJECT:         System setup
 * FILE:            dll/win32/syssetup/wizard.c
 * PURPOSE:         GUI controls
 * PROGRAMMERS:     Eric Kohl
 *                  Pierre Schweitzer <heis_spiter@hotmail.com>
 */

/* INCLUDES *****************************************************************/

#include <ntstatus.h>
#define WIN32_NO_STATUS
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <tchar.h>
#include <string.h>
#include <setupapi.h>
#include <pseh/pseh.h>
#define NTOS_MODE_USER
#include <ndk/ntndk.h>

#include <syssetup/syssetup.h>

#define NDEBUG
#include <debug.h>

#include "globals.h"
#include "resource.h"

#define VMWINST

#define PM_REGISTRATION_NOTIFY (WM_APP + 1)
  /* Private Message used to communicate progress from the background
     registration thread to the main thread.
     wParam = 0 Registration in progress
            = 1 Registration completed
     lParam = Pointer to a REGISTRATIONNOTIFY structure */

typedef struct _REGISTRATIONNOTIFY
{
  ULONG Progress;
  UINT ActivityID;
  LPCWSTR CurrentItem;
  LPCWSTR ErrorMessage;
} REGISTRATIONNOTIFY, *PREGISTRATIONNOTIFY;

typedef struct _REGISTRATIONDATA
{
  HWND hwndDlg;
  ULONG DllCount;
  ULONG Registered;
  PVOID DefaultContext;
} REGISTRATIONDATA, *PREGISTRATIONDATA;

/* GLOBALS ******************************************************************/

static SETUPDATA SetupData;


/* FUNCTIONS ****************************************************************/

#ifdef VMWINST
static BOOL
RunVMWInstall(HWND hWnd)
{
  PROCESS_INFORMATION ProcInfo;
  MSG msg;
  DWORD ret;
  STARTUPINFO si = {0};
  WCHAR InstallName[] = L"vmwinst.exe";

  si.cb = sizeof(STARTUPINFO);

  if(CreateProcess(NULL, InstallName, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS,
                   NULL, NULL, &si, &ProcInfo))
  {
    EnableWindow(hWnd, FALSE);
    for (;;)
    {
      while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
      {
        if (msg.message == WM_QUIT)
          goto done;
        TranslateMessage(&msg);
        DispatchMessage(&msg);
      }

      ret = MsgWaitForMultipleObjects(1, &ProcInfo.hProcess, FALSE, INFINITE, QS_ALLEVENTS | QS_ALLINPUT);
      if (ret == WAIT_OBJECT_0)
        break;
    }
done:
    EnableWindow(hWnd, TRUE);

    CloseHandle(ProcInfo.hThread);
    CloseHandle(ProcInfo.hProcess);
    return TRUE;
  }
  return FALSE;
}
#endif

static VOID
CenterWindow(HWND hWnd)
{
  HWND hWndParent;
  RECT rcParent;
  RECT rcWindow;

  hWndParent = GetParent(hWnd);
  if (hWndParent == NULL)
    hWndParent = GetDesktopWindow();

  GetWindowRect(hWndParent, &rcParent);
  GetWindowRect(hWnd, &rcWindow);

  SetWindowPos(hWnd,
	       HWND_TOP,
	       ((rcParent.right - rcParent.left) - (rcWindow.right - rcWindow.left)) / 2,
	       ((rcParent.bottom - rcParent.top) - (rcWindow.bottom - rcWindow.top)) / 2,
	       0,
	       0,
	       SWP_NOSIZE);
}


static HFONT
CreateTitleFont(VOID)
{
  NONCLIENTMETRICS ncm;
  LOGFONT LogFont;
  HDC hdc;
  INT FontSize;
  HFONT hFont;

  ncm.cbSize = sizeof(NONCLIENTMETRICS);
  SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0);

  LogFont = ncm.lfMessageFont;
  LogFont.lfWeight = FW_BOLD;
  _tcscpy(LogFont.lfFaceName, _T("MS Shell Dlg"));

  hdc = GetDC(NULL);
  FontSize = 12;
  LogFont.lfHeight = 0 - GetDeviceCaps (hdc, LOGPIXELSY) * FontSize / 72;
  hFont = CreateFontIndirect(&LogFont);
  ReleaseDC(NULL, hdc);

  return hFont;
}


static INT_PTR CALLBACK
GplDlgProc(HWND hwndDlg,
           UINT uMsg,
           WPARAM wParam,
           LPARAM lParam)
{
  HRSRC GplTextResource;
  HGLOBAL GplTextMem;
  PVOID GplTextLocked;
  PCHAR GplText;
  DWORD Size;


  switch (uMsg)
    {
      case WM_INITDIALOG:
        GplTextResource = FindResource(hDllInstance, MAKEINTRESOURCE(IDR_GPL), _T("RT_TEXT"));
        if (NULL == GplTextResource)
          {
            break;
          }
        Size = SizeofResource(hDllInstance, GplTextResource);
        if (0 == Size)
          {
            break;
          }
        GplText = HeapAlloc(GetProcessHeap(), 0, Size + 1);
        if (NULL == GplText)
          {
            break;
          }
        GplTextMem = LoadResource(hDllInstance, GplTextResource);
        if (NULL == GplTextMem)
          {
            HeapFree(GetProcessHeap(), 0, GplText);
            break;
          }
        GplTextLocked = LockResource(GplTextMem);
        if (NULL == GplTextLocked)
          {
            HeapFree(GetProcessHeap(), 0, GplText);
            break;
          }
        memcpy(GplText, GplTextLocked, Size);
        GplText[Size] = '\0';
        SendMessageA(GetDlgItem(hwndDlg, IDC_GPL_TEXT), WM_SETTEXT, 0, (LPARAM) GplText);
        HeapFree(GetProcessHeap(), 0, GplText);
        SetFocus(GetDlgItem(hwndDlg, IDOK));
        return FALSE;

      case WM_CLOSE:
        EndDialog(hwndDlg, IDCANCEL);
        break;

      case WM_COMMAND:
        if (HIWORD(wParam) == BN_CLICKED && IDOK == LOWORD(wParam))
          {
            EndDialog(hwndDlg, IDOK);
          }
        break;

      default:
        break;
    }

  return FALSE;
}


static INT_PTR CALLBACK
WelcomeDlgProc(HWND hwndDlg,
               UINT uMsg,
               WPARAM wParam,
               LPARAM lParam)
{
  switch (uMsg)
    {
      case WM_INITDIALOG:
        {
          PSETUPDATA SetupData;
          HWND hwndControl;
          DWORD dwStyle;

          /* Get pointer to the global setup data */
          SetupData = (PSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;

          hwndControl = GetParent(hwndDlg);

          /* Center the wizard window */
          CenterWindow (hwndControl);

          /* Hide the system menu */
          dwStyle = GetWindowLong(hwndControl, GWL_STYLE);
          SetWindowLong(hwndControl, GWL_STYLE, dwStyle & ~WS_SYSMENU);

          /* Hide and disable the 'Cancel' button */
          hwndControl = GetDlgItem(GetParent(hwndDlg), IDCANCEL);
          ShowWindow (hwndControl, SW_HIDE);
          EnableWindow (hwndControl, FALSE);

          /* Set title font */
          SendDlgItemMessage(hwndDlg,
                             IDC_WELCOMETITLE,
                             WM_SETFONT,
                             (WPARAM)SetupData->hTitleFont,
                             (LPARAM)TRUE);
        }
        break;


      case WM_NOTIFY:
        {
          LPNMHDR lpnm = (LPNMHDR)lParam;

          switch (lpnm->code)
            {
              case PSN_SETACTIVE:
                /* Enable the Next button */
                PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT);
                if (SetupData.UnattendSetup)
                  {
                    SetWindowLong(hwndDlg, DWL_MSGRESULT, IDD_ACKPAGE);
                    return TRUE;
                  }
                break;

              case PSN_WIZBACK:
                SetupData.UnattendSetup = FALSE;
                break;

              default:
                break;
            }
        }
        break;

      default:
        break;
    }

  return FALSE;
}


static INT_PTR CALLBACK
AckPageDlgProc(HWND hwndDlg,
                 UINT uMsg,
                 WPARAM wParam,
                 LPARAM lParam)
{
  LPNMHDR lpnm;
  PWCHAR Projects;
  PWCHAR End, CurrentProject;
  INT ProjectsSize, ProjectsCount;

  switch (uMsg)
    {
      case WM_INITDIALOG:
        {
          Projects = NULL;
          ProjectsSize = 256;
          do
            {
              Projects = HeapAlloc(GetProcessHeap(), 0, ProjectsSize * sizeof(WCHAR));
              if (NULL == Projects)
                {
                  return FALSE;
                }
              ProjectsCount =  LoadString(hDllInstance, IDS_ACKPROJECTS, Projects, ProjectsSize);
              if (0 == ProjectsCount)
                {
                  HeapFree(GetProcessHeap(), 0, Projects);
                  return FALSE;
                }
              if (ProjectsCount < ProjectsSize - 1)
                {
                  break;
                }
              HeapFree(GetProcessHeap(), 0, Projects);
              ProjectsSize *= 2;
            }
          while (1);
          CurrentProject = Projects;
          while (L'\0' != *CurrentProject)
            {
              End = wcschr(CurrentProject, L'\n');
              if (NULL != End)
                {
                  *End = L'\0';
                }
              (void)ListBox_AddString(GetDlgItem(hwndDlg, IDC_PROJECTS), CurrentProject);
              if (NULL != End)
                {
                  CurrentProject = End + 1;
                }
              else
                {
                  CurrentProject += wcslen(CurrentProject);
                }
            }
          HeapFree(GetProcessHeap(), 0, Projects);
        }
        break;

      case WM_COMMAND:
        if (HIWORD(wParam) == BN_CLICKED && IDC_VIEWGPL == LOWORD(wParam))
          {
            DialogBox(hDllInstance, MAKEINTRESOURCE(IDD_GPL), NULL, GplDlgProc);
          }
        break;

      case WM_NOTIFY:
        {
          lpnm = (LPNMHDR)lParam;

          switch (lpnm->code)
            {
              case PSN_SETACTIVE:
                /* Enable the Back and Next buttons */
                PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
                if (SetupData.UnattendSetup)
                  {
                    SetWindowLong(hwndDlg, DWL_MSGRESULT, IDD_OWNERPAGE);
                    return TRUE;
                  }
                break;

              case PSN_WIZBACK:
                SetupData.UnattendSetup = FALSE;
                break;

              default:
                break;
            }
        }
        break;

      default:
        break;
    }

  return FALSE;
}

static
BOOL
WriteOwnerSettings(TCHAR * OwnerName,
                   TCHAR * OwnerOrganization)
{
  HKEY hKey;
  LONG res;



  res = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                     _T("Software\\Microsoft\\Windows NT\\CurrentVersion"),
                     0,
                     KEY_ALL_ACCESS,
                     &hKey);

  if (res != ERROR_SUCCESS)
    {
      return FALSE;
    }

  res = RegSetValueEx(hKey,
                      _T("RegisteredOwner"),
                      0,
                      REG_SZ,
                      (LPBYTE)OwnerName,
                      (_tcslen(OwnerName) + 1) * sizeof(TCHAR));

  if (res != ERROR_SUCCESS)
    {
      RegCloseKey(hKey);
      return FALSE;
    }
 
  res = RegSetValueEx(hKey,
                      _T("RegisteredOrganization"),
                      0,
                      REG_SZ,
                      (LPBYTE)OwnerOrganization,
                      (_tcslen(OwnerOrganization) + 1) * sizeof(TCHAR));

  RegCloseKey(hKey);
  return (res == ERROR_SUCCESS);
}

static INT_PTR CALLBACK
OwnerPageDlgProc(HWND hwndDlg,
                 UINT uMsg,
                 WPARAM wParam,
                 LPARAM lParam)
{
  TCHAR OwnerName[51];
  TCHAR OwnerOrganization[51];
  WCHAR Title[64];

⌨️ 快捷键说明

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