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.

728 lines
15 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. Dialog.cpp
  5. Abstract:
  6. Implements the dialog procedures for the
  7. application.
  8. Notes:
  9. ANSI only - must run on Win9x.
  10. History:
  11. 01/30/01 rparsons Created
  12. 01/10/02 rparsons Revised
  13. --*/
  14. #include "demoapp.h"
  15. extern APPINFO g_ai;
  16. DWORD g_nCount = 0;
  17. //
  18. // Progress bar objects.
  19. //
  20. CProgress cprog;
  21. CProgress cprg;
  22. /*++
  23. Routine Description:
  24. Creates the extraction dialog box. This is the simple little progress
  25. dialog.
  26. Arguments:
  27. hInstance - Applicaiton instance handle.
  28. Return Value:
  29. On success, handle to the dialog.
  30. --*/
  31. HWND
  32. CreateExtractionDialog(
  33. IN HINSTANCE hInstance
  34. )
  35. {
  36. WNDCLASS wndclass;
  37. RECT rcDesktop;
  38. RECT rcDialog;
  39. RECT rcTaskbar;
  40. HWND hWndTaskbar;
  41. int nWidth = 0;
  42. int nHeight = 0;
  43. int nTaskbarHeight = 0;
  44. wndclass.style = CS_HREDRAW | CS_VREDRAW;
  45. wndclass.lpfnWndProc = (WNDPROC)ExtractionDialogProc;
  46. wndclass.cbClsExtra = 0;
  47. wndclass.cbWndExtra = DLGWINDOWEXTRA;
  48. wndclass.hInstance = hInstance;
  49. wndclass.hIcon = NULL;
  50. wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
  51. wndclass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
  52. wndclass.lpszMenuName = NULL;
  53. wndclass.lpszClassName = DLGEXTRACT_CLASS;
  54. if (!RegisterClass(&wndclass)) {
  55. return NULL;
  56. }
  57. g_ai.hWndExtractDlg = CreateDialog(hInstance,
  58. MAKEINTRESOURCE(IDD_EXTRACT),
  59. NULL,
  60. ExtractionDialogProc);
  61. if (!g_ai.hWndExtractDlg) {
  62. return NULL;
  63. }
  64. //
  65. // Get the coords of the desktop window and place the dialog.
  66. // Take into account the size of the taskbar.
  67. //
  68. hWndTaskbar = FindWindow("Shell_TrayWnd", NULL);
  69. ZeroMemory(&rcTaskbar, sizeof(RECT));
  70. if (hWndTaskbar) {
  71. GetWindowRect(hWndTaskbar, &rcTaskbar);
  72. }
  73. GetWindowRect(GetDesktopWindow(), &rcDesktop);
  74. GetWindowRect(g_ai.hWndExtractDlg, &rcDialog);
  75. nWidth = rcDialog.right - rcDialog.left;
  76. nHeight = rcDialog.bottom - rcDialog.top;
  77. if (rcTaskbar.top != 0) {
  78. nTaskbarHeight = rcTaskbar.bottom - rcTaskbar.top;
  79. }
  80. InflateRect(&rcDesktop, -5, -5);
  81. SetWindowPos(g_ai.hWndExtractDlg,
  82. HWND_TOPMOST,
  83. rcDesktop.right - nWidth,
  84. rcDesktop.bottom - nHeight - nTaskbarHeight,
  85. 0,
  86. 0,
  87. SWP_NOSIZE | SWP_SHOWWINDOW);
  88. return g_ai.hWndExtractDlg;
  89. }
  90. /*++
  91. Routine Description:
  92. Runs the message loop for extraction dialog.
  93. Arguments:
  94. hWnd - Handle to the window.
  95. uMsg - Windows message.
  96. wParam - Additional message info.
  97. lParam - Additional message info.
  98. Return Value:
  99. TRUE if handled, FALSE otherwise.
  100. --*/
  101. INT_PTR
  102. CALLBACK
  103. ExtractionDialogProc(
  104. IN HWND hWnd,
  105. IN UINT uMsg,
  106. IN WPARAM wParam,
  107. IN LPARAM lParam
  108. )
  109. {
  110. switch (uMsg) {
  111. case WM_INITDIALOG:
  112. //
  113. // Create the progress bar and enable the timer
  114. //
  115. cprog.Create(hWnd, g_ai.hInstance, "PROGBAR", 58, 73, 270, 20);
  116. cprog.SetMin(g_nCount);
  117. cprog.SetMax(100);
  118. cprog.SetPos(g_nCount);
  119. SetTimer(hWnd, IDC_TIMER, 35, NULL);
  120. break;
  121. case WM_TIMER:
  122. cprog.SetPos(++g_nCount);
  123. if (cprog.GetPos() == 100) {
  124. KillTimer(hWnd, IDC_TIMER);
  125. DestroyWindow(hWnd);
  126. }
  127. break;
  128. default:
  129. break;
  130. }
  131. return FALSE;
  132. }
  133. /*++
  134. Routine Description:
  135. Runs the message loop for welcome dialog.
  136. Arguments:
  137. hWnd - Handle to the window.
  138. uMsg - Windows message.
  139. wParam - Additional message info.
  140. lParam - Additional message info.
  141. Return Value:
  142. TRUE if handled, FALSE otherwise.
  143. --*/
  144. INT_PTR
  145. CALLBACK
  146. WelcomeDialogProc(
  147. IN HWND hWnd,
  148. IN UINT uMsg,
  149. IN WPARAM wParam,
  150. IN LPARAM lParam
  151. )
  152. {
  153. switch (uMsg) {
  154. case WM_INITDIALOG:
  155. SetWindowPos(hWnd, HWND_TOP, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE);
  156. SetForegroundWindow(hWnd);
  157. SetFocus(GetDlgItem(hWnd, IDOK));
  158. return FALSE;
  159. case WM_CLOSE:
  160. //
  161. // Pop up the 'do you want to exit' dialog.
  162. //
  163. DialogBox(g_ai.hInstance,
  164. MAKEINTRESOURCE(IDD_EXIT),
  165. hWnd,
  166. ExitSetupDialogProc);
  167. break;
  168. case WM_COMMAND:
  169. switch (LOWORD(wParam)) {
  170. case IDOK:
  171. //
  172. // See if the left Ctrl key is down.
  173. //
  174. if (GetKeyState(VK_LCONTROL) & 0x80000000) {
  175. TestIncludeExclude(hWnd);
  176. } else {
  177. EndDialog(hWnd, 0);
  178. }
  179. break;
  180. case IDCANCEL:
  181. //
  182. // Pop up the 'do you want to exit' dialog.
  183. //
  184. DialogBox(g_ai.hInstance,
  185. MAKEINTRESOURCE(IDD_EXIT),
  186. hWnd,
  187. ExitSetupDialogProc);
  188. break;
  189. default:
  190. break;
  191. }
  192. default:
  193. break;
  194. }
  195. return FALSE;
  196. }
  197. /*++
  198. Routine Description:
  199. Runs the message loop for exit setup dialog.
  200. Arguments:
  201. hWnd - Handle to the window.
  202. uMsg - Windows message.
  203. wParam - Additional message info.
  204. lParam - Additional message info.
  205. Return Value:
  206. TRUE if handled, FALSE otherwise.
  207. --*/
  208. INT_PTR
  209. CALLBACK
  210. ExitSetupDialogProc(
  211. IN HWND hWnd,
  212. IN UINT uMsg,
  213. IN WPARAM wParam,
  214. IN LPARAM lParam
  215. )
  216. {
  217. switch (uMsg) {
  218. case WM_CLOSE:
  219. EndDialog(hWnd, 0);
  220. break;
  221. case WM_COMMAND:
  222. switch (LOWORD(wParam)) {
  223. case IDC_EXIT_RESUME:
  224. EndDialog(hWnd, 0);
  225. break;
  226. case IDC_EXIT_EXIT:
  227. g_ai.fClosing = TRUE;
  228. EndDialog(hWnd, 0);
  229. PostQuitMessage(0);
  230. break;
  231. default:
  232. break;
  233. }
  234. default:
  235. break;
  236. }
  237. return FALSE;
  238. }
  239. /*++
  240. Routine Description:
  241. Runs the message loop for the installed components dialog.
  242. Arguments:
  243. hWnd - Handle to the window.
  244. uMsg - Windows message.
  245. wParam - Additional message info.
  246. lParam - Additional message info.
  247. Return Value:
  248. TRUE if handled, FALSE otherwise.
  249. --*/
  250. INT_PTR
  251. CALLBACK
  252. CheckComponentDialogProc(
  253. IN HWND hWnd,
  254. IN UINT uMsg,
  255. IN WPARAM wParam,
  256. IN LPARAM lParam
  257. )
  258. {
  259. switch (uMsg) {
  260. case WM_INITDIALOG:
  261. ShowWindow(hWnd, SW_SHOWNORMAL);
  262. UpdateWindow(hWnd);
  263. SetTimer(hWnd, IDC_TIMER, 3000, NULL);
  264. break;
  265. case WM_TIMER:
  266. KillTimer(hWnd, IDC_TIMER);
  267. if (g_ai.fEnableBadFunc) {
  268. BadLoadBogusDll();
  269. }
  270. EndDialog(hWnd, 0);
  271. break;
  272. default:
  273. break;
  274. }
  275. return FALSE;
  276. }
  277. /*++
  278. Routine Description:
  279. Runs the message loop for the free disk space dialog.
  280. Arguments:
  281. hWnd - Handle to the window.
  282. uMsg - Windows message.
  283. wParam - Additional message info.
  284. lParam - Additional message info.
  285. Return Value:
  286. TRUE if handled, FALSE otherwise.
  287. --*/
  288. INT_PTR
  289. CALLBACK
  290. CheckFreeDiskSpaceDialogProc(
  291. IN HWND hWnd,
  292. IN UINT uMsg,
  293. IN WPARAM wParam,
  294. IN LPARAM lParam
  295. )
  296. {
  297. switch (uMsg) {
  298. case WM_INITDIALOG:
  299. ShowWindow(hWnd, SW_SHOWNORMAL);
  300. UpdateWindow(hWnd);
  301. SetTimer(hWnd, IDC_TIMER, 3000, NULL);
  302. break;
  303. case WM_TIMER:
  304. {
  305. BOOL bReturn = FALSE;
  306. char szError[MAX_PATH];
  307. KillTimer(hWnd, IDC_TIMER);
  308. if (g_ai.fEnableBadFunc) {
  309. bReturn = BadGetFreeDiskSpace();
  310. if (!bReturn) {
  311. LoadString(g_ai.hInstance, IDS_NO_DISK_SPACE, szError, sizeof(szError));
  312. MessageBox(hWnd, szError, 0, MB_ICONERROR);
  313. }
  314. EndDialog(hWnd, 0);
  315. }
  316. break;
  317. }
  318. default:
  319. break;
  320. }
  321. return FALSE;
  322. }
  323. /*++
  324. Routine Description:
  325. Runs the message loop for the ready to copy dialog box.
  326. Arguments:
  327. hWnd - Handle to the window.
  328. uMsg - Windows message.
  329. wParam - Additional message info.
  330. lParam - Additional message info.
  331. Return Value:
  332. TRUE if handled, FALSE otherwise.
  333. --*/
  334. INT_PTR
  335. CALLBACK
  336. ReadyToCopyDialogProc(
  337. IN HWND hWnd,
  338. IN UINT uMsg,
  339. IN WPARAM wParam,
  340. IN LPARAM lParam
  341. )
  342. {
  343. switch (uMsg) {
  344. case WM_INITDIALOG:
  345. SetFocus(GetDlgItem(hWnd, IDOK));
  346. return FALSE;
  347. case WM_CLOSE:
  348. //
  349. // Pop up the 'do you want to exit' dialog
  350. //
  351. DialogBox(g_ai.hInstance,
  352. MAKEINTRESOURCE(IDD_EXIT),
  353. hWnd,
  354. ExitSetupDialogProc);
  355. break;
  356. case WM_COMMAND:
  357. switch (LOWORD(wParam)) {
  358. case IDOK:
  359. EndDialog(hWnd, 0);
  360. break;
  361. case IDCANCEL:
  362. //
  363. // Pop up the 'do you want to exit' dialog
  364. //
  365. DialogBox(g_ai.hInstance,
  366. MAKEINTRESOURCE(IDD_EXIT),
  367. hWnd,
  368. ExitSetupDialogProc);
  369. break;
  370. default:
  371. break;
  372. }
  373. default:
  374. break;
  375. }
  376. return FALSE;
  377. }
  378. /*++
  379. Routine Description:
  380. Runs the message loop for the copy files dialog.
  381. Arguments:
  382. hWnd - Handle to the window.
  383. uMsg - Windows message.
  384. wParam - Additional message info.
  385. lParam - Additional message info.
  386. Return Value:
  387. TRUE if handled, FALSE otherwise.
  388. --*/
  389. INT_PTR
  390. CALLBACK
  391. CopyFilesDialogProc(
  392. IN HWND hWnd,
  393. IN UINT uMsg,
  394. IN WPARAM wParam,
  395. IN LPARAM lParam
  396. )
  397. {
  398. switch (uMsg) {
  399. case WM_INITDIALOG:
  400. //
  401. // Create the progress bar and enable the timer
  402. //
  403. g_nCount = 0;
  404. cprg.Create(hWnd, g_ai.hInstance, "PROGBAR2", 10, 49, 415, 30);
  405. cprg.SetMin(g_nCount);
  406. cprg.SetMax(100);
  407. cprg.SetPos(g_nCount);
  408. SetTimer(hWnd, IDC_TIMER, 35, NULL);
  409. SetDlgItemText(hWnd, IDT_COPY_LABEL, "Copying files...");
  410. //
  411. // The progress bar is for demonstration sake.
  412. // Copy the files to \Program Files\Compatibility Demo
  413. //
  414. CopyAppFiles(hWnd);
  415. break;
  416. case WM_TIMER:
  417. cprg.SetPos(++g_nCount);
  418. if (cprg.GetPos() == 100) {
  419. KillTimer(hWnd, IDC_TIMER);
  420. EndDialog(hWnd, 0);
  421. }
  422. break;
  423. default:
  424. break;
  425. }
  426. return FALSE;
  427. }
  428. /*++
  429. Routine Description:
  430. Runs the message loop for the view readme dialog.
  431. Arguments:
  432. hWnd - Handle to the window.
  433. uMsg - Windows message.
  434. wParam - Additional message info.
  435. lParam - Additional message info.
  436. Return Value:
  437. TRUE if handled, FALSE otherwise.
  438. --*/
  439. INT_PTR
  440. CALLBACK
  441. ViewReadmeDialogProc(
  442. IN HWND hWnd,
  443. IN UINT uMsg,
  444. IN WPARAM wParam,
  445. IN LPARAM lParam
  446. )
  447. {
  448. switch (uMsg) {
  449. case WM_INITDIALOG:
  450. //
  451. // Make the dialog "flash" -
  452. // ForceApplicationFocus will fix this.
  453. //
  454. SetForegroundWindow(hWnd);
  455. SetFocus(GetDlgItem(hWnd, IDOK));
  456. break;
  457. case WM_CLOSE:
  458. //
  459. // Pop up the 'do you want to exit' dialog.
  460. //
  461. DialogBox(g_ai.hInstance,
  462. MAKEINTRESOURCE(IDD_EXIT),
  463. hWnd,
  464. ExitSetupDialogProc);
  465. break;
  466. case WM_COMMAND:
  467. switch (LOWORD(wParam)) {
  468. case IDOK:
  469. //
  470. // If the user has requested that the readme be displayed,
  471. // show it.
  472. //
  473. if (IsDlgButtonChecked(hWnd, IDR_VIEW_README)) {
  474. if (g_ai.fEnableBadFunc) {
  475. BadDisplayReadme(FALSE);
  476. } else {
  477. BadDisplayReadme(TRUE);
  478. }
  479. }
  480. EndDialog(hWnd, 0);
  481. break;
  482. default:
  483. break;
  484. }
  485. default:
  486. break;
  487. }
  488. return FALSE;
  489. }
  490. /*++
  491. Routine Description:
  492. Runs the message loop for the reboot dialog.
  493. Arguments:
  494. hWnd - Handle to the window.
  495. uMsg - Windows message.
  496. wParam - Additional message info.
  497. lParam - Additional message info.
  498. Return Value:
  499. TRUE if handled, FALSE otherwise.
  500. --*/
  501. INT_PTR
  502. CALLBACK
  503. RebootDialogProc(
  504. IN HWND hWnd,
  505. IN UINT uMsg,
  506. IN WPARAM wParam,
  507. IN LPARAM lParam
  508. )
  509. {
  510. switch (uMsg) {
  511. case WM_INITDIALOG:
  512. //
  513. // Default to restart the computer.
  514. //
  515. CheckDlgButton(hWnd, IDR_RESTART_NOW, BST_CHECKED);
  516. SetFocus(GetDlgItem(hWnd, IDOK));
  517. return FALSE;
  518. case WM_COMMAND:
  519. switch (LOWORD(wParam)) {
  520. case IDOK:
  521. //
  522. // If the user requested a reboot, do it.
  523. //
  524. if (IsDlgButtonChecked(hWnd, IDR_RESTART_NOW)) {
  525. if (g_ai.fEnableBadFunc) {
  526. BadRebootComputer(FALSE);
  527. } else {
  528. BadRebootComputer(TRUE);
  529. }
  530. }
  531. EndDialog(hWnd, 0);
  532. PostQuitMessage(0);
  533. break;
  534. default:
  535. break;
  536. }
  537. default:
  538. break;
  539. }
  540. return FALSE;
  541. }