Source code of Windows XP (NT5)
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.

232 lines
6.9 KiB

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