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.

302 lines
8.5 KiB

  1. #include "pch.h"
  2. #include "loader.h"
  3. #include "resource.h"
  4. #include "resrc1.h"
  5. #include <winuser.h>
  6. #include <commctrl.h>
  7. #define ANIMATE_OPEN(x) SendDlgItemMessage(Dlg,IDC_ANIMATE1,ACM_OPEN,(WPARAM)NULL,(LPARAM)(LPTSTR)MAKEINTRESOURCE(x))
  8. #define ANIMATE_PLAY() SendDlgItemMessage(Dlg,IDC_ANIMATE1,ACM_PLAY,(WPARAM)-1,(LPARAM)MAKELONG(0,-1))
  9. #define ANIMATE_STOP() SendDlgItemMessage(Dlg,IDC_ANIMATE1,ACM_STOP,(WPARAM)0,(LPARAM)0);
  10. #define ANIMATE_CLOSE() SendDlgItemMessage(Dlg,IDC_ANIMATE1,ACM_OPEN,(WPARAM)NULL,(LPARAM)NULL);
  11. VOID
  12. _CenterWindowOnDesktop (
  13. HWND WndToCenter
  14. )
  15. {
  16. RECT rcFrame, rcWindow;
  17. LONG x, y, w, h;
  18. POINT point;
  19. HWND Desktop = GetDesktopWindow ();
  20. point.x = point.y = 0;
  21. ClientToScreen(Desktop, &point);
  22. GetWindowRect(WndToCenter, &rcWindow);
  23. GetClientRect(Desktop, &rcFrame);
  24. w = rcWindow.right - rcWindow.left + 1;
  25. h = rcWindow.bottom - rcWindow.top + 1;
  26. x = point.x + ((rcFrame.right - rcFrame.left + 1 - w) / 2);
  27. y = point.y + ((rcFrame.bottom - rcFrame.top + 1 - h) / 2);
  28. //
  29. // Get the work area for the current desktop (i.e., the area that
  30. // the tray doesn't occupy).
  31. //
  32. if(!SystemParametersInfo (SPI_GETWORKAREA, 0, (PVOID)&rcFrame, 0)) {
  33. //
  34. // For some reason SPI failed, so use the full screen.
  35. //
  36. rcFrame.top = rcFrame.left = 0;
  37. rcFrame.right = GetSystemMetrics(SM_CXSCREEN);
  38. rcFrame.bottom = GetSystemMetrics(SM_CYSCREEN);
  39. }
  40. if(x + w > rcFrame.right) {
  41. x = rcFrame.right - w;
  42. } else if(x < rcFrame.left) {
  43. x = rcFrame.left;
  44. }
  45. if(y + h > rcFrame.bottom) {
  46. y = rcFrame.bottom - h;
  47. } else if(y < rcFrame.top) {
  48. y = rcFrame.top;
  49. }
  50. MoveWindow(WndToCenter, x, y, w, h, FALSE);
  51. }
  52. VOID
  53. _DialogSetTextByResource( HWND hWnd, HINSTANCE hInst, DWORD dwResID, LPARAM Extra )
  54. {
  55. PSTR lpszMsgFmtA;
  56. PWSTR lpszMsgFmtW;
  57. PSTR lpszNewTextA;
  58. PWSTR lpszNewTextW;
  59. if (g_VersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) {
  60. // WinNT
  61. lpszMsgFmtW = GetResourceStringW( hInst, dwResID );
  62. if (lpszMsgFmtW)
  63. {
  64. FormatMessageW( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  65. lpszMsgFmtW,
  66. 0,
  67. 0,
  68. (LPWSTR)(&lpszNewTextW),
  69. 0,
  70. (va_list *)&Extra );
  71. FREE( lpszMsgFmtW );
  72. if (lpszNewTextW)
  73. {
  74. SetDlgItemTextW( hWnd, IDC_TEXT, (PWSTR)lpszNewTextW );
  75. LocalFree( lpszNewTextW );
  76. }
  77. }
  78. } else {
  79. // Win9x
  80. lpszMsgFmtA = GetResourceStringA( hInst, dwResID );
  81. if (lpszMsgFmtA)
  82. {
  83. FormatMessageA( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  84. lpszMsgFmtA,
  85. 0,
  86. 0,
  87. (LPSTR)(&lpszNewTextA),
  88. 0,
  89. (va_list *)&Extra );
  90. FREE( lpszMsgFmtA );
  91. if (lpszNewTextA)
  92. {
  93. SetDlgItemTextA( hWnd, IDC_TEXT, (PSTR)lpszNewTextA );
  94. LocalFree( lpszNewTextA );
  95. }
  96. }
  97. }
  98. }
  99. VOID
  100. _DisplayError( HWND hWnd, HINSTANCE hInst, DWORD ecValue, LPARAM Extra )
  101. {
  102. ERRORMAPPINGSTRUCT ErrorMap[] = ERROR_MAPPING;
  103. DWORD dwArraySize;
  104. DWORD x;
  105. DWORD dwResId = IDS_MSG_SUCCESS;
  106. PSTR lpszMsgFmtA;
  107. PWSTR lpszMsgFmtW;
  108. PSTR lpszBoxTitleA;
  109. PWSTR lpszBoxTitleW;
  110. PSTR lpszNewTextA;
  111. PWSTR lpszNewTextW;
  112. dwArraySize = sizeof(ErrorMap) / sizeof(ERRORMAPPINGSTRUCT);
  113. for (x=0; x<dwArraySize; x++)
  114. {
  115. if (ecValue == ErrorMap[x].ecValue)
  116. {
  117. dwResId = ErrorMap[x].uResourceID;
  118. break;
  119. }
  120. }
  121. if (g_VersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) {
  122. // WinNT
  123. lpszMsgFmtW = GetResourceStringW( hInst, dwResId );
  124. if (lpszMsgFmtW)
  125. {
  126. FormatMessageW( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  127. lpszMsgFmtW,
  128. 0,
  129. 0,
  130. (LPWSTR)(&lpszNewTextW),
  131. 0,
  132. (va_list *)&Extra );
  133. FREE( lpszMsgFmtW );
  134. if (lpszNewTextW)
  135. {
  136. lpszBoxTitleW = GetResourceStringW( hInst, IDS_WINDOWTITLE );
  137. if (lpszBoxTitleW)
  138. {
  139. MessageBoxW( hWnd, lpszNewTextW, lpszBoxTitleW, MB_OK | MB_ICONERROR | MB_TASKMODAL );
  140. FREE( lpszBoxTitleW );
  141. }
  142. LocalFree( lpszNewTextW );
  143. }
  144. }
  145. } else {
  146. // Win9x
  147. lpszMsgFmtA = GetResourceStringA( hInst, dwResId );
  148. if (lpszMsgFmtA)
  149. {
  150. FormatMessageA( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  151. lpszMsgFmtA,
  152. 0,
  153. 0,
  154. (LPSTR)(&lpszNewTextA),
  155. 0,
  156. (va_list *)&Extra );
  157. FREE( lpszMsgFmtA );
  158. if (lpszNewTextA)
  159. {
  160. lpszBoxTitleA = GetResourceStringA( hInst, IDS_WINDOWTITLE );
  161. if (lpszBoxTitleA)
  162. {
  163. MessageBoxA( hWnd, lpszNewTextA, lpszBoxTitleA, MB_OK | MB_ICONERROR | MB_TASKMODAL );
  164. FREE( lpszBoxTitleA );
  165. }
  166. LocalFree( lpszNewTextA );
  167. }
  168. }
  169. }
  170. }
  171. BOOL
  172. CALLBACK
  173. _SetMigwizActive(
  174. HWND hWnd,
  175. LPARAM lParam
  176. )
  177. {
  178. SetForegroundWindow( hWnd );
  179. return FALSE;
  180. }
  181. INT_PTR
  182. CALLBACK
  183. DlgProc (
  184. HWND Dlg,
  185. UINT Msg,
  186. WPARAM wParam,
  187. LPARAM lParam
  188. )
  189. {
  190. static HWND hWndParent = NULL;
  191. static HINSTANCE hInstParent = NULL;
  192. static HCURSOR Cursor = NULL;
  193. static HWND hWndAnim = NULL;
  194. static DWORD dwCurrentAnim = 0;
  195. static DWORD dwThreadId = 0;
  196. switch (Msg)
  197. {
  198. case WM_ACTIVATE:
  199. if (dwThreadId != 0)
  200. {
  201. EnumThreadWindows( dwThreadId, _SetMigwizActive, (LPARAM)NULL );
  202. }
  203. break;
  204. case WM_INITDIALOG:
  205. hWndParent = ((LPTHREADSTARTUPINFO)lParam)->hWnd;
  206. hInstParent = ((LPTHREADSTARTUPINFO)lParam)->hInstance;
  207. ANIMATE_OPEN( IDA_STARTUP );
  208. ANIMATE_PLAY( );
  209. dwCurrentAnim = IDA_STARTUP;
  210. Cursor = SetCursor (LoadCursor (NULL, IDC_WAIT));
  211. ShowCursor (TRUE);
  212. _CenterWindowOnDesktop( Dlg );
  213. return TRUE;
  214. case WM_COMMAND:
  215. switch (LOWORD(wParam))
  216. {
  217. case IDOK:
  218. case IDCANCEL:
  219. SendMessage( hWndParent, WM_USER_DIALOG_COMPLETE, wParam, 0 );
  220. return TRUE;
  221. break;
  222. }
  223. break;
  224. case WM_USER_UNPACKING_FILE:
  225. if (dwCurrentAnim == IDA_STARTUP)
  226. {
  227. ANIMATE_STOP();
  228. ANIMATE_CLOSE();
  229. ANIMATE_OPEN( IDA_FILECOPY );
  230. ANIMATE_PLAY();
  231. dwCurrentAnim = IDA_FILECOPY;
  232. }
  233. if (g_VersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT) {
  234. // WinNT
  235. _DialogSetTextByResource( Dlg, hInstParent, IDS_MSG_UNPACKING_FILEW, lParam );
  236. } else {
  237. // Win9x
  238. _DialogSetTextByResource( Dlg, hInstParent, IDS_MSG_UNPACKING_FILEA, lParam );
  239. }
  240. break;
  241. case WM_USER_THREAD_ERROR:
  242. ANIMATE_STOP();
  243. ANIMATE_CLOSE();
  244. ShowWindow( Dlg, SW_HIDE );
  245. _DisplayError( Dlg, hInstParent, (DWORD)wParam, lParam );
  246. SendMessage( hWndParent, WM_USER_DIALOG_COMPLETE, wParam, 0 );
  247. break;
  248. case WM_USER_SUBTHREAD_CREATED:
  249. ShowWindow( Dlg, SW_HIDE );
  250. dwThreadId = (DWORD)lParam;
  251. break;
  252. case WM_USER_THREAD_COMPLETE:
  253. ANIMATE_STOP();
  254. ANIMATE_CLOSE();
  255. if ((ERRORCODE)lParam == E_OK)
  256. {
  257. SendMessage( hWndParent, WM_USER_DIALOG_COMPLETE, 0, 0 );
  258. }
  259. dwThreadId = 0;
  260. break;
  261. case WM_DESTROY:
  262. ShowCursor (FALSE);
  263. if (Cursor) {
  264. SetCursor (Cursor);
  265. Cursor = NULL;
  266. }
  267. break;
  268. }
  269. return FALSE;
  270. }