Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

239 lines
5.6 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. Main.cpp
  5. Abstract:
  6. Provides the entry point for the application
  7. and the message loop.
  8. Notes:
  9. Unicode only - Windows 2000 & XP
  10. History:
  11. 01/02/2002 rparsons Created
  12. --*/
  13. #include "main.h"
  14. //
  15. // This structure contains all the data that we'll need
  16. // to access throughout the application.
  17. //
  18. APPINFO g_ai;
  19. /*++
  20. Routine Description:
  21. Runs the message loop for the application.
  22. Arguments:
  23. hWnd - Handle to the window.
  24. uMsg - Windows message.
  25. wParam - Additional message info.
  26. lParam - Additional message info.
  27. Return Value:
  28. TRUE if handled, FALSE otherwise.
  29. --*/
  30. INT_PTR
  31. CALLBACK
  32. MainWndProc(
  33. IN HWND hWnd,
  34. IN UINT uMsg,
  35. IN WPARAM wParam,
  36. IN LPARAM lParam
  37. )
  38. {
  39. switch (uMsg) {
  40. case WM_INITDIALOG:
  41. {
  42. HICON hIcon = LoadIcon(g_ai.hInstance, MAKEINTRESOURCE(IDI_ICON));
  43. SetClassLongPtr(hWnd, GCLP_HICON, (LONG_PTR)hIcon);
  44. if (g_ai.bQuiet) {
  45. ShowWindow(hWnd, SW_HIDE);
  46. } else {
  47. ShowWindow(hWnd, SW_SHOWNORMAL);
  48. }
  49. UpdateWindow(hWnd);
  50. PostMessage(hWnd, WM_CUSTOM_INSTALL, 0, 0);
  51. break;
  52. }
  53. case WM_CLOSE:
  54. EndDialog(hWnd, 0);
  55. PostQuitMessage(0);
  56. break;
  57. case WM_CUSTOM_INSTALL:
  58. PerformInstallation(hWnd);
  59. if (g_ai.bQuiet) {
  60. EndDialog(hWnd, 0);
  61. PostQuitMessage(0);
  62. }
  63. break;
  64. case WM_COMMAND:
  65. switch (LOWORD(wParam)) {
  66. case IDOK:
  67. if (g_ai.bInstallSuccess) {
  68. InstallLaunchExe();
  69. }
  70. EndDialog(hWnd, 0);
  71. PostQuitMessage(0);
  72. break;
  73. default:
  74. break;
  75. }
  76. default:
  77. break;
  78. }
  79. return FALSE;
  80. }
  81. /*++
  82. Routine Description:
  83. Application entry point.
  84. Arguments:
  85. hInstance - App instance handle.
  86. hPrevInstance - Always NULL.
  87. lpCmdLine - Pointer to the command line.
  88. nCmdShow - Window show flag.
  89. Return Value:
  90. 0 on failure.
  91. --*/
  92. int
  93. APIENTRY
  94. wWinMain(
  95. IN HINSTANCE hInstance,
  96. IN HINSTANCE hPrevInstance,
  97. IN LPWSTR lpCmdLine,
  98. IN int nCmdShow
  99. )
  100. {
  101. MSG msg;
  102. WNDCLASS wndclass;
  103. WCHAR wszError[MAX_PATH];
  104. INITCOMMONCONTROLSEX icex;
  105. g_ai.hInstance = hInstance;
  106. wndclass.style = CS_HREDRAW | CS_VREDRAW;
  107. wndclass.lpfnWndProc = MainWndProc;
  108. wndclass.cbClsExtra = 0;
  109. wndclass.cbWndExtra = DLGWINDOWEXTRA;
  110. wndclass.hInstance = hInstance;
  111. wndclass.hIcon = NULL;
  112. wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  113. wndclass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
  114. wndclass.lpszMenuName = NULL;
  115. wndclass.lpszClassName = APP_CLASS;
  116. if (lpCmdLine != NULL && lstrcmp(lpCmdLine, TEXT("q")) == 0) {
  117. g_ai.bQuiet = TRUE;
  118. }
  119. if (!RegisterClass(&wndclass) && !g_ai.bQuiet) {
  120. LoadString(hInstance, IDS_NO_CLASS, wszError, ARRAYSIZE(wszError));
  121. MessageBox(NULL, wszError, APP_NAME, MB_ICONERROR);
  122. return 0;
  123. }
  124. //
  125. // Set up the common controls.
  126. //
  127. icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
  128. icex.dwICC = ICC_PROGRESS_CLASS;
  129. if (!InitCommonControlsEx(&icex)) {
  130. InitCommonControls();
  131. }
  132. //
  133. // Initialize the installer. Get commonly used paths and save
  134. // them away for later.
  135. //
  136. UINT uReturn = InitializeInstaller();
  137. if (!g_ai.bQuiet) {
  138. if (-1 == uReturn) {
  139. LoadString(g_ai.hInstance, IDS_OS_NOT_SUPPORTED, wszError, ARRAYSIZE(wszError));
  140. MessageBox(NULL, wszError, APP_NAME, MB_ICONERROR);
  141. return 0;
  142. } else if (0 == uReturn) {
  143. LoadString(g_ai.hInstance, IDS_INIT_FAILED, wszError, ARRAYSIZE(wszError));
  144. MessageBox(NULL, wszError, APP_NAME, MB_ICONERROR);
  145. return 0;
  146. }
  147. }
  148. //
  149. // Initialize our structure that describes the files that
  150. // we're going to install.
  151. //
  152. if (!InitializeFileInfo()) {
  153. DPF(dlError, "[WinMain] Failed to initialize file info");
  154. return 0;
  155. }
  156. //
  157. // If the currently installed files are newer than what we have to
  158. // offer, launch the installed appverif.exe and quit.
  159. //
  160. if (!IsPkgAppVerifNewer() && !g_ai.bQuiet) {
  161. InstallLaunchExe();
  162. return 0;
  163. }
  164. //
  165. // Create the main dialog and run the message pump.
  166. //
  167. g_ai.hMainDlg = CreateDialog(hInstance,
  168. MAKEINTRESOURCE(IDD_MAIN),
  169. NULL,
  170. MainWndProc);
  171. if (!g_ai.hMainDlg) {
  172. LoadString(hInstance, IDS_NO_MAIN_DLG, wszError, ARRAYSIZE(wszError));
  173. MessageBox(NULL, wszError, APP_NAME, MB_ICONERROR);
  174. return 0;
  175. }
  176. g_ai.hWndProgress = GetDlgItem(g_ai.hMainDlg, IDC_PROGRESS);
  177. while (GetMessage(&msg, (HWND) NULL, 0, 0)) {
  178. if (!IsDialogMessage(g_ai.hMainDlg, &msg)) {
  179. TranslateMessage(&msg);
  180. DispatchMessage(&msg);
  181. }
  182. }
  183. return (int)msg.wParam;
  184. }