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.

231 lines
7.1 KiB

  1. #include "pch.h"
  2. #include "loader.h"
  3. #include <commctrl.h>
  4. #include "dialog.h"
  5. static HWND g_hWndDialog = NULL;
  6. static HANDLE g_hThread = NULL;
  7. OSVERSIONINFO g_VersionInfo;
  8. LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
  9. {
  10. switch (message)
  11. {
  12. case WM_ACTIVATE:
  13. if (g_hWndDialog != NULL &&
  14. LOWORD(wParam) == WA_ACTIVE)
  15. {
  16. SetForegroundWindow( g_hWndDialog );
  17. }
  18. break;
  19. case WM_USER_DIALOG_COMPLETE:
  20. CloseHandle( g_hThread );
  21. DestroyWindow( g_hWndDialog );
  22. PostQuitMessage( 0 );
  23. break;
  24. default:
  25. return DefWindowProc( hWnd, message, wParam, lParam );
  26. }
  27. return 0;
  28. }
  29. int
  30. APIENTRY
  31. WinMain(HINSTANCE hInstance,
  32. HINSTANCE hPrevInstance,
  33. LPSTR lpCmdLine,
  34. int nCmdShow)
  35. {
  36. WNDCLASSEXA wcxA;
  37. WNDCLASSEXW wcxW;
  38. MSG msg;
  39. PSTR lpszClassNameA = NULL;
  40. PSTR lpszWindowNameA = NULL;
  41. PWSTR lpszClassNameW = NULL;
  42. PWSTR lpszWindowNameW = NULL;
  43. DWORD dwResult = ERROR_SUCCESS;
  44. DWORD dwThreadID;
  45. THREADSTARTUPINFO StartInfo;
  46. HINSTANCE hInst;
  47. HWND hWnd;
  48. InitCommonControls();
  49. hInst = hInstance;
  50. //
  51. // let's get the current version info, we are going to need it later
  52. //
  53. ZeroMemory (&g_VersionInfo, sizeof(OSVERSIONINFO));
  54. g_VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  55. if (!GetVersionEx (&g_VersionInfo)) {
  56. g_VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  57. g_VersionInfo.dwMajorVersion = 4;
  58. g_VersionInfo.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS;
  59. }
  60. if (g_VersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) {
  61. // WinNT
  62. lpszClassNameW = GetResourceStringW( hInstance, IDS_WINDOWCLASS );
  63. lpszWindowNameW = GetResourceStringW( hInstance, IDS_WINDOWTITLE );
  64. hWnd = FindWindowW( lpszClassNameW, NULL );
  65. if (hWnd)
  66. {
  67. SetForegroundWindow( hWnd );
  68. goto END;
  69. }
  70. wcxW.cbSize = sizeof (WNDCLASSEXW);
  71. wcxW.style = CS_HREDRAW | CS_VREDRAW;
  72. wcxW.lpfnWndProc = WndProc;
  73. wcxW.cbClsExtra = 0;
  74. wcxW.cbWndExtra = 0;
  75. wcxW.hInstance = hInstance;
  76. wcxW.hIcon = NULL;
  77. wcxW.hCursor = LoadCursorA(NULL, IDC_ARROW);
  78. wcxW.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  79. wcxW.lpszMenuName = NULL;
  80. wcxW.lpszClassName = lpszClassNameW;
  81. wcxW.hIconSm = NULL;
  82. if (!RegisterClassExW (&wcxW))
  83. {
  84. dwResult = GetLastError();
  85. goto END;
  86. }
  87. hWnd = CreateWindowW( lpszClassNameW,
  88. lpszWindowNameW,
  89. WS_OVERLAPPEDWINDOW,
  90. CW_USEDEFAULT,
  91. CW_USEDEFAULT,
  92. 400,
  93. 300,
  94. NULL,
  95. NULL,
  96. hInstance,
  97. NULL );
  98. if (!hWnd)
  99. {
  100. dwResult = GetLastError();
  101. goto END;
  102. }
  103. StartInfo.hWnd = hWnd;
  104. StartInfo.hInstance = hInstance;
  105. g_hWndDialog = CreateDialogParamW( hInstance,
  106. MAKEINTRESOURCEW(IDD_MIGWIZINIT),
  107. hWnd,
  108. DlgProc,
  109. (LPARAM)&StartInfo );
  110. if (g_hWndDialog == NULL)
  111. {
  112. dwResult = GetLastError();
  113. goto END;
  114. }
  115. } else {
  116. // Win9x
  117. lpszClassNameA = GetResourceStringA( hInstance, IDS_WINDOWCLASS );
  118. lpszWindowNameA = GetResourceStringA( hInstance, IDS_WINDOWTITLE );
  119. hWnd = FindWindowA( lpszClassNameA, lpszWindowNameA );
  120. if (hWnd)
  121. {
  122. SetForegroundWindow( hWnd );
  123. goto END;
  124. }
  125. wcxA.cbSize = sizeof (WNDCLASSEXA);
  126. wcxA.style = CS_HREDRAW | CS_VREDRAW;
  127. wcxA.lpfnWndProc = WndProc;
  128. wcxA.cbClsExtra = 0;
  129. wcxA.cbWndExtra = 0;
  130. wcxA.hInstance = hInstance;
  131. wcxA.hIcon = NULL;
  132. wcxA.hCursor = LoadCursorA(NULL, IDC_ARROW);
  133. wcxA.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  134. wcxA.lpszMenuName = NULL;
  135. wcxA.lpszClassName = lpszClassNameA;
  136. wcxA.hIconSm = NULL;
  137. if (!RegisterClassExA (&wcxA))
  138. {
  139. dwResult = GetLastError();
  140. goto END;
  141. }
  142. hWnd = CreateWindowA( lpszClassNameA,
  143. lpszWindowNameA,
  144. WS_OVERLAPPEDWINDOW,
  145. CW_USEDEFAULT,
  146. CW_USEDEFAULT,
  147. 400,
  148. 300,
  149. NULL,
  150. NULL,
  151. hInstance,
  152. NULL );
  153. if (!hWnd)
  154. {
  155. dwResult = GetLastError();
  156. goto END;
  157. }
  158. StartInfo.hWnd = hWnd;
  159. StartInfo.hInstance = hInstance;
  160. g_hWndDialog = CreateDialogParamA( hInstance,
  161. MAKEINTRESOURCEA(IDD_MIGWIZINIT),
  162. hWnd,
  163. DlgProc,
  164. (LPARAM)&StartInfo );
  165. if (g_hWndDialog == NULL)
  166. {
  167. dwResult = GetLastError();
  168. goto END;
  169. }
  170. }
  171. // Create the Unpacking thread.
  172. // Note we pass along the Dialog's hwnd so the thread will report directly to it
  173. StartInfo.hWnd = g_hWndDialog;
  174. StartInfo.hInstance = hInstance;
  175. StartInfo.lpCmdLine = lpCmdLine;
  176. g_hThread = CreateThread( NULL,
  177. 0,
  178. UnpackThread,
  179. (PVOID)&StartInfo,
  180. 0,
  181. &dwThreadID );
  182. if (g_hThread == NULL)
  183. {
  184. // TODO: Handle Error
  185. dwResult = GetLastError();
  186. goto END;
  187. }
  188. // Main message loop:
  189. while (GetMessage( &msg, NULL, 0, 0 ))
  190. {
  191. TranslateMessage( &msg );
  192. DispatchMessage( &msg );
  193. }
  194. dwResult = LOWORD(msg.wParam);
  195. END:
  196. if (g_VersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) {
  197. // WinNT
  198. if (lpszClassNameW)
  199. {
  200. UnregisterClassW(lpszClassNameW, hInstance);
  201. FREE( lpszClassNameW );
  202. }
  203. if (lpszWindowNameW)
  204. {
  205. FREE( lpszWindowNameW );
  206. }
  207. } else {
  208. // Win9x
  209. if (lpszClassNameA)
  210. {
  211. UnregisterClassA(lpszClassNameA, hInstance);
  212. FREE( lpszClassNameA );
  213. }
  214. if (lpszWindowNameA)
  215. {
  216. FREE( lpszWindowNameA );
  217. }
  218. }
  219. return dwResult;
  220. }