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.

533 lines
14 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. fdinit.c
  5. Abstract:
  6. Code for initializing the fdisk application.
  7. Author:
  8. Ted Miller (tedm) 7-Jan-1992
  9. --*/
  10. #include "fdisk.h"
  11. HWND InitDlg;
  12. BOOLEAN StartedAsIcon = FALSE;
  13. BOOLEAN InitDlgComplete = FALSE;
  14. BOOL
  15. InitializeApp(
  16. VOID
  17. )
  18. /*++
  19. Routine Description:
  20. This routine initializes the fdisk app. This includes registering
  21. the frame window class and creating the frame window.
  22. Arguments:
  23. None.
  24. Return Value:
  25. boolean value indicating success or failure.
  26. --*/
  27. {
  28. WNDCLASS wc;
  29. TCHAR szTitle[80];
  30. DWORD ec;
  31. HDC hdcScreen = GetDC(NULL);
  32. TEXTMETRIC tm;
  33. BITMAP bitmap;
  34. HFONT hfontT;
  35. unsigned i;
  36. ReadProfile();
  37. // Load cursors
  38. hcurWait = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
  39. hcurNormal = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
  40. // fonts
  41. #ifdef JAPAN
  42. hFontGraph = CreateFont(GetHeightFromPoints(10), 0,
  43. 0, 0, 400, FALSE, FALSE, FALSE, SHIFTJIS_CHARSET,
  44. OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
  45. DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
  46. TEXT("System")
  47. );
  48. #else
  49. hFontGraph = CreateFont(GetHeightFromPoints(8), 0,
  50. 0, 0, 400, FALSE, FALSE, FALSE, ANSI_CHARSET,
  51. OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
  52. DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
  53. TEXT("Helv"));
  54. #endif
  55. hFontLegend = hFontGraph;
  56. hFontStatus = hFontGraph;
  57. #ifdef JAPAN
  58. hFontGraphBold = CreateFont(GetHeightFromPoints(10), 0,
  59. 0, 0, 700, FALSE, FALSE, FALSE,
  60. SHIFTJIS_CHARSET, OUT_DEFAULT_PRECIS,
  61. CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
  62. VARIABLE_PITCH | FF_SWISS, TEXT("System")
  63. );
  64. #else
  65. hFontGraphBold = CreateFont(GetHeightFromPoints(8), 0,
  66. 0, 0, 700, FALSE, FALSE, FALSE, ANSI_CHARSET,
  67. OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
  68. DEFAULT_QUALITY, VARIABLE_PITCH | FF_SWISS,
  69. TEXT("Helv"));
  70. #endif
  71. hfontT = SelectObject(hdcScreen, hFontGraph);
  72. GetTextMetrics(hdcScreen, &tm);
  73. if (hfontT) {
  74. SelectObject(hdcScreen, hfontT);
  75. }
  76. hPenNull = CreatePen(PS_NULL, 0, 0);
  77. hPenThinSolid = CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
  78. GraphWidth = (DWORD)GetSystemMetrics(SM_CXSCREEN);
  79. GraphHeight = 25 * tm.tmHeight / 4; // 6.25 x font height
  80. // set up the legend off-screen bitmap
  81. wLegendItem = GetSystemMetrics(SM_CXHTHUMB);
  82. dyLegend = 2 * wLegendItem; // 7*wLegendItem/2 for a double-height legend
  83. ReleaseDC(NULL, hdcScreen);
  84. dyBorder = GetSystemMetrics(SM_CYBORDER);
  85. dyStatus = tm.tmHeight + tm.tmExternalLeading + 7 * dyBorder;
  86. // set up brushes
  87. for (i=0; i<BRUSH_ARRAY_SIZE; i++) {
  88. Brushes[i] = CreateHatchBrush(AvailableHatches[BrushHatches[i]], AvailableColors[BrushColors[i]]);
  89. }
  90. hBrushFreeLogical = CreateHatchBrush(HS_FDIAGONAL, RGB(128, 128, 128));
  91. hBrushFreePrimary = CreateHatchBrush(HS_BDIAGONAL, RGB(128, 128, 128));
  92. // load legend strings
  93. for (i=IDS_LEGEND_FIRST; i<=IDS_LEGEND_LAST; i++) {
  94. if (!(LegendLabels[i-IDS_LEGEND_FIRST] = LoadAString(i))) {
  95. return FALSE;
  96. }
  97. }
  98. if (((wszUnformatted = LoadWString(IDS_UNFORMATTED)) == NULL)
  99. || ((wszNewUnformatted = LoadWString(IDS_NEW_UNFORMATTED)) == NULL)
  100. || ((wszUnknown = LoadWString(IDS_UNKNOWN )) == NULL)) {
  101. return FALSE;
  102. }
  103. // register the frame class
  104. wc.style = CS_OWNDC | CS_VREDRAW;
  105. wc.lpfnWndProc = MyFrameWndProc;
  106. wc.cbClsExtra = 0;
  107. wc.cbWndExtra = 0;
  108. wc.hInstance = hModule;
  109. wc.hIcon = LoadIcon(hModule, MAKEINTRESOURCE(IDFDISK));
  110. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  111. wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
  112. wc.lpszMenuName = MAKEINTRESOURCE(IDFDISK);
  113. wc.lpszClassName = szFrame;
  114. if (!RegisterClass(&wc)) {
  115. return FALSE;
  116. }
  117. if (!RegisterArrowClass(hModule)) {
  118. return FALSE;
  119. }
  120. LoadString(hModule, IDS_APPNAME, szTitle, sizeof(szTitle)/sizeof(TCHAR));
  121. // create the frame window. Note that this also creates the listbox.
  122. hwndFrame = CreateWindow(szFrame,
  123. szTitle,
  124. WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
  125. ProfileWindowX,
  126. ProfileWindowY,
  127. ProfileWindowW,
  128. ProfileWindowH,
  129. NULL,
  130. NULL,
  131. hModule,
  132. NULL);
  133. if (!hwndFrame) {
  134. return FALSE;
  135. }
  136. if (!hwndList) {
  137. DestroyWindow(hwndFrame);
  138. return FALSE;
  139. }
  140. hDC = GetDC(hwndFrame);
  141. BarTopYOffset = tm.tmHeight;
  142. BarHeight = 21 * tm.tmHeight / 4;
  143. BarBottomYOffset = BarTopYOffset + BarHeight;
  144. dxBarTextMargin = 5*tm.tmAveCharWidth/4;
  145. dyBarTextLine = tm.tmHeight;
  146. dxDriveLetterStatusArea = 5 * tm.tmAveCharWidth / 2;
  147. hBitmapSmallDisk = LoadBitmap(hModule, MAKEINTRESOURCE(IDB_SMALLDISK));
  148. GetObject(hBitmapSmallDisk, sizeof(BITMAP), &bitmap);
  149. dxSmallDisk = bitmap.bmWidth;
  150. dySmallDisk = bitmap.bmHeight;
  151. xSmallDisk = dxSmallDisk / 2;
  152. ySmallDisk = BarTopYOffset + (2*dyBarTextLine) - dySmallDisk - tm.tmDescent;
  153. hBitmapRemovableDisk = LoadBitmap(hModule, MAKEINTRESOURCE(IDB_REMOVABLE));
  154. GetObject(hBitmapRemovableDisk, sizeof(BITMAP), &bitmap);
  155. dxRemovableDisk = bitmap.bmWidth;
  156. dyRemovableDisk = bitmap.bmHeight;
  157. xRemovableDisk = dxRemovableDisk / 2;
  158. yRemovableDisk = BarTopYOffset + (2*dyBarTextLine) - dyRemovableDisk - tm.tmDescent;
  159. BarLeftX = 7 * dxSmallDisk;
  160. BarWidth = GraphWidth - BarLeftX - (5 * tm.tmAveCharWidth);
  161. DiskN = LoadAString(IDS_DISKN);
  162. if ((ec = InitializeListBox(hwndList)) != NO_ERROR) {
  163. DestroyWindow(hwndList);
  164. DestroyWindow(hwndFrame);
  165. return FALSE;
  166. }
  167. // initial list box selection cursor (don't allow to fall on
  168. // extended partition).
  169. LBCursorListBoxItem = 0;
  170. ResetLBCursorRegion();
  171. ShowWindow(hwndFrame,
  172. ProfileIsIconic ? SW_SHOWMINIMIZED
  173. : ProfileIsMaximized ? SW_SHOWMAXIMIZED : SW_SHOWDEFAULT);
  174. UpdateWindow(hwndFrame);
  175. return TRUE;
  176. }
  177. VOID
  178. CreateDiskState(
  179. OUT PDISKSTATE *DiskState,
  180. IN DWORD Disk,
  181. OUT PBOOL SignatureCreated
  182. )
  183. /*++
  184. Routine Description:
  185. This routine is designed to be called once, at initialization time,
  186. per disk. It creates and initializes a disk state -- which includes
  187. creating a memory DC and compatible bitmap for drawing the disk's
  188. graph, and getting some information that is static in nature about
  189. the disk (ie, its total size.)
  190. Arguments:
  191. DiskState - structure whose fields are to be intialized
  192. Disk - number of disk
  193. SignatureCreated - received boolean indicating whether an FT signature was created for
  194. the disk.
  195. Return Value:
  196. None.
  197. --*/
  198. {
  199. HDC hDCMem;
  200. PDISKSTATE pDiskState = Malloc(sizeof(DISKSTATE));
  201. *DiskState = pDiskState;
  202. pDiskState->LeftRight = Malloc(0);
  203. pDiskState->Selected = Malloc(0);
  204. pDiskState->Disk = Disk;
  205. // create a memory DC for drawing the bar off-screen,
  206. // and the correct bitmap
  207. #if 0
  208. pDiskState->hDCMem = NULL;
  209. pDiskState->hbmMem = NULL;
  210. hDCMem = CreateCompatibleDC(hDC);
  211. #else
  212. pDiskState->hDCMem = hDCMem = CreateCompatibleDC(hDC);
  213. pDiskState->hbmMem = CreateCompatibleBitmap(hDC, GraphWidth, GraphHeight);
  214. #endif
  215. SelectObject(hDCMem,pDiskState->hbmMem);
  216. pDiskState->RegionArray = NULL;
  217. pDiskState->RegionCount = 0;
  218. pDiskState->BarType = BarAuto;
  219. pDiskState->OffLine = IsDiskOffLine(Disk);
  220. if (pDiskState->OffLine) {
  221. pDiskState->SigWasCreated = FALSE;
  222. pDiskState->Signature = 0;
  223. pDiskState->DiskSizeMB = 0;
  224. FDLOG((1, "CreateDiskState: Disk %u is off-line\n", Disk));
  225. } else {
  226. pDiskState->DiskSizeMB = DiskSizeMB(Disk);
  227. if (pDiskState->Signature = FdGetDiskSignature(Disk)) {
  228. if (SignatureIsUniqueToSystem(Disk, pDiskState->Signature)) {
  229. pDiskState->SigWasCreated = FALSE;
  230. FDLOG((2,
  231. "CreateDiskState: Found signature %08lx on disk %u\n",
  232. pDiskState->Signature,
  233. Disk));
  234. } else {
  235. goto createSignature;
  236. }
  237. } else {
  238. createSignature:
  239. pDiskState->Signature = FormDiskSignature();
  240. FdSetDiskSignature(Disk, pDiskState->Signature);
  241. pDiskState->SigWasCreated = TRUE;
  242. FDLOG((1,
  243. "CreateDiskState: No signature on disk %u; created signature %08lx\n",
  244. Disk,
  245. pDiskState->Signature));
  246. }
  247. }
  248. *SignatureCreated = (BOOL)pDiskState->SigWasCreated;
  249. }
  250. BOOL CALLBACK
  251. InitializationDlgProc(
  252. IN HWND hDlg,
  253. IN UINT uMsg,
  254. IN WPARAM wParam,
  255. IN LPARAM lParam
  256. )
  257. /*++
  258. Routine Description:
  259. Arguments:
  260. standard Windows dialog procedure
  261. Return Values:
  262. standard Windows dialog procedure
  263. --*/
  264. {
  265. static DWORD percentDrawn;
  266. static RECT rectGG; // GasGauge rectangle
  267. static BOOL captionIsLoaded;
  268. static PFORMAT_PARAMS formatParams;
  269. TCHAR title[100],
  270. templateString[100];
  271. switch (uMsg) {
  272. case WM_INITDIALOG: {
  273. HWND hwndGauge = GetDlgItem(hDlg, IDC_GASGAUGE);
  274. InitDlg = hDlg;
  275. percentDrawn = 0;
  276. StartedAsIcon = IsIconic(hDlg);
  277. // Get the coordinates of the gas gauge static control rectangle,
  278. // and convert them to dialog client area coordinates
  279. GetClientRect(hwndGauge, &rectGG);
  280. ClientToScreen(hwndGauge, (LPPOINT)&rectGG.left);
  281. ClientToScreen(hwndGauge, (LPPOINT)&rectGG.right);
  282. ScreenToClient(hDlg, (LPPOINT)&rectGG.left);
  283. ScreenToClient(hDlg, (LPPOINT)&rectGG.right);
  284. return TRUE;
  285. }
  286. case WM_PAINT: {
  287. INT width = rectGG.right - rectGG.left;
  288. INT height = rectGG.bottom - rectGG.top;
  289. INT nDivideRects;
  290. HDC hDC;
  291. PAINTSTRUCT ps;
  292. TCHAR buffer[10];
  293. SIZE size;
  294. INT xText,
  295. yText,
  296. byteCount;
  297. RECT rectDone,
  298. rectLeftToDo;
  299. hDC = BeginPaint(hDlg, &ps);
  300. byteCount = wsprintf(buffer, TEXT("%3d%%"), percentDrawn);
  301. GetTextExtentPoint(hDC, buffer, lstrlen(buffer), &size);
  302. xText = rectGG.left + (width - size.cx) / 2;
  303. yText = rectGG.top + (height - size.cy) / 2;
  304. // Paint in the "done so far" rectangle of the gas
  305. // gauge with blue background and white text
  306. nDivideRects = (width * percentDrawn) / 100;
  307. SetRect(&rectDone,
  308. rectGG.left,
  309. rectGG.top,
  310. rectGG.left + nDivideRects,
  311. rectGG.bottom);
  312. SetTextColor(hDC, RGB(255, 255, 255));
  313. SetBkColor(hDC, RGB(0, 0, 255));
  314. ExtTextOut(hDC,
  315. xText,
  316. yText,
  317. ETO_CLIPPED | ETO_OPAQUE,
  318. &rectDone,
  319. buffer,
  320. byteCount/sizeof(TCHAR),
  321. NULL);
  322. // Paint in the "still left to do" rectangle of the gas
  323. // gauge with white background and blue text
  324. SetRect(&rectLeftToDo,
  325. rectGG.left + nDivideRects,
  326. rectGG.top,
  327. rectGG.right,
  328. rectGG.bottom);
  329. SetBkColor(hDC, RGB(255, 255, 255));
  330. SetTextColor(hDC, RGB(0, 0, 255));
  331. ExtTextOut(hDC,
  332. xText,
  333. yText,
  334. ETO_CLIPPED | ETO_OPAQUE,
  335. &rectLeftToDo,
  336. buffer,
  337. byteCount/sizeof(TCHAR),
  338. NULL);
  339. EndPaint(hDlg, &ps);
  340. if (percentDrawn == 100) {
  341. InitDlgComplete = TRUE;
  342. }
  343. return TRUE;
  344. }
  345. case WM_USER:
  346. percentDrawn = (INT)wParam;
  347. InvalidateRect(hDlg, &rectGG, TRUE);
  348. UpdateWindow(hDlg);
  349. return TRUE;
  350. case (WM_USER + 1):
  351. EndDialog(hDlg, FALSE);
  352. return TRUE;
  353. default:
  354. return FALSE;
  355. }
  356. }
  357. VOID
  358. InitializationMessageThread(
  359. PVOID ThreadParameter
  360. )
  361. /*++
  362. Routine Description:
  363. This is the entry for the initialization message thread. It creates
  364. a dialog that simply tells the user to be patient.
  365. Arguments:
  366. ThreadParameter - not used.
  367. Return Value:
  368. None
  369. --*/
  370. {
  371. DialogBoxParam(hModule,
  372. MAKEINTRESOURCE(IDD_INITIALIZING),
  373. hwndFrame,
  374. InitializationDlgProc,
  375. (ULONG) NULL);
  376. InitDlg = (HWND) 0;
  377. ExitThread(0L);
  378. }
  379. VOID
  380. DisplayInitializationMessage(
  381. VOID
  382. )
  383. /*++
  384. Routine Description:
  385. Create a 2nd thread to display an initialization message.
  386. Arguments:
  387. None
  388. Return Value:
  389. None
  390. --*/
  391. {
  392. HANDLE threadHandle;
  393. DWORD threadId;
  394. threadHandle = CreateThread(NULL,
  395. 0,
  396. (LPTHREAD_START_ROUTINE) InitializationMessageThread,
  397. (LPVOID) NULL,
  398. (DWORD) 0,
  399. (LPDWORD) &threadId);
  400. if (!threadHandle) {
  401. CloseHandle(threadHandle);
  402. }
  403. }