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.

383 lines
15 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // RUNNOW.CPP / Tuneup
  4. //
  5. // Microsoft Confidential
  6. // Copyright (c) Microsoft Corporation 1998
  7. // All rights reserved
  8. //
  9. // 8/98 - Jason Cohen (JCOHEN)
  10. //
  11. //////////////////////////////////////////////////////////////////////////////
  12. //
  13. // Internal include file(s).
  14. //
  15. #include <windows.h>
  16. #include "tasks.h"
  17. #include "main.h"
  18. //
  19. // Internal defined value(s).
  20. //
  21. #define CHECK_WIDTH 18
  22. #define FIRST_SPACING 7
  23. #define LINE_SPACING 13
  24. #define WINGDING_CHECK 0xFC
  25. #define WINGDING_ARROW 0xD8 //0x77 //0xE8 //0xE0
  26. #define WM_PROGRESS (WM_USER + 1000)
  27. //
  28. // Internal global variable(s).
  29. //
  30. HWND g_hWndRunNowDlg = NULL;
  31. //
  32. // Inernal function prototype(s).
  33. //
  34. static INT RunNowProgressProc(DWORD);
  35. static BOOL CALLBACK RunNowDlgProc(HWND, UINT, WPARAM, LPARAM);
  36. static VOID InitWingdingFont(HWND);
  37. //
  38. // External function(s).
  39. //
  40. VOID RunTasksNow(HWND hWndParent, LPTASKDATA lpTasks)
  41. {
  42. HANDLE hThread;
  43. DWORD dwThreadID;
  44. // Use another thread to run progressing dialog.
  45. //
  46. hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) RunNowProgressProc, (LPVOID) NULL, 0, (LPDWORD) &dwThreadID);
  47. // Hide the wizard window.
  48. //
  49. ShowEnableWindow(hWndParent, FALSE);
  50. // Wait for the dialog to be created.
  51. //
  52. while ( g_hWndRunNowDlg == NULL )
  53. Sleep(10);
  54. // Loop through all the tasks.
  55. //
  56. while ( lpTasks && g_hWndRunNowDlg )
  57. {
  58. // Check to see if it is scheduled.
  59. //
  60. if ( !(g_dwFlags & TUNEUP_CUSTOM) || (lpTasks->dwOptions & TASK_SCHEDULED) )
  61. {
  62. // Put an arrow next to the item.
  63. //
  64. SendMessage(g_hWndRunNowDlg, WM_PROGRESS, 0, 0L);
  65. // Execute the task.
  66. //
  67. ExecAndWait(hWndParent, lpTasks->lpFullPathName, lpTasks->lpParameters, NULL, FALSE, FALSE);
  68. }
  69. lpTasks = lpTasks->lpNext;
  70. }
  71. // If the progress dialog is still there, close it
  72. //
  73. if ( g_hWndRunNowDlg )
  74. SendMessage(g_hWndRunNowDlg, WM_CLOSE, 0, 0);
  75. }
  76. //
  77. // Internal function(s).
  78. //
  79. static INT RunNowProgressProc(DWORD dwDummy)
  80. {
  81. return (INT)DialogBox(g_hInst, MAKEINTRESOURCE(IDD_PROGRESS), NULL, (DLGPROC) RunNowDlgProc);
  82. }
  83. static BOOL CALLBACK RunNowDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  84. {
  85. static POINT Point;
  86. static INT nHeight,
  87. nIndex = -1;
  88. static HWND hWndTemp = NULL,
  89. *lphWnd = NULL;
  90. static HFONT hBoldFont = NULL,
  91. hNormFont = NULL;
  92. TCHAR szWingDing[] = _T(" ");
  93. POINT PointMove;
  94. RECT Rect,
  95. RectDlg;
  96. LPTASKDATA lpTasks;
  97. switch (message)
  98. {
  99. case WM_COMMAND:
  100. if ( (INT) LOWORD(wParam) == IDCANCEL )
  101. EndDialog(hDlg, 0);
  102. return 0;
  103. case WM_DESTROY:
  104. // Free the font handles.
  105. //
  106. if ( hBoldFont )
  107. DeleteObject(hBoldFont);
  108. if ( hNormFont )
  109. DeleteObject(hNormFont);
  110. InitWingdingFont(NULL);
  111. // Free the hWnd.
  112. //
  113. FREE(lphWnd);
  114. g_hWndRunNowDlg = NULL;
  115. return TRUE;
  116. case WM_INITDIALOG:
  117. // Disable system menu itmes.
  118. //
  119. //EnableMenuItem(GetSystemMenu(hDlg, FALSE), SC_CLOSE, MF_BYCOMMAND | MF_DISABLED);
  120. // Move the window to the upper right corner of the desktop.
  121. //
  122. CenterWindow(hDlg, NULL, TRUE);
  123. // Get the rect of the title control we are going to base all the others of.
  124. //
  125. GetWindowRect(GetDlgItem(hDlg, IDC_TITLE), &Rect);
  126. MapWindowPoints(NULL, hDlg, (LPPOINT)&Rect, 2);
  127. // Figure the width and height of the new controls.
  128. //
  129. Rect.right -= Rect.left; // The width of the control.
  130. Rect.bottom -= Rect.top; // The height of the control.
  131. // Now we need to convert the left top coordinates from screen to client coordinates.
  132. //
  133. Point.x = Rect.left; // The left of the control.
  134. Point.y = Rect.top; // The top of the control.
  135. Point.y += FIRST_SPACING;
  136. // Allocate the memory for the hWnds.
  137. //
  138. nHeight = TasksScheduled(g_Tasks);
  139. lphWnd = (HWND *) MALLOC(sizeof(HWND) * nHeight--);
  140. nIndex = nHeight;
  141. for (lpTasks = g_Tasks; lpTasks; lpTasks = lpTasks->lpNext)
  142. {
  143. // Check to see if it is scheduled.
  144. //
  145. if ( !(g_dwFlags & TUNEUP_CUSTOM) || (lpTasks->dwOptions & TASK_SCHEDULED) )
  146. {
  147. // Each new control should be 2 times the width of the control down
  148. // from the previous control. This will give 1 width of the control
  149. // between each.
  150. //
  151. Point.y += Rect.bottom + LINE_SPACING;
  152. // Create the control and set the font and text.
  153. //
  154. hWndTemp = CreateWindow(_T("STATIC"), _T(""), WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE, Point.x + CHECK_WIDTH, Point.y, Rect.right - CHECK_WIDTH, Rect.bottom, hDlg, NULL, g_hInst, NULL);
  155. if ( hNormFont == NULL )
  156. hNormFont = (HFONT) SendDlgItemMessage(hDlg, IDC_TITLE, WM_GETFONT, 0, 0L);
  157. SendMessage(hWndTemp, WM_SETFONT, (WPARAM) hNormFont, MAKELPARAM(FALSE, 0));
  158. SetWindowText(hWndTemp, lpTasks->lpTitle);
  159. // If we can, save the hwnd so we can use it to make
  160. // the current text bold.
  161. //
  162. if ( lphWnd && (nIndex >= 0) )
  163. *(lphWnd + nIndex) = hWndTemp;
  164. nIndex--;
  165. }
  166. }
  167. // Make sure we allocated the memory and used all of it.
  168. // nIndex should be exatly -1 if we got the right number
  169. // of hWnds.
  170. //
  171. if ( lphWnd && (nIndex == -1) )
  172. nIndex = nHeight;
  173. else
  174. nIndex = -1;
  175. // Reset this so that the progress message knows the
  176. // first time it is run.
  177. //
  178. hWndTemp = NULL;
  179. // Make sure that the Point.y is at the bottom of the
  180. // last control created by adding the height of the control
  181. // to it.
  182. //
  183. Point.y += Rect.bottom;
  184. // Get the current position in client coordinates
  185. // of the Cancel button.
  186. //
  187. GetWindowRect(GetDlgItem(hDlg, IDCANCEL), &Rect);
  188. MapWindowPoints(NULL, hDlg, (LPPOINT)&Rect, 2);
  189. PointMove.x = Rect.left;
  190. PointMove.y = Rect.top;
  191. GetWindowRect(GetDlgItem(hDlg, IDCANCEL), &Rect);
  192. // Get the rect of the dialog in screen coordinates.
  193. //
  194. GetWindowRect(hDlg, &RectDlg);
  195. // Move up the cancel button based on the bottom of the last control
  196. // created and adding the space between the bottom of the cancel button
  197. // and the bottom of the dialog.
  198. //
  199. PointMove.y = Point.y + (RectDlg.bottom - Rect.bottom);
  200. // Move the Cancel button so it is up under the last control created.
  201. //
  202. SetWindowPos(GetDlgItem(hDlg, IDCANCEL), NULL, PointMove.x, PointMove.y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
  203. // Set where the bottom of the dialog in screen coordinates should
  204. // be based on where the cancel button was moved to.
  205. //
  206. Point.x = 0; // Don't care.
  207. Point.y = PointMove.y + RectDlg.bottom - Rect.top;
  208. ClientToScreen(hDlg, &Point);
  209. // Move up the bottom of the dialog so it is just under the cancel button.
  210. //
  211. SetWindowPos(hDlg, NULL, 0, 0, RectDlg.right - RectDlg.left, Point.y - RectDlg.top, SWP_NOMOVE | SWP_NOZORDER);
  212. g_hWndRunNowDlg = hDlg;
  213. return FALSE;
  214. case WM_PROGRESS:
  215. // Check to see if this is the first
  216. // time this function is run.
  217. //
  218. if ( hWndTemp == NULL )
  219. {
  220. // Get the rect of the title control we are going to base all the others of.
  221. // We need to convert the left top coordinates from screen to client coordinates.
  222. //
  223. GetWindowRect(GetDlgItem(hDlg, IDC_TITLE), &Rect);
  224. MapWindowPoints(NULL, hDlg, (LPPOINT)&Rect, 2);
  225. Point.x = Rect.left; // The left of the control.
  226. Point.y = Rect.top; // The top of the control.
  227. nHeight = Rect.bottom - Rect.top; // The height of the control.
  228. MapWindowPoints(NULL, hDlg, (LPPOINT)&Rect, 2);
  229. Point.y += FIRST_SPACING;
  230. }
  231. else
  232. {
  233. // Set the previous control to checked before creating the next one.
  234. //
  235. szWingDing[0] = (TCHAR) WINGDING_CHECK;
  236. SetWindowText(hWndTemp, szWingDing);
  237. if ( lphWnd && (nIndex >= 0) )
  238. SendMessage(*(lphWnd + nIndex), WM_SETFONT, (WPARAM) hNormFont, MAKELPARAM(TRUE, 0));
  239. nIndex--;
  240. }
  241. // Each new control should be 2 times the width of the control down
  242. // from the previous control. This will give 1 width of the control
  243. // between each.
  244. //
  245. Point.y += nHeight + LINE_SPACING;
  246. // Create the control and set the wingding font and arrow text.
  247. //
  248. hWndTemp = CreateWindow(_T("STATIC"), _T(""), WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE, Point.x, Point.y, CHECK_WIDTH, nHeight, hDlg, NULL, g_hInst, NULL);
  249. InitWingdingFont(hWndTemp);
  250. szWingDing[0] = (TCHAR) WINGDING_ARROW;
  251. SetWindowText(hWndTemp, szWingDing);
  252. // Bold the current item if we can.
  253. //
  254. if ( lphWnd && (nIndex >= 0) )
  255. {
  256. if ( hBoldFont == NULL )
  257. hBoldFont = GetFont(*(lphWnd + nIndex), NULL, 10, FW_BOLD);
  258. if ( hBoldFont )
  259. SendMessage(*(lphWnd + nIndex), WM_SETFONT, (WPARAM) hBoldFont, MAKELPARAM(TRUE, 0));
  260. }
  261. return TRUE;
  262. default:
  263. return FALSE;
  264. }
  265. }
  266. static VOID InitWingdingFont(HWND hWndCtrl)
  267. {
  268. static HFONT hCheckFont = NULL;
  269. TCHAR szFontName[32];
  270. DWORD dwFontSize;
  271. // If NULL is passed in, we should free the font handle.
  272. //
  273. if ( hWndCtrl == NULL )
  274. {
  275. // Free the font handle.
  276. //
  277. if ( hCheckFont )
  278. DeleteObject(hCheckFont);
  279. }
  280. else
  281. {
  282. // We may already have the handle to the font we need,
  283. // but if not, we need to get it.
  284. //
  285. if ( hCheckFont == NULL )
  286. {
  287. // Get the font size.
  288. //
  289. if ( LoadString(NULL, IDS_CHECKFONTSIZE, szFontName, sizeof(szFontName) / sizeof(TCHAR)) )
  290. dwFontSize = _tcstoul(szFontName, NULL, 10);
  291. else
  292. dwFontSize = 12;
  293. // Get the font name.
  294. //
  295. if ( !LoadString(NULL, IDS_CHECKFONTNAME, szFontName, sizeof(szFontName) / sizeof(TCHAR)) )
  296. lstrcpy(szFontName, _T("Wingdings"));
  297. hCheckFont = GetFont(hWndCtrl, szFontName, dwFontSize, FW_BOLD, TRUE);
  298. }
  299. // Now send the font to the control.
  300. //
  301. if ( hCheckFont )
  302. SendMessage(hWndCtrl, WM_SETFONT, (WPARAM) hCheckFont, MAKELPARAM(TRUE, 0));
  303. }
  304. }