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.

875 lines
25 KiB

  1. /*****************************************************************************************************************
  2. FILENAME: GraphWin.cpp
  3. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  4. */
  5. #ifndef SNAPIN
  6. #ifndef NOWINDOWSH
  7. #include <windows.h>
  8. #endif
  9. #endif
  10. #include "stdafx.h"
  11. extern "C" {
  12. #include "SysStruc.h"
  13. }
  14. #include "DfrgUI.h"
  15. #include "DfrgCmn.h"
  16. #include "DfrgEngn.h"
  17. #include "DiskView.h"
  18. #include "DfrgCtl.h"
  19. #include "DataIoCl.h"
  20. #include "GraphWin.h"
  21. #include "Message.h"
  22. #include "Graphix.h"
  23. #include "ESButton.h"
  24. #include "ErrMacro.h"
  25. #include "DlgRpt.h"
  26. #include "DfrgRes.h"
  27. #include "VolList.h"
  28. /****************************************************************************************************************/
  29. extern CDfrgCtl* pCDfrgCtl;
  30. extern HINSTANCE hinstRes;
  31. extern HINSTANCE hInstRes;
  32. extern HINSTANCE hinstMain;
  33. extern HFONT g_hFont;
  34. extern CVolList VolumeList;
  35. extern BOOL bSnapinSelected;
  36. /****************************************************************************************************************/
  37. HWND hwndGraphics = NULL;
  38. RECT rcGraphics;
  39. RECT rcDefragStartButton;
  40. RECT rcAnalyzeStartButton;
  41. RECT rcPauseButton;
  42. RECT rcCancelButton;
  43. RECT rcReportButton;
  44. RECT rcAnalyzeDisp;
  45. RECT rcDefragDisp;
  46. static RECT rcAnalyzeBorder;
  47. static RECT rcDefragBorder;
  48. extern RECT rcCtlRect;
  49. static ESButton* pAnalyzeButton = NULL;
  50. static ESButton* pDefragButton = NULL;
  51. static ESButton* pPauseButton = NULL;
  52. static ESButton* pStopButton = NULL;
  53. static ESButton* pReportButton = NULL;
  54. static DWORD dwLastMax = 0;
  55. static int iLastPos = 0;
  56. static DWORD dwScrollUnit = 0;
  57. static DWORD dwScrollPage = 0;
  58. #define ESI_BUTTON_SPACE 6
  59. #define ESI_BUTTON_WIDTH 84
  60. #define ESI_LEFT_MARGIN 14
  61. /****************************************************************************************************************/
  62. static BOOL
  63. PaintGraphicsWindowBackground(
  64. HDC WorkDC
  65. );
  66. /*****************************************************************************************************************
  67. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  68. ROUTINE DESCRIPTION:
  69. GLOBAL VARIABLES:
  70. INPUT:
  71. None;
  72. RETURN:
  73. None.
  74. */
  75. BOOL
  76. InitializeGraphicsWindow(
  77. IN HWND hwnd,
  78. IN HINSTANCE hInst
  79. )
  80. {
  81. WNDCLASS wc;
  82. // Initialize the window class.
  83. wc.style = CS_OWNDC|CS_HREDRAW|CS_VREDRAW|CS_SAVEBITS;
  84. wc.lpfnWndProc = (WNDPROC) GraphicsWndProc;
  85. wc.cbClsExtra = 0;
  86. wc.cbWndExtra = 0;
  87. wc.hInstance = hInst;
  88. wc.hIcon = NULL;
  89. wc.hCursor = NULL;
  90. wc.hbrBackground = NULL;
  91. wc.lpszMenuName = NULL;
  92. wc.lpszClassName = GRAPHICSWINDOW_CLASS;
  93. // Register the window class.
  94. EF(RegisterClass(&wc));
  95. // Create the window.
  96. EF((hwndGraphics = CreateWindow(GRAPHICSWINDOW_CLASS,
  97. TEXT(""),
  98. WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN,
  99. CW_USEDEFAULT,
  100. CW_USEDEFAULT,
  101. CW_USEDEFAULT,
  102. CW_USEDEFAULT,
  103. hwnd,
  104. NULL,
  105. hInst,
  106. NULL)) != NULL);
  107. ShowScrollBar(hwndGraphics, SB_VERT, FALSE);
  108. ShowWindow(hwndGraphics, SW_SHOW);
  109. UpdateWindow(hwndGraphics);
  110. pAnalyzeButton = new ESButton(hwndGraphics, ID_ANALYZE, hInst);
  111. pDefragButton = new ESButton(hwndGraphics, ID_DEFRAG, hInst);
  112. pPauseButton = new ESButton(hwndGraphics, ID_PAUSE, hInst);
  113. pStopButton = new ESButton(hwndGraphics, ID_STOP, hInst);
  114. pReportButton = new ESButton(hwndGraphics, ID_REPORT, hInst);
  115. pAnalyzeButton->SetFont(g_hFont);
  116. pAnalyzeButton->SetText(hInstRes, IDS_BTN_ANALYZE);
  117. pDefragButton->SetFont(g_hFont);
  118. pDefragButton->SetText(hInstRes, IDS_BTN_DEFRAGMENT);
  119. pPauseButton->SetFont(g_hFont);
  120. pPauseButton->SetText(hInstRes, IDS_BTN_PAUSE);
  121. pStopButton->SetFont(g_hFont);
  122. pStopButton->SetText(hInstRes, IDS_BTN_STOP);
  123. pReportButton->SetFont(g_hFont);
  124. pReportButton->SetText(hInstRes, IDS_BTN_REPORT);
  125. SetButtonState();
  126. SetFocus(pAnalyzeButton->GetWindowHandle());
  127. return TRUE;
  128. }
  129. /*****************************************************************************************************************
  130. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  131. ROUTINE DESCRIPTION:
  132. This is the WndProc function for the graphics window.
  133. GLOBALS:
  134. INPUT:
  135. hWnd - Handle to the window.
  136. uMsg - The message.
  137. wParam - The word parameter for the message.
  138. lParam - the long parameter for the message.
  139. RETURN:
  140. various.
  141. */
  142. LRESULT CALLBACK
  143. GraphicsWndProc(
  144. IN HWND hWnd,
  145. IN UINT uMsg,
  146. IN UINT wParam,
  147. IN LONG lParam
  148. )
  149. {
  150. switch(uMsg) {
  151. case WM_COMMAND:
  152. switch ((short int)wParam) {
  153. case ID_ANALYZE:
  154. pCDfrgCtl->put_Command(ID_ANALYZE);
  155. break;
  156. case ID_DEFRAG:
  157. pCDfrgCtl->put_Command(ID_DEFRAG);
  158. break;
  159. case ID_PAUSE:
  160. pCDfrgCtl->put_Command(ID_PAUSE);
  161. break;
  162. case ID_CONTINUE:
  163. pCDfrgCtl->put_Command(ID_CONTINUE);
  164. break;
  165. case ID_STOP:
  166. pCDfrgCtl->put_Command(ID_STOP);
  167. break;
  168. case ID_REPORT:
  169. if (VolumeList.GetCurrentVolume()->IsReportOKToDisplay()){
  170. // raise the report dialog
  171. RaiseReportDialog(
  172. VolumeList.GetCurrentVolume(),
  173. VolumeList.GetCurrentVolume()->DefragMode());
  174. }
  175. break;
  176. return S_OK;
  177. }
  178. case WM_VSCROLL:
  179. switch((short int)wParam){
  180. case SB_LINEDOWN:
  181. iLastPos += dwScrollUnit;
  182. break;
  183. case SB_LINEUP:
  184. iLastPos -= dwScrollUnit;
  185. break;
  186. case SB_PAGEDOWN:
  187. iLastPos += dwScrollPage;
  188. break;
  189. case SB_PAGEUP:
  190. iLastPos -= dwScrollPage;
  191. break;
  192. case SB_THUMBPOSITION:
  193. case SB_THUMBTRACK:
  194. iLastPos = (wParam >> 16)*dwLastMax/100;
  195. break;
  196. case SB_ENDSCROLL:
  197. return 0;
  198. }
  199. if(iLastPos < 0){
  200. iLastPos = 0;
  201. }
  202. if(iLastPos > (int)dwLastMax){
  203. iLastPos = dwLastMax;
  204. }
  205. SizeGraphicsWindow();
  206. // pCDfrgCtl->InvalidateRect(NULL, TRUE);
  207. // pCDfrgCtl->FireViewChange();
  208. pCDfrgCtl->OnDrawFunction();
  209. break;
  210. case WM_ERASEBKGND:
  211. return TRUE;
  212. break;
  213. case WM_PAINT:
  214. {
  215. PAINTSTRUCT ps;
  216. EF(BeginPaint(hWnd, &ps));
  217. PaintGraphicsWindowFunction();
  218. EF(EndPaint(hWnd, &ps));
  219. }
  220. break;
  221. case WM_CLOSE:
  222. DestroyWindow(hWnd);
  223. break;
  224. case WM_DESTROY:
  225. // Destroy the thread.
  226. PostQuitMessage(0);
  227. break;
  228. default:
  229. return DefWindowProc(hWnd, uMsg, wParam, lParam);
  230. }
  231. return 0;
  232. }
  233. /*****************************************************************************************************************
  234. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  235. ROUTINE DESCRIPTION:
  236. Sizes the graphics window
  237. GLOBAL VARIABLES:
  238. HWND hwndGraphics - handle of the list view window.
  239. INPUT:
  240. RETURN:
  241. TRUE = success
  242. FALSE = error
  243. */
  244. BOOL
  245. SizeGraphicsWindow(
  246. void
  247. )
  248. {
  249. SET_DISP_DATA DispData = {0};
  250. SCROLLINFO si = {0};
  251. CVolume *pVolume = VolumeList.GetCurrentVolume();
  252. si.cbSize = sizeof(SCROLLINFO);
  253. // Size and position the Graphics window.
  254. EF(SetWindowPos(hwndGraphics, // handle of window
  255. HWND_TOP, // placement-order handle
  256. rcGraphics.left, // horizontal position
  257. rcGraphics.top, // vertical position
  258. rcGraphics.right - rcGraphics.left, // width
  259. rcGraphics.bottom - rcGraphics.top, // height
  260. SWP_SHOWWINDOW // window-positioning flags
  261. ));
  262. si.fMask = SIF_RANGE|SIF_POS;
  263. si.nMin = 0;
  264. if((rcGraphics.bottom - rcGraphics.top) > MIN_SCROLL_HEIGHT){
  265. si.nMax = 0;
  266. }
  267. else {
  268. si.nMax = MIN_SCROLL_HEIGHT - (rcGraphics.bottom - rcGraphics.top);
  269. }
  270. si.nPos = iLastPos;
  271. if(si.nPos > si.nMax){
  272. si.nPos = si.nMax;
  273. }
  274. SetScrollInfo(hwndGraphics, SB_VERT, &si, TRUE);
  275. dwLastMax = si.nMax;
  276. iLastPos = si.nPos;
  277. dwScrollUnit = si.nMax / 10;
  278. dwScrollPage = rcGraphics.bottom - rcGraphics.top;
  279. if(dwScrollPage > (DWORD)si.nMax){
  280. dwScrollPage = si.nMax;
  281. }
  282. //Calculate the position for the analyze display rectangle.
  283. rcAnalyzeDisp.top = 40 - si.nPos;
  284. if((rcGraphics.bottom - rcGraphics.top) > MIN_SCROLL_HEIGHT){
  285. rcAnalyzeDisp.top += ((rcGraphics.bottom - rcGraphics.top) - MIN_SCROLL_HEIGHT)/2;
  286. }
  287. rcAnalyzeDisp.bottom = rcAnalyzeDisp.top + TOP_MARGIN_RAW + BOTTOM_MARGIN_RAW + ROW_HEIGHT_RAW;
  288. rcAnalyzeDisp.left = ESI_LEFT_MARGIN;
  289. rcAnalyzeDisp.right = (rcGraphics.right - rcGraphics.left) - ESI_LEFT_MARGIN - (si.nMax ? 25 : 0);
  290. // max right margin of the graphics wells
  291. int maxRightEdge = ESI_LEFT_MARGIN + 5*ESI_BUTTON_WIDTH + 4*ESI_BUTTON_SPACE;
  292. if (rcAnalyzeDisp.right < maxRightEdge)
  293. rcAnalyzeDisp.right = maxRightEdge;
  294. //Calculate from the analyze display rectangle, the position of the defrag display rectangle.
  295. rcDefragDisp = rcAnalyzeDisp;
  296. rcDefragDisp.top = rcDefragDisp.bottom + 40;
  297. rcDefragDisp.bottom = rcDefragDisp.top + rcAnalyzeDisp.bottom - rcAnalyzeDisp.top;
  298. //Set output dimensions on the analyze display rectangle.
  299. if(pVolume->m_pAnalyzeDisplay) {
  300. //Get mutex.
  301. EF_ASSERT(WaitForSingleObject(pVolume->m_hAnalyzeDisplayMutex,
  302. DISKDISPLAYMUTEXWAITINTERVAL
  303. ) == WAIT_OBJECT_0);
  304. //Set the dimensions.
  305. (pVolume->m_pAnalyzeDisplay)->SetNewOutputDimensions(
  306. rcAnalyzeDisp.left,
  307. rcAnalyzeDisp.top,
  308. rcAnalyzeDisp.right - rcAnalyzeDisp.left,
  309. rcAnalyzeDisp.bottom - rcAnalyzeDisp.top);
  310. //Get the cluster factor (so we can test for an error consition -- this value should not be zero.)
  311. DispData.AnalyzeClusterFactor = (pVolume->m_pAnalyzeDisplay)->GetClusterFactor();
  312. //Close the mutex.
  313. EF_ASSERT(ReleaseMutex(pVolume->m_hAnalyzeDisplayMutex));
  314. //Test for the cluster factor equaling zero.
  315. EF_ASSERT(DispData.AnalyzeClusterFactor);
  316. }
  317. //Set output dimensions on the defrag display rectangle.
  318. if(pVolume->m_pDefragDisplay) {
  319. //Get mutex.
  320. EF_ASSERT(WaitForSingleObject(pVolume->m_hDefragDisplayMutex,
  321. DISKDISPLAYMUTEXWAITINTERVAL)
  322. == WAIT_OBJECT_0);
  323. //Set the dimensions.
  324. (pVolume->m_pDefragDisplay)->SetNewOutputDimensions(
  325. rcDefragDisp.left,
  326. rcDefragDisp.top,
  327. rcDefragDisp.right - rcDefragDisp.left,
  328. rcDefragDisp.bottom - rcDefragDisp.top);
  329. //Get the cluster factor (so we can test for an error consition -- this value should not be zero.)
  330. DispData.DefragClusterFactor = (pVolume->m_pDefragDisplay)->GetClusterFactor();
  331. //Close the mutex.
  332. EF_ASSERT(ReleaseMutex(pVolume->m_hDefragDisplayMutex));
  333. //Test for the cluster factor equaling zero.
  334. EF_ASSERT(DispData.DefragClusterFactor);
  335. }
  336. if(pVolume->m_pdataDefragEngine && (DispData.AnalyzeClusterFactor || DispData.DefragClusterFactor)) {
  337. DataIoClientSetData(ID_SETDISPDIMENSIONS,
  338. (PTCHAR)&DispData,
  339. sizeof(SET_DISP_DATA),
  340. pVolume->m_pdataDefragEngine);
  341. }
  342. // Calculate the analyze display border.
  343. rcAnalyzeBorder.top = rcAnalyzeDisp.top - 1;
  344. rcAnalyzeBorder.left = rcAnalyzeDisp.left - 1;
  345. rcAnalyzeBorder.right = rcAnalyzeDisp.right;
  346. rcAnalyzeBorder.bottom = rcAnalyzeDisp.bottom;
  347. // Calculate the defrag display border.
  348. rcDefragBorder.top = rcDefragDisp.top - 1;
  349. rcDefragBorder.left = rcDefragDisp.left - 1;
  350. rcDefragBorder.right = rcDefragDisp.right;
  351. rcDefragBorder.bottom = rcDefragDisp.bottom;
  352. // Calculate the Analyze button position and size.
  353. rcAnalyzeStartButton.top = rcDefragDisp.bottom + ESI_LEFT_MARGIN - 1;
  354. rcAnalyzeStartButton.left = rcDefragDisp.left - 1;
  355. rcAnalyzeStartButton.right = rcAnalyzeStartButton.left + ESI_BUTTON_WIDTH;
  356. rcAnalyzeStartButton.bottom = rcAnalyzeStartButton.top + 26;
  357. // start off with all buttons the same as the analyze button
  358. rcDefragStartButton =
  359. rcPauseButton =
  360. rcCancelButton =
  361. rcReportButton =
  362. rcAnalyzeStartButton;
  363. // Calculate the Defrag button position and size.
  364. rcDefragStartButton.left = rcAnalyzeStartButton.right + ESI_BUTTON_SPACE;
  365. rcDefragStartButton.right = rcDefragStartButton.left + ESI_BUTTON_WIDTH;
  366. // Calculate the Pause button position and size.
  367. rcPauseButton.left = rcDefragStartButton.right + ESI_BUTTON_SPACE;
  368. rcPauseButton.right = rcPauseButton.left + ESI_BUTTON_WIDTH;
  369. // Calculate the Cancel button position and size.
  370. rcCancelButton.left = rcPauseButton.right + ESI_BUTTON_SPACE;
  371. rcCancelButton.right = rcCancelButton.left + ESI_BUTTON_WIDTH;
  372. // Calculate the See Report button position and size.
  373. rcReportButton.left = rcCancelButton.right + ESI_BUTTON_SPACE;
  374. rcReportButton.right = rcReportButton.left + ESI_BUTTON_WIDTH;
  375. // put the buttons on the screen
  376. pAnalyzeButton->PositionButton(&rcAnalyzeStartButton);
  377. pDefragButton->PositionButton(&rcDefragStartButton);
  378. pPauseButton->PositionButton(&rcPauseButton);
  379. pStopButton->PositionButton(&rcCancelButton);
  380. pReportButton->PositionButton(&rcReportButton);
  381. return TRUE;
  382. }
  383. /*****************************************************************************************************************
  384. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  385. ROUTINE DESCRIPTION:
  386. GLOBAL VARIABLES:
  387. INPUT:
  388. RETURN:
  389. TRUE = success
  390. FALSE = error
  391. */
  392. BOOL
  393. PaintGraphicsWindowFunction(
  394. )
  395. {
  396. HDC OutputDC, WorkDC;
  397. HANDLE hBitmap = NULL;
  398. HANDLE hOld = NULL;
  399. RECT rect;
  400. //Only paint if this snapin is selected.
  401. if(!bSnapinSelected){
  402. return TRUE;
  403. }
  404. //Get the size of the window.
  405. EF(GetClientRect(hwndGraphics, &rect));
  406. // Get the DC
  407. OutputDC = GetDC(hwndGraphics);
  408. WorkDC = CreateCompatibleDC(OutputDC);
  409. EF_ASSERT(hBitmap = CreateCompatibleBitmap(OutputDC, rect.right-rect.left, rect.bottom-rect.top));
  410. hOld = SelectObject(WorkDC, hBitmap);
  411. // Paint a light gray background on the entire window.
  412. HBRUSH hBrush = (HBRUSH) CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
  413. FillRect(WorkDC, &rect, hBrush);
  414. DeleteObject(hBrush);
  415. EF(PaintGraphicsWindowBackground(WorkDC));
  416. EF(PaintGraphicsWindow(rect, FALSE, WorkDC));
  417. EF(BitBlt(OutputDC, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, WorkDC, 0, 0, SRCCOPY));
  418. // Cleanup the bitmap stuff.
  419. EF(hBitmap == SelectObject(WorkDC, hOld));
  420. EF(DeleteObject(hBitmap));
  421. EF(DeleteDC(WorkDC));
  422. EF(ReleaseDC(hwndGraphics, OutputDC));
  423. return TRUE;
  424. }
  425. /*****************************************************************************************************************
  426. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  427. ROUTINE DESCRIPTION:
  428. Paints the information in the graphics window.
  429. GLOBAL VARIABLES:
  430. INPUT:
  431. RETURN:
  432. TRUE = success
  433. FALSE = error
  434. */
  435. BOOL
  436. PaintGraphicsWindow(
  437. IN RECT rect,
  438. IN BOOL bPartialRedraw,
  439. HDC hdc
  440. )
  441. {
  442. CVolume *pVolume = VolumeList.GetCurrentVolume();
  443. //Paint the analyze display.
  444. if(pVolume->m_pAnalyzeDisplay) {
  445. //Get The mutex.
  446. EF_ASSERT(WaitForSingleObject(pVolume->m_hAnalyzeDisplayMutex,
  447. DISKDISPLAYMUTEXWAITINTERVAL
  448. ) == WAIT_OBJECT_0);
  449. //Do the draw.
  450. pVolume->m_pAnalyzeDisplay->DrawLinesInHDC(
  451. NULL,
  452. hdc,
  453. bPartialRedraw ? NULL : &rect,
  454. FALSE);
  455. //Release the mutex.
  456. EF_ASSERT(ReleaseMutex(pVolume->m_hAnalyzeDisplayMutex));
  457. }
  458. //Paint the defrag display.
  459. if(pVolume->m_pDefragDisplay) {
  460. //Get The mutex.
  461. EF_ASSERT(WaitForSingleObject(pVolume->m_hDefragDisplayMutex,
  462. DISKDISPLAYMUTEXWAITINTERVAL
  463. ) == WAIT_OBJECT_0);
  464. //Do the draw.
  465. pVolume->m_pDefragDisplay->DrawLinesInHDC(
  466. NULL,
  467. hdc,
  468. bPartialRedraw ? NULL : &rect,
  469. FALSE);
  470. //Release the mutex.
  471. EF_ASSERT(ReleaseMutex(pVolume->m_hDefragDisplayMutex));
  472. }
  473. return TRUE;
  474. }
  475. /*****************************************************************************************************************
  476. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  477. ROUTINE DESCRIPTION:
  478. Paints the information in the graphics window. Most code extracted from DrawBackgroundBorders.
  479. GLOBAL VARIABLES:
  480. INPUT:
  481. RETURN:
  482. TRUE = success
  483. FALSE = error
  484. */
  485. static BOOL
  486. PaintGraphicsWindowBackground(
  487. HDC WorkDC
  488. )
  489. {
  490. /* HDC OutputDC, WorkDC;
  491. HANDLE hBitmap = NULL;
  492. // Get the DC
  493. OutputDC = GetDC(hwndGraphics);
  494. WorkDC = CreateCompatibleDC(OutputDC);
  495. EF_ASSERT(hBitmap = CreateCompatibleBitmap(OutputDC, rcGraphics.right-rcGraphics.left, rcGraphics.bottom-rcGraphics.top));
  496. SelectObject(WorkDC, hBitmap);
  497. */
  498. HBRUSH hBrush;
  499. RECT rcAll;
  500. // Note we want to paint ALL of the graphics window.
  501. rcAll = rcGraphics;
  502. rcAll.top = 0;
  503. rcAll.left = 0;
  504. // Paint the entire graphics window to the system color
  505. hBrush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
  506. FillRect(WorkDC, &rcAll, hBrush);
  507. DeleteObject(hBrush);
  508. // Fill the dark gray analyze and defrag graphics area
  509. hBrush = CreateSolidBrush(GetSysColor(COLOR_3DSHADOW));
  510. FillRect(WorkDC, &rcAnalyzeDisp, hBrush);
  511. FillRect(WorkDC, &rcDefragDisp, hBrush);
  512. DeleteObject(hBrush);
  513. // edge below the list view is at the very top of this window
  514. //ESIDrawEdge(WorkDC, rcListView.left, 0, rcListView.right, 0);
  515. //DrawEdge(WorkDC, &rcCtlRect, BDR_SUNKENINNER|BDR_RAISEDOUTER, BF_TOP);
  516. DrawEdge(WorkDC, &rcCtlRect, EDGE_BUMP, BF_TOP);
  517. // Draw the sunken box borders around the analyze and defragment grapics displays
  518. DrawBorderEx(WorkDC, rcAnalyzeBorder, SUNKEN_BOX);
  519. DrawBorderEx(WorkDC, rcDefragBorder, SUNKEN_BOX);
  520. // Draw the text above the analyze and defrag displays
  521. SetBkColor(WorkDC, GetSysColor(COLOR_BTNFACE));
  522. SetBkMode(WorkDC, OPAQUE);
  523. SetTextColor(WorkDC, GetSysColor(COLOR_BTNTEXT));
  524. SelectObject(WorkDC, g_hFont);
  525. TCHAR cString[300];
  526. EH_ASSERT(LoadString(hInstRes, IDS_LABEL_ANALYSIS_DISPLAY, cString, sizeof(cString)/sizeof(TCHAR)));
  527. TextOut(WorkDC, rcAnalyzeDisp.left-1, rcAnalyzeDisp.top-20, cString, wcslen(cString));
  528. EH_ASSERT(LoadString(hInstRes, IDS_LABEL_DEFRAG_DISPLAY, cString, sizeof(cString)/sizeof(TCHAR)));
  529. TextOut(WorkDC, rcDefragDisp.left-2, rcDefragDisp.top-20, cString, wcslen(cString));
  530. // If we had an analyze or defrag display then tell the user that we are resizing.
  531. SetBkMode(WorkDC, TRANSPARENT);
  532. // make the text white in all color schemes
  533. SetTextColor(WorkDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
  534. // get the label that appears in the graphics wells
  535. TCHAR defragLabel[300];
  536. TCHAR analyzeLabel[300];
  537. CVolume *pVolume = VolumeList.GetCurrentVolume();
  538. switch (pVolume->DefragState()){
  539. case DEFRAG_STATE_NONE:
  540. wcscpy(analyzeLabel, L"");
  541. wcscpy(defragLabel, L"");
  542. break;
  543. case DEFRAG_STATE_ANALYZING:
  544. EH_ASSERT(LoadString(hInstRes, IDS_LABEL_ANALYZING, analyzeLabel, sizeof(analyzeLabel)/sizeof(TCHAR)));
  545. wcscat(analyzeLabel, L" ");
  546. wcscat(analyzeLabel, pVolume->DisplayLabel());
  547. wcscpy(defragLabel, L"");
  548. break;
  549. case DEFRAG_STATE_ANALYZED:
  550. EH_ASSERT(LoadString(hInstRes, IDS_LABEL_CREATING_COLOR_IMAGE, analyzeLabel, sizeof(analyzeLabel)/sizeof(TCHAR)));
  551. wcscpy(defragLabel, L"");
  552. break;
  553. case DEFRAG_STATE_REANALYZING:
  554. EH_ASSERT(LoadString(hInstRes, IDS_LABEL_REANALYZING, analyzeLabel, sizeof(analyzeLabel)/sizeof(TCHAR)));
  555. wcscat(analyzeLabel, L" ");
  556. wcscat(analyzeLabel, pVolume->DisplayLabel());
  557. wcscpy(defragLabel, L"");
  558. break;
  559. case DEFRAG_STATE_DEFRAGMENTING:
  560. EH_ASSERT(LoadString(hInstRes, IDS_LABEL_RESIZING, analyzeLabel, sizeof(analyzeLabel)/sizeof(TCHAR)));
  561. EH_ASSERT(LoadString(hInstRes, IDS_LABEL_DEFRAGMENTING, defragLabel, sizeof(defragLabel)/sizeof(TCHAR)));
  562. wcscat(defragLabel, L" ");
  563. wcscat(defragLabel, pVolume->DisplayLabel());
  564. break;
  565. case DEFRAG_STATE_DEFRAGMENTED:
  566. EH_ASSERT(LoadString(hInstRes, IDS_LABEL_RESIZING, analyzeLabel, sizeof(analyzeLabel)/sizeof(TCHAR)));
  567. EH_ASSERT(LoadString(hInstRes, IDS_LABEL_RESIZING, defragLabel, sizeof(defragLabel)/sizeof(TCHAR)));
  568. break;
  569. default:
  570. wcscpy(analyzeLabel, L"");
  571. wcscpy(defragLabel, L"");
  572. }
  573. // override the others if the user pressed "Stop"
  574. if (pVolume->StoppedByUser()){
  575. wcscpy(analyzeLabel, L"");
  576. wcscpy(defragLabel, L"");
  577. }
  578. // write the text into the graphic wells
  579. DrawText(WorkDC, analyzeLabel, wcslen(analyzeLabel), &rcAnalyzeDisp, DT_CENTER);
  580. DrawText(WorkDC, defragLabel, wcslen(defragLabel), &rcDefragDisp, DT_CENTER);
  581. ///////////////////////////////////////////////////////////////////////////////////////////////
  582. // Drawing the buttons is accomplished by simply positioning them.
  583. pAnalyzeButton->PaintButton();
  584. pDefragButton->PaintButton();
  585. pPauseButton->PaintButton();
  586. pStopButton->PaintButton();
  587. pReportButton->PaintButton();
  588. /*
  589. EF(BitBlt (OutputDC, rcGraphics.left, rcGraphics.top, rcGraphics.right-rcGraphics.left, rcGraphics.bottom-rcGraphics.top, WorkDC, 0, 0, SRCCOPY));
  590. // Cleanup the bitmap stuff.
  591. DeleteObject(hBitmap);
  592. ReleaseDC(hwndGraphics, WorkDC);
  593. ReleaseDC(hwndGraphics, OutputDC);
  594. */
  595. return TRUE;
  596. }
  597. /*****************************************************************************************************************
  598. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  599. ROUTINE DESCRIPTION:
  600. GLOBAL VARIABLES:
  601. INPUT:
  602. None;
  603. RETURN:
  604. None.
  605. */
  606. void
  607. SetButtonState(void)
  608. {
  609. CVolume *pVolume = VolumeList.GetCurrentVolume();
  610. pAnalyzeButton->ShowButton(SW_SHOW);
  611. pDefragButton->ShowButton(SW_SHOW);
  612. pReportButton->ShowButton(SW_SHOW);
  613. pPauseButton->ShowButton(SW_SHOW);
  614. pStopButton->ShowButton(SW_SHOW);
  615. if (pVolume == (CVolume *) NULL)
  616. return;
  617. // set the pause/resume text correctly
  618. if (pVolume->Paused()){
  619. pPauseButton->SetText(hInstRes, IDS_BTN_RESUME);
  620. }
  621. else {
  622. pPauseButton->SetText(hInstRes, IDS_BTN_PAUSE);
  623. }
  624. if (pVolume->Locked()){ // turn off all buttons if this volume is locked
  625. pAnalyzeButton->EnableButton(FALSE);
  626. pDefragButton->EnableButton(FALSE);
  627. pReportButton->EnableButton(FALSE);
  628. pPauseButton->EnableButton(FALSE);
  629. pStopButton->EnableButton(FALSE);
  630. }
  631. else if (VolumeList.DefragInProcess()){ // one of the volumes is being analyzed/defragged
  632. pAnalyzeButton->EnableButton(FALSE);
  633. pDefragButton->EnableButton(FALSE);
  634. pReportButton->EnableButton(FALSE);
  635. if (pVolume->EngineState() == ENGINE_STATE_RUNNING){ // the selected vol is being analyzed/defragged
  636. pPauseButton->EnableButton(TRUE);
  637. pStopButton->EnableButton(TRUE);
  638. }
  639. else{
  640. pPauseButton->EnableButton(FALSE);
  641. pStopButton->EnableButton(FALSE);
  642. }
  643. }
  644. else{ // neither defrag nor analyze are not running on any volumes
  645. pAnalyzeButton->EnableButton(TRUE);
  646. pDefragButton->EnableButton(TRUE);
  647. pPauseButton->EnableButton(FALSE);
  648. pStopButton->EnableButton(FALSE);
  649. // is the report available for the currently selected volume?
  650. if (pVolume->IsReportOKToDisplay()){
  651. pReportButton->EnableButton(TRUE);
  652. }
  653. else{
  654. pReportButton->EnableButton(FALSE);
  655. }
  656. }
  657. }
  658. /*****************************************************************************************************************
  659. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  660. ROUTINE DESCRIPTION:
  661. GLOBAL VARIABLES:
  662. INPUT:
  663. None;
  664. RETURN:
  665. None.
  666. */
  667. BOOL
  668. DestroyGraphicsWindow(
  669. )
  670. {
  671. if(hwndGraphics != NULL) { DestroyWindow(hwndGraphics); hwndGraphics = NULL; }
  672. if(pAnalyzeButton){
  673. delete pAnalyzeButton;
  674. }
  675. if(pDefragButton){
  676. delete pDefragButton;
  677. }
  678. if(pPauseButton){
  679. delete pPauseButton;
  680. }
  681. if(pStopButton){
  682. delete pStopButton;
  683. }
  684. if(pReportButton){
  685. delete pReportButton;
  686. }
  687. return TRUE;
  688. }