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.

303 lines
8.8 KiB

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