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.

2965 lines
96 KiB

  1. //=============================================================================*
  2. // COPYRIGHT� 2001 Microsoft Corporation and Executive Software International, Inc.
  3. //=============================================================================*
  4. // File: DlgRpt.cpp
  5. //=============================================================================*
  6. #include "stdafx.h"
  7. #ifndef SNAPIN
  8. #ifndef NOWINDOWSH
  9. #include <windows.h>
  10. #endif
  11. #endif
  12. #include "commdlg.h"
  13. #include <commctrl.h>
  14. #include <shlobj.h> // for SHGetSpecialFolderLocation()
  15. #include "DfrgUI.h"
  16. #include "DfrgCmn.h"
  17. #include "DfrgCtl.h"
  18. #include "DlgRpt.h"
  19. #include "GetDfrgRes.h"
  20. #include "DfrgHlp.h"
  21. #include "TextBlock.h"
  22. #include "VolList.h"
  23. #include <locale.h>
  24. #include "expand.h"
  25. #define MAX_FRAGGED_FILE_COLUMNS 3
  26. #define MAX_VOLUME_INFO_COLUMNS 3
  27. static CVolume *pLocalVolume = NULL;
  28. static HFONT hDlgFont;
  29. static RECT rcButtonClose;
  30. static RECT rcButtonDefrag;
  31. static RECT rcButtonSave;
  32. static RECT rcButtonPrint;
  33. static RECT rButton;
  34. static RECT rcOriginalDialogSize;
  35. static RECT rcNewDialogSize;
  36. static UINT minimumDialogWidth;
  37. static UINT minimumDialogHeight;
  38. static UINT maximumDialogWidth;
  39. static UINT maximumDialogHeight;
  40. static UINT totalButtonWidth;
  41. static UINT m_ButtonTopBottomSpacer;
  42. static UINT m_ButtonHeight;
  43. static UINT m_ButtonWidth;
  44. static UINT m_ButtonSpacer;
  45. static UINT m_Margin;
  46. static UINT m_ButtonFloat;
  47. static UINT adjustedButtonWidthClose;
  48. static UINT adjustedButtonWidthDefrag;
  49. static UINT adjustedButtonWidthSave;
  50. static UINT adjustedButtonWidthPrint;
  51. static UINT uEditBoxWidth;
  52. static UINT uEditBoxHeight;
  53. static UINT adjustedButtonHeight;
  54. static UINT wNormalHeight; // height of reduced dialog box (which
  55. // extends just past the ID_MORE button vertically)
  56. static UINT wExpandedHeight; // height of full size dialog box
  57. static BOOL fExpanded = FALSE;
  58. static UINT uFontHeight;
  59. static UINT uVolumeListViewWidth;
  60. //structure for the buttons
  61. typedef struct{
  62. TCHAR m_buttonText[200];
  63. TCHAR m_buttonHelp[200];
  64. BOOL m_buttonVisible;
  65. } GENERICBUTTONARRAY;
  66. static GENERICBUTTONARRAY genericButtonArray[5];
  67. static BOOL
  68. InitializeReport(
  69. IN HWND hWndDialog
  70. );
  71. static BOOL
  72. WriteTextReportInMemory(
  73. CTextBlock &textBlock,
  74. DWORD dwFlags
  75. );
  76. static UINT
  77. WriteTextReportListView(
  78. IN HWND hWndDialog,
  79. IN CTextBlock &textBlock,
  80. IN DWORD dwFlags
  81. );
  82. static void
  83. InitializeFragListView(
  84. IN HWND hWndDialog
  85. );
  86. static void
  87. InitializeVolumeListView(
  88. IN HWND hWndDialog
  89. );
  90. //Prints the text report and most fragged list on a printer.
  91. static BOOL
  92. PrintDriveData(
  93. IN HWND hWndDialog
  94. );
  95. //Saves the text report and most fragged list to a text file.
  96. static BOOL
  97. SaveDriveData(
  98. IN HWND hWndDialog
  99. );
  100. static void
  101. InsertListViewItems(
  102. IN HWND hWndDialog,
  103. CVolume *pLocalVolume
  104. );
  105. static UINT
  106. InsertVolumeListViewItems(
  107. IN HWND hWndDialog, IN UINT iListItemNumber, IN UINT resourceIDText, IN UINT resourceIDSeperator,
  108. IN TCHAR* pTextStr, BOOL bIndentText, UINT uLongestTextString
  109. );
  110. static UINT
  111. InsertVolumeListViewItems(
  112. IN HWND hWndDialog, IN UINT iListItemNumber, IN TCHAR* itemOneText, IN UINT resourceIDSeperator,
  113. IN TCHAR* pTextStr, BOOL bIndentText, UINT uLongestTextString
  114. );
  115. static UINT
  116. InsertVolumeListViewItems(
  117. IN HWND hWndDialog, IN UINT iListItemNumber, IN UINT resourceIDText, IN UINT resourceIDSeperator,
  118. IN TCHAR* pTextStr, IN UINT resourceIDPercent, BOOL bIndentText, UINT uLongestTextString
  119. );
  120. TCHAR*
  121. InsertCommaIntoText(
  122. IN TCHAR* stringBuffer
  123. );
  124. static void
  125. ExitReport(
  126. IN HWND hWndDialog
  127. );
  128. static BOOL CALLBACK
  129. ReportDialogProc(
  130. IN HWND hWndDialog,
  131. IN UINT uMessage,
  132. IN WPARAM wParam,
  133. IN LPARAM lParam
  134. );
  135. //resize stuff
  136. void SetButtonsandIcon(HWND hWndDialog);
  137. void PositionButton(RECT* prcPos, HWND hWndDialog);
  138. void PositionControls(HWND hWndDialog, RECT rDlg);
  139. void GetButtonDimensions(HWND hWndDialog, BOOL bIsAnalysisReport);
  140. void PositionButtons(HWND hWndDialog, RECT rDlg, BOOL bIsAnalysisReport);
  141. UINT GetStringWidth(PTCHAR stringBuf, HDC WorkDC);
  142. void ResizeDialog(HWND hWndDialog);
  143. static UINT FindMaxEditboxStringWidth(VString vstring);
  144. static UINT FindMaxEditboxStringHeight(VString vstring);
  145. static void
  146. ResizeVolumeListViewColumns(
  147. IN HWND hWndDialog, IN UINT uWidthFirstColumn,
  148. IN UINT uWidthSecondColumn, IN UINT uWidthThirdColumn);
  149. // Creates a text report that can be dumped to the screen or file, or printer, etc.
  150. // Passed into CreateTextReportInMemory to tell it what type of report to generate.
  151. #define TEXT_REPORT 1
  152. #define MOST_FRAGGED_REPORT 2
  153. #define NULL_TERMINATE_REPORT 4
  154. #define ASCII_REPORT 8
  155. #define UNICODE_REPORT 16
  156. #define CR_LF_REPORT 32
  157. #define ADD_TABS_REPORT 64
  158. #define PRINT_DEFRAG_TITLE 128
  159. static BOOL
  160. CreateTextReportInMemory(
  161. CTextBlock &textBlock,
  162. DWORD dwFlags = NULL
  163. );
  164. static BOOL
  165. WriteFraggedReportInMemory(
  166. CTextBlock &textBlock,
  167. DWORD dwFlags
  168. );
  169. static BOOL isDescending = TRUE; // used by sort routine
  170. // prototype for the list sort function
  171. static int CALLBACK ListViewCompareFunc(
  172. LPARAM lParam1,
  173. LPARAM lParam2,
  174. LPARAM lParamSort);
  175. LONGLONG checkForNegativeValues(
  176. LONGLONG lldatavalue
  177. );
  178. /*****************************************************************************************************************
  179. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  180. ROUTINE DESCRIPTION:
  181. Raises the Defrag Report dialog
  182. GLOBAL VARIABLES:
  183. None
  184. INPUT:
  185. IN pLocalVolume - address of volume that has just completed Analyzing
  186. RETURN:
  187. TRUE - Worked OK
  188. FALSE - Failure
  189. */
  190. BOOL RaiseReportDialog(
  191. CVolume *pVolume
  192. )
  193. {
  194. LPCTSTR lpTemplateName;
  195. pLocalVolume = pVolume;
  196. isDescending = FALSE;
  197. m_ButtonTopBottomSpacer = 12;
  198. m_ButtonHeight = 26;
  199. m_ButtonWidth = 84;
  200. m_ButtonSpacer = 16;
  201. m_Margin = 20;
  202. m_ButtonFloat = 20;
  203. minimumDialogWidth = 275;
  204. minimumDialogHeight = 330;
  205. // minimumNumberOfCaractersWide = 40;
  206. // minimumNumberOfLinesLong = 2;
  207. if (pLocalVolume->DefragMode() == ANALYZE){
  208. lpTemplateName = MAKEINTRESOURCE(IDD_ANALYSIS_REPORT);
  209. }
  210. else {
  211. lpTemplateName = MAKEINTRESOURCE(IDD_DEFRAG_REPORT);
  212. }
  213. INT_PTR ret = DialogBoxParam(
  214. GetDfrgResHandle(),
  215. lpTemplateName,
  216. pLocalVolume->m_pDfrgCtl->m_hWndCD,
  217. (DLGPROC)ReportDialogProc,
  218. pLocalVolume->DefragMode());
  219. if (ret == -1){
  220. Message(TEXT("RaiseReportDialog - DialogBoxParam"), GetLastError(), TEXT("RaiseReportDialog"));
  221. return FALSE;
  222. }
  223. return TRUE;
  224. }
  225. /********************************************************************
  226. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  227. ROUTINE DESCRIPTION:
  228. The Report dialog callback
  229. GLOBAL VARIABLES:
  230. hFauItems
  231. dwFragListSize
  232. hFragFile
  233. INPUT:
  234. IN HWND hWndDialog, - handle to dialog
  235. IN UINT uMessage, - window message
  236. IN WPARAM wParam, - message flags
  237. IN LPARAM lParam - message flags
  238. RETURN:
  239. TRUE - processed message
  240. FALSE - message not processed.
  241. */
  242. static BOOL CALLBACK
  243. ReportDialogProc(
  244. IN HWND hWndDialog,
  245. IN UINT uMessage,
  246. IN WPARAM wParam,
  247. IN LPARAM lParam
  248. )
  249. {
  250. switch(uMessage) {
  251. case WM_INITDIALOG:
  252. if(!InitializeReport(hWndDialog))
  253. ExitReport(hWndDialog);
  254. SetFocus(GetDlgItem(hWndDialog, IDCANCEL));
  255. return FALSE;
  256. break;
  257. case WM_NOTIFY:
  258. switch (((LPNMHDR) lParam)->code) {
  259. // Process LVN_GETDISPINFO to supply information about callback items.
  260. case LVN_GETDISPINFO:
  261. {
  262. Message(TEXT("ReportDialogProc: LVN_GETDISPINFO"), -1, NULL);
  263. LV_DISPINFO* pnmv = (LV_DISPINFO*)lParam;
  264. // Provide the item or subitem's text, if requested.
  265. if (pnmv->item.mask & LVIF_TEXT) {
  266. CFraggedFile *pFraggedFile = (CFraggedFile *) pnmv->item.lParam;
  267. // copy the text from the array into the list column
  268. switch (pnmv->item.iSubItem)
  269. {
  270. case 0:
  271. _tcsnccpy(pnmv->item.pszText, pFraggedFile->cExtentCount(),
  272. pnmv->item.cchTextMax);
  273. break;
  274. case 1:
  275. _tcsnccpy(pnmv->item.pszText, pFraggedFile->cFileSize(),
  276. pnmv->item.cchTextMax);
  277. break;
  278. case 2:
  279. // if path is too long, truncate it and use elipse
  280. if (pFraggedFile->FileNameLen() >= pnmv->item.cchTextMax) {
  281. _tcsnccpy(pnmv->item.pszText, TEXT("\\..."), pnmv->item.cchTextMax);
  282. _tcsnccat(pnmv->item.pszText,
  283. pFraggedFile->FileNameTruncated(pnmv->item.cchTextMax - 5),
  284. pnmv->item.cchTextMax);
  285. }
  286. // otherwise use full path
  287. else {
  288. _tcsnccpy(pnmv->item.pszText, pFraggedFile->FileName(),
  289. pnmv->item.cchTextMax);
  290. }
  291. break;
  292. }
  293. }
  294. break;
  295. }
  296. // Process LVN_COLUMNCLICK to sort items by column.
  297. case LVN_COLUMNCLICK:
  298. {
  299. Message(TEXT("ReportDialogProc: LVN_COLUMNCLICK"), -1, NULL);
  300. NM_LISTVIEW *pnm = (NM_LISTVIEW *) lParam;
  301. ListView_SortItems(
  302. pnm->hdr.hwndFrom,
  303. ListViewCompareFunc,
  304. (LPARAM) pnm->iSubItem);
  305. isDescending = !isDescending;
  306. break;
  307. }
  308. }
  309. break;
  310. case WM_CLOSE:
  311. ExitReport(hWndDialog);
  312. break;
  313. case WM_COMMAND:
  314. switch(LOWORD(wParam)) {
  315. case IDC_VOLUME_INFORMATION:
  316. {
  317. //
  318. // Don't select all of the text in the edit
  319. // control.
  320. //
  321. if ( HIWORD( wParam ) == EN_SETFOCUS )
  322. SendMessage( (HWND) lParam, EM_SETSEL, 0, 0 );
  323. }
  324. break;
  325. case IDC_PRINT:
  326. PrintDriveData(hWndDialog);
  327. break;
  328. case IDC_SAVE:
  329. SaveDriveData(hWndDialog);
  330. break;
  331. case IDC_DEFRAGMENT:
  332. pLocalVolume->Defragment();
  333. ExitReport(hWndDialog);
  334. break;
  335. case IDCANCEL:
  336. ExitReport(hWndDialog);
  337. break;
  338. case IDHELP:
  339. // WinHelp (hWndDialog, cHelpFileName, HELP_CONTEXT, 65);
  340. break;
  341. default:
  342. return FALSE;
  343. }
  344. break;
  345. case WM_HELP:
  346. switch((int)((LPHELPINFO)lParam)->iCtrlId){
  347. case IDC_EDITBOX_TEXT:
  348. case IDC_VOLUME_INFORMATION_TEXT:
  349. case IDC_MOST_FRAGMENTED_TEXT:
  350. break;
  351. default:
  352. {
  353. HWND hHelpHandle = (HWND)((LPHELPINFO)lParam)->hItemHandle;
  354. DWORD_PTR dwData;
  355. if(pLocalVolume->DefragMode() == ANALYZE){
  356. dwData = (DWORD_PTR) AnalysisRptHelpIDArray;
  357. }
  358. else{
  359. dwData = (DWORD_PTR) DefragRptHelpIDArray;
  360. }
  361. EF(WinHelp(hHelpHandle, GetHelpFilePath(), HELP_WM_HELP, dwData));
  362. break;
  363. }
  364. }
  365. break;
  366. case WM_CONTEXTMENU:
  367. {
  368. switch(GetDlgCtrlID((HWND)wParam)){
  369. case 0:
  370. EH(FALSE);
  371. break;
  372. case IDC_EDITBOX_TEXT:
  373. case IDC_VOLUME_INFORMATION_TEXT:
  374. case IDC_MOST_FRAGMENTED_TEXT:
  375. break;
  376. default:
  377. if(pLocalVolume->DefragMode() == ANALYZE){
  378. EF(WinHelp (hWndDialog, GetHelpFilePath(), HELP_CONTEXTMENU, (DWORD_PTR)AnalysisRptHelpIDArray));
  379. }
  380. else{
  381. EF(WinHelp (hWndDialog, GetHelpFilePath(), HELP_CONTEXTMENU, (DWORD_PTR)DefragRptHelpIDArray));
  382. }
  383. }
  384. }
  385. break;
  386. default:
  387. return FALSE;
  388. }
  389. return TRUE;
  390. }
  391. /****************************************************************************************************************/
  392. // ListViewCompareFunc - sorts the list view control. It is a comparison function.
  393. // Returns a negative value if the first item should precede the
  394. // second item, a positive value if the first item should
  395. // follow the second item, and zero if the items are equivalent.
  396. // lParam1 and lParam2 - pointers to the REPORT_FRAGGED_FILE_DATA struct for that item (row)
  397. // lParamSort - the index of the column to sort
  398. static int CALLBACK ListViewCompareFunc(
  399. LPARAM lParam1,
  400. LPARAM lParam2,
  401. LPARAM lParamSort)
  402. {
  403. LPTSTR lpString1 = NULL, lpString2 = NULL;
  404. LONGLONG number1, number2;
  405. int iResult = 1;
  406. BOOL isNumber = FALSE;
  407. CFraggedFile *pRec1 = (CFraggedFile *)lParam1;
  408. CFraggedFile *pRec2 = (CFraggedFile *)lParam2;
  409. if (pRec1 && pRec2)
  410. {
  411. switch (lParamSort)
  412. {
  413. case 0:
  414. number1 = pRec1->ExtentCount();
  415. number2 = pRec2->ExtentCount();
  416. isNumber = TRUE;
  417. break;
  418. case 1:
  419. number1 = pRec1->FileSize();
  420. number2 = pRec2->FileSize();
  421. isNumber = TRUE;
  422. break;
  423. case 2:
  424. lpString1 = pRec1->FileName();
  425. lpString2 = pRec2->FileName();
  426. isNumber = FALSE;
  427. break;
  428. default:
  429. Message(TEXT("ListViewCompareFunc: Unrecognized column number"), E_FAIL, 0);
  430. break;
  431. }
  432. if (isNumber){
  433. if (number1 < number2)
  434. iResult = -1;
  435. else if (number1 > number2)
  436. iResult = 1;
  437. else
  438. iResult = 0;
  439. }
  440. else{
  441. if (lpString1 && lpString2) {
  442. iResult = lstrcmpi(lpString1, lpString2);
  443. }
  444. }
  445. if (isDescending)
  446. iResult = -iResult;
  447. }
  448. return iResult;
  449. }
  450. /***************************************************************************************************************
  451. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  452. DESCRIPTION:
  453. This function initializes data for the report dialog box
  454. DATA STRUCTURES:
  455. None.
  456. GLOBALS:
  457. hFauItems
  458. hFragFile
  459. dwFragListSize
  460. INPUT:
  461. hWndDialog - handle to the dialog box
  462. RETURN:
  463. None.
  464. */
  465. static BOOL
  466. InitializeReport(
  467. IN HWND hWndDialog
  468. )
  469. {
  470. RECT rDlg;
  471. // set up the font
  472. NONCLIENTMETRICS ncm;
  473. ncm.cbSize = sizeof(ncm);
  474. setlocale(LC_ALL, ".OCP");
  475. //get the maximum size of the screen
  476. maximumDialogWidth = GetSystemMetrics(SM_CXFULLSCREEN);
  477. maximumDialogHeight = GetSystemMetrics(SM_CYFULLSCREEN);
  478. ::SystemParametersInfo (SPI_GETNONCLIENTMETRICS, sizeof (ncm), &ncm, 0);
  479. ncm.lfStatusFont.lfWeight = FW_NORMAL;
  480. InitializeVolumeListView(hWndDialog);
  481. // hDlgFont = ::CreateFontIndirect(&ncm.lfStatusFont);
  482. hDlgFont = ::CreateFontIndirect(&ncm.lfMessageFont);
  483. SendDlgItemMessage(hWndDialog, IDC_EDITBOX_TEXT, WM_SETFONT, (WPARAM) hDlgFont, 0L);
  484. SendDlgItemMessage(hWndDialog, IDC_VOLUME_INFORMATION_TEXT, WM_SETFONT, (WPARAM) hDlgFont, 0L);
  485. SendDlgItemMessage(hWndDialog, IDC_VOLUME_INFORMATION, WM_SETFONT, (WPARAM) hDlgFont, 0L);
  486. SendDlgItemMessage(hWndDialog, IDC_MOST_FRAGMENTED_TEXT, WM_SETFONT, (WPARAM) hDlgFont, 0L);
  487. SendDlgItemMessage(hWndDialog, IDC_MOST_FRAGMENTED, WM_SETFONT, (WPARAM) hDlgFont, 0L);
  488. SendDlgItemMessage(hWndDialog, IDC_PRINT, WM_SETFONT, (WPARAM) hDlgFont, 0L);
  489. SendDlgItemMessage(hWndDialog, IDC_SAVE, WM_SETFONT, (WPARAM) hDlgFont, 0L);
  490. SendDlgItemMessage(hWndDialog, IDCANCEL, WM_SETFONT, (WPARAM) hDlgFont, 0L);
  491. if(pLocalVolume->DefragMode() == ANALYZE)
  492. {
  493. SendDlgItemMessage(hWndDialog, IDC_DEFRAGMENT, WM_SETFONT, (WPARAM) hDlgFont, 0L);
  494. }
  495. // set the title of the dialog box
  496. UINT titleTextID;
  497. if(pLocalVolume->DefragMode() == ANALYZE){
  498. titleTextID = IDS_ANALYSIS_REPORT_TITLE;
  499. // also set the font of the defrag button
  500. //SendDlgItemMessage(hWndDialog, IDC_DEFRAGMENT, WM_SETFONT, (WPARAM) hDlgFont, 0L);
  501. }
  502. else{
  503. titleTextID = IDS_DEFRAG_REPORT_TITLE;
  504. }
  505. VString titleText(titleTextID, GetDfrgResHandle());
  506. EF(SetWindowText(hWndDialog, titleText.GetBuffer()));
  507. CTextBlock textBlock;
  508. // Create a text report in memory that we can dump to the screen.
  509. // EF(CreateTextReportInMemory(textBlock, ADD_TABS_REPORT));
  510. // set the tab stops for the Volume information list view
  511. UINT tabStopArray[3] = {15, 180, 190}; // 1=label, 2=equal sign
  512. // EF(SendDlgItemMessage(hWndDialog, IDC_VOLUME_INFORMATION,
  513. // EM_SETTABSTOPS, (WPARAM) 3, (LPARAM)tabStopArray));
  514. // Write the report to the edit control.
  515. // SetDlgItemText(hWndDialog, IDC_VOLUME_INFORMATION, textBlock.GetBuffer());
  516. InitializeFragListView(hWndDialog);
  517. InsertListViewItems(hWndDialog, pLocalVolume);
  518. //what is the longest string loaded in the volume list view
  519. UINT uLongestTextString = 0;
  520. uLongestTextString = WriteTextReportListView(hWndDialog,textBlock, ADD_TABS_REPORT);
  521. //calulate the Width of the Volume Information Columns and adjust
  522. UINT uWidthFirstColumn = uLongestTextString * uFontHeight / 2;
  523. UINT uWidthSecondColumn = 3 * uFontHeight / 2;
  524. UINT uWidthThirdColumn = 12 * uFontHeight / 2;
  525. uLongestTextString += 15; //add the length of the other two colums max should be 15
  526. UINT uWidthOfVolumeListBox = uLongestTextString * uFontHeight / 2;
  527. ResizeVolumeListViewColumns(hWndDialog, uWidthFirstColumn, uWidthSecondColumn, uWidthThirdColumn);
  528. VString label1;
  529. if(pLocalVolume->DefragMode() == ANALYZE){
  530. // write the Analysis Complete text in the dialog
  531. VString dlgText(IDS_ANALYSIS_COMPLETE_FOR, GetDfrgResHandle());
  532. dlgText.AddChar(L' ');
  533. dlgText += pLocalVolume->DisplayLabel();
  534. dlgText.AddChar(L'\r');
  535. dlgText.AddChar(L'\n');
  536. if((pLocalVolume->m_TextData.PercentDiskFragged + pLocalVolume->m_TextData.FreeSpaceFragPercent) / 2 > 10){
  537. //If the fragmentation on the disk exceeds 10% fragmentation, then recommend defragging.
  538. label1.LoadString(IDS_LABEL_CHOOSE_DEFRAGMENT, GetDfrgResHandle());
  539. }
  540. else{
  541. //Otherwise tell the user he doesn't need to defragment at this time.
  542. label1.LoadString(IDS_LABEL_NO_CHOOSE_DEFRAGMENT, GetDfrgResHandle());
  543. }
  544. dlgText += label1;
  545. EF(SetDlgItemText(hWndDialog, IDC_EDITBOX_TEXT, dlgText.GetBuffer()));
  546. }
  547. else{
  548. TCHAR cString[200];
  549. label1.LoadString(IDS_DEFRAG_REPORT_FOR, GetDfrgResHandle());
  550. wsprintf(cString, TEXT("%s %s"),
  551. label1.GetBuffer(),
  552. pLocalVolume->DisplayLabel());
  553. EF(SetDlgItemText(hWndDialog, IDC_EDITBOX_TEXT, cString));
  554. SetFocus(GetDlgItem(hWndDialog, IDCANCEL));
  555. }
  556. //I have created the dialog, now it is time to make the size correct
  557. //I am sizing it by calculating the size of the volume information listview
  558. //and the size of the buttons and comparing that to the default size and taking
  559. //the largest value.
  560. //first calculate the list view width
  561. uFontHeight = -ncm.lfMessageFont.lfHeight;
  562. uVolumeListViewWidth = uLongestTextString * uFontHeight / 2; //the width of the list view in pixels
  563. //second calculate the width of the buttons
  564. if(pLocalVolume->DefragMode() == ANALYZE)
  565. {
  566. GetButtonDimensions(hWndDialog, TRUE);
  567. } else
  568. {
  569. GetButtonDimensions(hWndDialog, FALSE);
  570. }
  571. //now decide which one is bigger
  572. if(minimumDialogWidth < totalButtonWidth)
  573. {
  574. minimumDialogWidth = totalButtonWidth;
  575. }
  576. if(minimumDialogWidth < uVolumeListViewWidth)
  577. {
  578. minimumDialogWidth = uVolumeListViewWidth;
  579. }
  580. //calculate the final Height and Width of things
  581. //now we can move everything around and make it look cool...
  582. GetWindowRect(hWndDialog, &rDlg);
  583. //calculate to final size of the dialog and adjust if necessary
  584. UINT dialogBoxFinalWidth = rDlg.right - rDlg.left;// + 3 * m_Margin + iconSize;
  585. minimumDialogHeight = (16 * dialogBoxFinalWidth) /10;
  586. UINT dialogBoxFinalHeight = rDlg.bottom - rDlg.top;
  587. dialogBoxFinalWidth = __max(dialogBoxFinalWidth,minimumDialogWidth);
  588. dialogBoxFinalHeight = __max(dialogBoxFinalHeight,minimumDialogHeight);
  589. //check to see if the dialogBoxFinalWidth/Height is greater than the screen and adjust
  590. dialogBoxFinalWidth = __min(dialogBoxFinalWidth,maximumDialogWidth);
  591. dialogBoxFinalHeight = __min(dialogBoxFinalHeight,maximumDialogHeight);
  592. //resize the dialog by moving it to make sure that the minimum size is used if necessary
  593. MoveWindow(hWndDialog,rDlg.left,rDlg.top,dialogBoxFinalWidth,dialogBoxFinalHeight, TRUE);
  594. GetWindowRect(hWndDialog, &rDlg);
  595. UINT iNumberofLinesLong = 0;
  596. UINT iNumberofCharactersWide = 0;
  597. //adjust the size of the edit box IDC_EDITBOX_TEXT
  598. TCHAR dlgText[256];
  599. VString dlgString;
  600. GetDlgItemText(hWndDialog, IDC_EDITBOX_TEXT, dlgText, 256);
  601. dlgString += dlgText;
  602. iNumberofCharactersWide = FindMaxEditboxStringWidth(dlgString);
  603. uEditBoxWidth = rDlg.right - rDlg.left - (2 * m_Margin); //if no characters make it the total width
  604. if(iNumberofCharactersWide == 0)
  605. {
  606. iNumberofLinesLong = 1; //and put one line in it
  607. } else
  608. {
  609. iNumberofCharactersWide +=5; //add little extra space
  610. iNumberofLinesLong = FindMaxEditboxStringHeight(dlgString);
  611. }
  612. uEditBoxHeight = (iNumberofLinesLong * uFontHeight * 15) / 10; //the height of editbox in pixels
  613. UINT uHeightOfFont = (uFontHeight * 15) / 10;
  614. UINT uCurrentVerticalSpaceLocation = 0;
  615. //resize the edit box
  616. MoveWindow(GetDlgItem(hWndDialog, IDC_EDITBOX_TEXT), m_Margin, m_ButtonTopBottomSpacer, uEditBoxWidth, uEditBoxHeight, TRUE);
  617. uCurrentVerticalSpaceLocation += m_ButtonTopBottomSpacer + uEditBoxHeight + 5;
  618. //move the dividing line
  619. MoveWindow(GetDlgItem(hWndDialog, IDC_DIVIDE_LINE), m_Margin, uCurrentVerticalSpaceLocation, rDlg.right - rDlg.left - (2 * m_Margin), 2, TRUE);
  620. uCurrentVerticalSpaceLocation += m_ButtonTopBottomSpacer + 2;
  621. //move the Volume Information Text
  622. GetWindowRect(GetDlgItem(hWndDialog, IDC_VOLUME_INFORMATION_TEXT),&rDlg);
  623. MoveWindow(GetDlgItem(hWndDialog, IDC_VOLUME_INFORMATION_TEXT), m_Margin, uCurrentVerticalSpaceLocation, uEditBoxWidth, uHeightOfFont, TRUE);
  624. uCurrentVerticalSpaceLocation += m_ButtonTopBottomSpacer + uHeightOfFont;
  625. //move and resize the Volume Information
  626. GetWindowRect(GetDlgItem(hWndDialog, IDC_VOLUME_INFORMATION),&rDlg);
  627. MoveWindow(GetDlgItem(hWndDialog, IDC_VOLUME_INFORMATION), m_Margin, uCurrentVerticalSpaceLocation, dialogBoxFinalWidth - (2 * m_Margin), ((dialogBoxFinalHeight - (2 * m_Margin)) / 6) , TRUE);
  628. uCurrentVerticalSpaceLocation += m_ButtonTopBottomSpacer + ((dialogBoxFinalHeight - (2 * m_Margin)) / 6);
  629. //move the Most Fragmented Information Text
  630. GetWindowRect(GetDlgItem(hWndDialog, IDC_MOST_FRAGMENTED_TEXT),&rDlg);
  631. MoveWindow(GetDlgItem(hWndDialog, IDC_MOST_FRAGMENTED_TEXT), m_Margin, uCurrentVerticalSpaceLocation, uEditBoxWidth, uHeightOfFont, TRUE);
  632. uCurrentVerticalSpaceLocation += m_ButtonTopBottomSpacer + uHeightOfFont;
  633. //move the Most Fragmented Information
  634. GetWindowRect(GetDlgItem(hWndDialog, IDC_MOST_FRAGMENTED),&rDlg);
  635. MoveWindow(GetDlgItem(hWndDialog, IDC_MOST_FRAGMENTED), m_Margin, uCurrentVerticalSpaceLocation, dialogBoxFinalWidth - (2 * m_Margin), ((dialogBoxFinalHeight - (2 * m_Margin)) / 4), TRUE);
  636. uCurrentVerticalSpaceLocation += m_ButtonTopBottomSpacer + ((dialogBoxFinalHeight - (2 * m_Margin)) / 4);
  637. //calculate the new dialogBoxFinalHeight based on the size of the controls
  638. //don't forget the title bar estimated to be (2 * uHeightOfFont)
  639. dialogBoxFinalHeight = //__min((UINT)dialogBoxFinalHeight,
  640. uCurrentVerticalSpaceLocation + (2 * uHeightOfFont) + (2 * m_ButtonTopBottomSpacer) + m_ButtonHeight;
  641. //resize the dialog box
  642. GetWindowRect(hWndDialog,&rDlg);
  643. MoveWindow(hWndDialog,rDlg.left,rDlg.top,dialogBoxFinalWidth,dialogBoxFinalHeight, TRUE);
  644. GetWindowRect(hWndDialog,&rDlg);
  645. if(pLocalVolume->DefragMode() == ANALYZE)
  646. {
  647. PositionButtons(hWndDialog, rDlg, TRUE);
  648. } else
  649. {
  650. PositionButtons(hWndDialog, rDlg, FALSE);
  651. }
  652. return TRUE;
  653. }
  654. /***************************************************************************************************************
  655. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  656. DESCRIPTION:
  657. This will write a report telling how many fragmented files are on the drive, etc., into a memory buffer.
  658. DATA STRUCTURES:
  659. None.
  660. GLOBALS:
  661. INPUT:
  662. hText - The handle to the memory to write the report to.
  663. pText - A pointer to the same.
  664. pTextEnd - A pointer to the end of the buffer.
  665. dwFlags - Contains flags specifying how to generate the report, (unicode vs. ascii, and cr lf instead of newline.)
  666. RETURN:
  667. TRUE - Success.
  668. FALSE - Fatal error.
  669. */
  670. static BOOL
  671. WriteTextReportInMemory(
  672. CTextBlock &textBlock,
  673. DWORD dwFlags
  674. )
  675. {
  676. setlocale(LC_ALL, ".OCP");
  677. // Get a pointer to the text data structure.
  678. TEXT_DATA *pTextData = &(pLocalVolume->m_TextData);
  679. // check all the values of textdata to make sure no negative values
  680. //to fix bug number 35764
  681. pTextData->DiskSize = checkForNegativeValues(pTextData->DiskSize);
  682. pTextData->BytesPerCluster = checkForNegativeValues(pTextData->BytesPerCluster);
  683. pTextData->UsedSpace = checkForNegativeValues(pTextData->UsedSpace);
  684. pTextData->FreeSpace = checkForNegativeValues(pTextData->FreeSpace);
  685. pTextData->FreeSpacePercent = checkForNegativeValues(pTextData->FreeSpacePercent);
  686. pTextData->UsableFreeSpace = checkForNegativeValues(pTextData->UsableFreeSpace);
  687. pTextData->UsableFreeSpacePercent = checkForNegativeValues(pTextData->UsableFreeSpacePercent);
  688. pTextData->PagefileBytes = checkForNegativeValues(pTextData->PagefileBytes);
  689. pTextData->PagefileFrags = checkForNegativeValues(pTextData->PagefileFrags);
  690. pTextData->TotalDirectories = checkForNegativeValues(pTextData->TotalDirectories);
  691. pTextData->FragmentedDirectories = checkForNegativeValues(pTextData->FragmentedDirectories);
  692. pTextData->ExcessDirFrags = checkForNegativeValues(pTextData->ExcessDirFrags);
  693. pTextData->TotalFiles = checkForNegativeValues(pTextData->TotalFiles);
  694. pTextData->AvgFileSize = checkForNegativeValues(pTextData->AvgFileSize);
  695. pTextData->NumFraggedFiles = checkForNegativeValues(pTextData->NumFraggedFiles);
  696. pTextData->NumExcessFrags = checkForNegativeValues(pTextData->NumExcessFrags);
  697. pTextData->PercentDiskFragged = checkForNegativeValues(pTextData->PercentDiskFragged);
  698. pTextData->AvgFragsPerFile = checkForNegativeValues(pTextData->AvgFragsPerFile);
  699. pTextData->MFTBytes = checkForNegativeValues(pTextData->MFTBytes);
  700. pTextData->InUseMFTRecords = checkForNegativeValues(pTextData->InUseMFTRecords);
  701. pTextData->TotalMFTRecords = checkForNegativeValues(pTextData->TotalMFTRecords);
  702. pTextData->MFTExtents = checkForNegativeValues(pTextData->MFTExtents);
  703. pTextData->FreeSpaceFragPercent = checkForNegativeValues(pTextData->FreeSpaceFragPercent);
  704. // set up the text block
  705. textBlock.SetResourceHandle(GetDfrgResHandle());
  706. // if no tabs, then set the fixed columns
  707. if (dwFlags & ADD_TABS_REPORT){
  708. textBlock.SetUseTabs(TRUE);
  709. }
  710. else{
  711. textBlock.SetFixedColumnWidth(TRUE);
  712. textBlock.SetColumnCount(5);
  713. textBlock.SetColumnWidth(0, 4); // spacer
  714. textBlock.SetColumnWidth(1, 43); // label
  715. textBlock.SetColumnWidth(2, 2); // equal sign
  716. textBlock.SetColumnWidth(3, 1); // data
  717. textBlock.SetColumnWidth(4, 2); // percent sign
  718. }
  719. textBlock.SetUseCRLF(TRUE);
  720. // print the title
  721. if (dwFlags & PRINT_DEFRAG_TITLE){
  722. textBlock.WriteToBuffer(IDS_PRODUCT_NAME);
  723. textBlock.EndOfLine();
  724. textBlock.EndOfLine();
  725. }
  726. // write out the display label (usually the drive letter/label)
  727. textBlock.WriteToBuffer(IDS_LABEL_VOLUME);
  728. textBlock.WriteToBuffer(L" %s", pLocalVolume->DisplayLabel());
  729. textBlock.EndOfLine();
  730. // if there are >1 mount points, print them all out
  731. // yes, this will duplicate the same as the display label
  732. // refresh the mount point list
  733. #ifndef VER4
  734. pLocalVolume->GetVolumeMountPointList();
  735. if (pLocalVolume->MountPointCount() > 1){
  736. for (UINT i=0; i<pLocalVolume->MountPointCount(); i++){
  737. textBlock.WriteToBuffer(IDS_MOUNTED_VOLUME);
  738. textBlock.WriteToBuffer(L": %s", pLocalVolume->MountPoint(i));
  739. textBlock.EndOfLine();
  740. }
  741. }
  742. #endif
  743. ///////////////////////////////////////////////////////////////////////////
  744. // Volume Size
  745. textBlock.WriteToBuffer(L"");
  746. textBlock.WriteTab();
  747. textBlock.WriteToBuffer(IDS_LABEL_VOLUME_SIZE);
  748. textBlock.WriteTab();
  749. textBlock.WriteToBuffer(IDS_LABEL_EQUAL_SIGN);
  750. textBlock.WriteTab();
  751. textBlock.WriteByteCount(pTextData->DiskSize);
  752. textBlock.EndOfLine();
  753. // Cluster Size
  754. textBlock.WriteToBuffer(L"");
  755. textBlock.WriteTab();
  756. textBlock.WriteToBuffer(IDS_LABEL_CLUSTER_SIZE);
  757. textBlock.WriteTab();
  758. textBlock.WriteToBuffer(IDS_LABEL_EQUAL_SIGN);
  759. textBlock.WriteTab();
  760. textBlock.WriteByteCount(pTextData->BytesPerCluster);
  761. textBlock.EndOfLine();
  762. // Used Space
  763. textBlock.WriteToBuffer(L"");
  764. textBlock.WriteTab();
  765. textBlock.WriteToBuffer(IDS_LABEL_USED_SPACE);
  766. textBlock.WriteTab();
  767. textBlock.WriteToBuffer(IDS_LABEL_EQUAL_SIGN);
  768. textBlock.WriteTab();
  769. textBlock.WriteByteCount(pTextData->UsedSpace);
  770. textBlock.EndOfLine();
  771. // Free Space
  772. textBlock.WriteToBuffer(L"");
  773. textBlock.WriteTab();
  774. textBlock.WriteToBuffer(IDS_LABEL_FREE_SPACE);
  775. textBlock.WriteTab();
  776. textBlock.WriteToBuffer(IDS_LABEL_EQUAL_SIGN);
  777. textBlock.WriteTab();
  778. textBlock.WriteByteCount(pTextData->FreeSpace);
  779. textBlock.EndOfLine();
  780. // % Free Space
  781. textBlock.WriteToBuffer(L"");
  782. textBlock.WriteTab();
  783. textBlock.WriteToBuffer(IDS_LABEL_PERCENT_FREE_SPACE);
  784. textBlock.WriteTab();
  785. textBlock.WriteToBuffer(IDS_LABEL_EQUAL_SIGN);
  786. textBlock.WriteTab();
  787. textBlock.WriteToBuffer(L"%d ", (UINT) pTextData->FreeSpacePercent);
  788. textBlock.WriteToBuffer(IDS_LABEL_PERCENT_SIGN);
  789. textBlock.EndOfLine();
  790. // Volume Fragmentation Header
  791. textBlock.EndOfLine();
  792. textBlock.WriteToBuffer(IDS_LABEL_VOLUME_FRAGMENTATION_HEADING);
  793. textBlock.EndOfLine();
  794. // % Total Fragmentation
  795. textBlock.WriteToBuffer(L"");
  796. textBlock.WriteTab();
  797. textBlock.WriteToBuffer(IDS_LABEL_TOTAL_FRAGMENTATION);
  798. textBlock.WriteTab();
  799. textBlock.WriteToBuffer(IDS_LABEL_EQUAL_SIGN);
  800. textBlock.WriteTab();
  801. textBlock.WriteToBuffer(L"%d ", (UINT) (pTextData->PercentDiskFragged + pTextData->FreeSpaceFragPercent) / 2);
  802. textBlock.WriteToBuffer(IDS_LABEL_PERCENT_SIGN);
  803. textBlock.EndOfLine();
  804. // % File Fragmentation
  805. textBlock.WriteToBuffer(L"");
  806. textBlock.WriteTab();
  807. textBlock.WriteToBuffer(IDS_LABEL_FILE_FRAGMENTATION);
  808. textBlock.WriteTab();
  809. textBlock.WriteToBuffer(IDS_LABEL_EQUAL_SIGN);
  810. textBlock.WriteTab();
  811. textBlock.WriteToBuffer(L"%d ", (UINT) pTextData->PercentDiskFragged);
  812. textBlock.WriteToBuffer(IDS_LABEL_PERCENT_SIGN);
  813. textBlock.EndOfLine();
  814. // % Free Space Fragmentation
  815. textBlock.WriteToBuffer(L"");
  816. textBlock.WriteTab();
  817. textBlock.WriteToBuffer(IDS_LABEL_FREE_SPACE_FRAGMENTATION);
  818. textBlock.WriteTab();
  819. textBlock.WriteToBuffer(IDS_LABEL_EQUAL_SIGN);
  820. textBlock.WriteTab();
  821. textBlock.WriteToBuffer(L"%d ", (UINT) pTextData->FreeSpaceFragPercent);
  822. textBlock.WriteToBuffer(IDS_LABEL_PERCENT_SIGN);
  823. textBlock.EndOfLine();
  824. // File Fragmentation Header
  825. textBlock.EndOfLine();
  826. textBlock.WriteToBuffer(IDS_LABEL_FILE_FRAGMENTATION_HEADING);
  827. textBlock.EndOfLine();
  828. // Total Files
  829. textBlock.WriteToBuffer(L"");
  830. textBlock.WriteTab();
  831. textBlock.WriteToBuffer(IDS_LABEL_TOTAL_FILES);
  832. textBlock.WriteTab();
  833. textBlock.WriteToBuffer(IDS_LABEL_EQUAL_SIGN);
  834. textBlock.WriteTab();
  835. //textBlock.WriteToBuffer(L"%d", pTextData->TotalFiles);
  836. textBlock.WriteToBufferLL(pTextData->TotalFiles);
  837. textBlock.EndOfLine();
  838. // Average Files Size
  839. textBlock.WriteToBuffer(L"");
  840. textBlock.WriteTab();
  841. textBlock.WriteToBuffer(IDS_LABEL_AVERAGE_FILE_SIZE);
  842. textBlock.WriteTab();
  843. textBlock.WriteToBuffer(IDS_LABEL_EQUAL_SIGN);
  844. textBlock.WriteTab();
  845. textBlock.WriteByteCount(pTextData->AvgFileSize);
  846. textBlock.EndOfLine();
  847. // Total fragmented files
  848. textBlock.WriteToBuffer(L"");
  849. textBlock.WriteTab();
  850. textBlock.WriteToBuffer(IDS_LABEL_TOTAL_FRAGMENTED_FILES);
  851. textBlock.WriteTab();
  852. textBlock.WriteToBuffer(IDS_LABEL_EQUAL_SIGN);
  853. textBlock.WriteTab();
  854. //textBlock.WriteToBuffer(L"%d", pTextData->NumFraggedFiles);
  855. textBlock.WriteToBufferLL(pTextData->NumFraggedFiles);
  856. textBlock.EndOfLine();
  857. // Total excess fragments
  858. textBlock.WriteToBuffer(L"");
  859. textBlock.WriteTab();
  860. textBlock.WriteToBuffer(IDS_LABEL_TOTAL_EXCESS_FRAGMENTS);
  861. textBlock.WriteTab();
  862. textBlock.WriteToBuffer(IDS_LABEL_EQUAL_SIGN);
  863. textBlock.WriteTab();
  864. //textBlock.WriteToBuffer(L"%d", pTextData->NumExcessFrags);
  865. textBlock.WriteToBufferLL(pTextData->NumExcessFrags);
  866. textBlock.EndOfLine();
  867. // Average Fragments per File (CHECK THE MATH AND THE UNITS ON THIS ONE!!!)
  868. struct lconv *locals = localeconv();
  869. textBlock.WriteToBuffer(L"");
  870. textBlock.WriteTab();
  871. textBlock.WriteToBuffer(IDS_LABEL_AVERAGE_FRAGMENTS_PER_FILE);
  872. textBlock.WriteTab();
  873. textBlock.WriteToBuffer(IDS_LABEL_EQUAL_SIGN);
  874. textBlock.WriteTab();
  875. textBlock.WriteToBuffer(L"%d%c%02d",
  876. (UINT)pTextData->AvgFragsPerFile/100,
  877. ((locals && (locals->decimal_point)) ? *(locals->decimal_point) : '.'),
  878. (UINT)pTextData->AvgFragsPerFile%100);
  879. textBlock.EndOfLine();
  880. // Pagefile Fragmentation Header
  881. textBlock.EndOfLine();
  882. textBlock.WriteToBuffer(IDS_LABEL_PAGEFILE_FRAGMENTATION_HEADING);
  883. textBlock.EndOfLine();
  884. // Pagefile Size
  885. textBlock.WriteToBuffer(L"");
  886. textBlock.WriteTab();
  887. textBlock.WriteToBuffer(IDS_LABEL_PAGEFILE_SIZE);
  888. textBlock.WriteTab();
  889. textBlock.WriteToBuffer(IDS_LABEL_EQUAL_SIGN);
  890. textBlock.WriteTab();
  891. textBlock.WriteByteCount(pTextData->PagefileBytes);
  892. textBlock.EndOfLine();
  893. // Total Fragments
  894. textBlock.WriteToBuffer(L"");
  895. textBlock.WriteTab();
  896. textBlock.WriteToBuffer(IDS_LABEL_TOTAL_FRAGMENTS);
  897. textBlock.WriteTab();
  898. textBlock.WriteToBuffer(IDS_LABEL_EQUAL_SIGN);
  899. textBlock.WriteTab();
  900. //textBlock.WriteToBuffer(L"%d", pTextData->PagefileFrags);
  901. textBlock.WriteToBufferLL(pTextData->PagefileFrags);
  902. textBlock.EndOfLine();
  903. // Directory Fragmentation Header
  904. textBlock.EndOfLine();
  905. textBlock.WriteToBuffer(IDS_LABEL_DIRECTORY_FRAGMENTATION_HEADING);
  906. textBlock.EndOfLine();
  907. // Total Directories
  908. textBlock.WriteToBuffer(L"");
  909. textBlock.WriteTab();
  910. textBlock.WriteToBuffer(IDS_LABEL_TOTAL_DIRECTORIES);
  911. textBlock.WriteTab();
  912. textBlock.WriteToBuffer(IDS_LABEL_EQUAL_SIGN);
  913. textBlock.WriteTab();
  914. //textBlock.WriteToBuffer(L"%d", pTextData->TotalDirectories);
  915. textBlock.WriteToBufferLL(pTextData->TotalDirectories);
  916. textBlock.EndOfLine();
  917. // Fragmented Directories
  918. textBlock.WriteToBuffer(L"");
  919. textBlock.WriteTab();
  920. textBlock.WriteToBuffer(IDS_LABEL_FRAGMENTED_DIRECTORIES);
  921. textBlock.WriteTab();
  922. textBlock.WriteToBuffer(IDS_LABEL_EQUAL_SIGN);
  923. textBlock.WriteTab();
  924. //textBlock.WriteToBuffer(L"%d", pTextData->FragmentedDirectories);
  925. textBlock.WriteToBufferLL(pTextData->FragmentedDirectories);
  926. textBlock.EndOfLine();
  927. // Excess directory fragments
  928. textBlock.WriteToBuffer(L"");
  929. textBlock.WriteTab();
  930. textBlock.WriteToBuffer(IDS_LABEL_EXCESS_DIRECTORY_FRAGMENTS);
  931. textBlock.WriteTab();
  932. textBlock.WriteToBuffer(IDS_LABEL_EQUAL_SIGN);
  933. textBlock.WriteTab();
  934. //textBlock.WriteToBuffer(L"%d", pTextData->ExcessDirFrags);
  935. textBlock.WriteToBufferLL(pTextData->ExcessDirFrags);
  936. textBlock.EndOfLine();
  937. //Only display MFT data if this is an NTFS drive.
  938. if(wcscmp(pLocalVolume->FileSystem(), L"NTFS") == 0){
  939. // MFT Fragmentation Header
  940. textBlock.EndOfLine();
  941. textBlock.WriteToBuffer(IDS_LABEL_MFT_FRAGMENTATION_HEADING);
  942. textBlock.EndOfLine();
  943. // Total MFT Size
  944. textBlock.WriteToBuffer(L"");
  945. textBlock.WriteTab();
  946. textBlock.WriteToBuffer(IDS_LABEL_TOTAL_MFT_SIZE);
  947. textBlock.WriteTab();
  948. textBlock.WriteToBuffer(IDS_LABEL_EQUAL_SIGN);
  949. textBlock.WriteTab();
  950. textBlock.WriteByteCount(pTextData->MFTBytes);
  951. textBlock.EndOfLine();
  952. // Number of MFT records
  953. textBlock.WriteToBuffer(L"");
  954. textBlock.WriteTab();
  955. textBlock.WriteToBuffer(IDS_LABEL_MFT_RECORD_COUNT);
  956. textBlock.WriteTab();
  957. textBlock.WriteToBuffer(IDS_LABEL_EQUAL_SIGN);
  958. textBlock.WriteTab();
  959. textBlock.WriteToBufferLL(pTextData->InUseMFTRecords);
  960. textBlock.EndOfLine();
  961. // Percent of MFT in use
  962. textBlock.WriteToBuffer(L"");
  963. textBlock.WriteTab();
  964. textBlock.WriteToBuffer(IDS_LABEL_PERCENT_MFT_IN_USE);
  965. textBlock.WriteTab();
  966. textBlock.WriteToBuffer(IDS_LABEL_EQUAL_SIGN);
  967. textBlock.WriteTab();
  968. textBlock.WriteToBuffer(L"%d ", (UINT) (100*pTextData->InUseMFTRecords/pTextData->TotalMFTRecords));
  969. textBlock.WriteToBuffer(IDS_LABEL_PERCENT_SIGN);
  970. textBlock.EndOfLine();
  971. // Total MFT fragments
  972. textBlock.WriteToBuffer(L"");
  973. textBlock.WriteTab();
  974. textBlock.WriteToBuffer(IDS_LABEL_TOTAL_MFT_FRAGMENTS);
  975. textBlock.WriteTab();
  976. textBlock.WriteToBuffer(IDS_LABEL_EQUAL_SIGN);
  977. textBlock.WriteTab();
  978. textBlock.WriteToBufferLL(pTextData->MFTExtents);
  979. textBlock.EndOfLine();
  980. }
  981. return TRUE;
  982. }
  983. static UINT
  984. WriteTextReportListView(
  985. IN HWND hWndDialog,
  986. IN CTextBlock &textBlock,
  987. IN DWORD dwFlags
  988. )
  989. {
  990. // Get a pointer to the text data structure.
  991. TEXT_DATA *pTextData = &(pLocalVolume->m_TextData);
  992. TCHAR buffer[256];
  993. TCHAR tempBuffer[256];
  994. UINT uIndexofListView = 0;
  995. //what is the longest string loaded in the volume list view
  996. UINT uLongestTextString = 0;
  997. // check all the values of textdata to make sure no negative values
  998. //to fix bug number 35764
  999. pTextData->DiskSize = checkForNegativeValues(pTextData->DiskSize);
  1000. pTextData->BytesPerCluster = checkForNegativeValues(pTextData->BytesPerCluster);
  1001. pTextData->UsedSpace = checkForNegativeValues(pTextData->UsedSpace);
  1002. pTextData->FreeSpace = checkForNegativeValues(pTextData->FreeSpace);
  1003. pTextData->FreeSpacePercent = checkForNegativeValues(pTextData->FreeSpacePercent);
  1004. pTextData->UsableFreeSpace = checkForNegativeValues(pTextData->UsableFreeSpace);
  1005. pTextData->UsableFreeSpacePercent = checkForNegativeValues(pTextData->UsableFreeSpacePercent);
  1006. pTextData->PagefileBytes = checkForNegativeValues(pTextData->PagefileBytes);
  1007. pTextData->PagefileFrags = checkForNegativeValues(pTextData->PagefileFrags);
  1008. pTextData->TotalDirectories = checkForNegativeValues(pTextData->TotalDirectories);
  1009. pTextData->FragmentedDirectories = checkForNegativeValues(pTextData->FragmentedDirectories);
  1010. pTextData->ExcessDirFrags = checkForNegativeValues(pTextData->ExcessDirFrags);
  1011. pTextData->TotalFiles = checkForNegativeValues(pTextData->TotalFiles);
  1012. pTextData->AvgFileSize = checkForNegativeValues(pTextData->AvgFileSize);
  1013. pTextData->NumFraggedFiles = checkForNegativeValues(pTextData->NumFraggedFiles);
  1014. pTextData->NumExcessFrags = checkForNegativeValues(pTextData->NumExcessFrags);
  1015. pTextData->PercentDiskFragged = checkForNegativeValues(pTextData->PercentDiskFragged);
  1016. pTextData->AvgFragsPerFile = checkForNegativeValues(pTextData->AvgFragsPerFile);
  1017. pTextData->MFTBytes = checkForNegativeValues(pTextData->MFTBytes);
  1018. pTextData->InUseMFTRecords = checkForNegativeValues(pTextData->InUseMFTRecords);
  1019. pTextData->TotalMFTRecords = checkForNegativeValues(pTextData->TotalMFTRecords);
  1020. pTextData->MFTExtents = checkForNegativeValues(pTextData->MFTExtents);
  1021. pTextData->FreeSpaceFragPercent = checkForNegativeValues(pTextData->FreeSpaceFragPercent);
  1022. //Only display MFT data if this is an NTFS drive.
  1023. if(wcscmp(pLocalVolume->FileSystem(), L"NTFS") == 0)
  1024. {
  1025. // Total MFT fragments
  1026. swprintf(buffer, L"%I64d", pTextData->MFTExtents);
  1027. uLongestTextString = InsertVolumeListViewItems(hWndDialog,uIndexofListView,IDS_LABEL_TOTAL_MFT_FRAGMENTS,
  1028. IDS_LABEL_EQUAL_SIGN,InsertCommaIntoText(buffer),TRUE,uLongestTextString);
  1029. uIndexofListView++;
  1030. // Percent of MFT in use
  1031. swprintf(buffer, L"%d", 100*pTextData->InUseMFTRecords/pTextData->TotalMFTRecords);
  1032. uLongestTextString = InsertVolumeListViewItems(hWndDialog,uIndexofListView,IDS_LABEL_PERCENT_MFT_IN_USE,
  1033. IDS_LABEL_EQUAL_SIGN,buffer,TRUE,uLongestTextString);
  1034. uIndexofListView++;
  1035. // Number of MFT records
  1036. swprintf(buffer, L"%I64d", pTextData->InUseMFTRecords);
  1037. uLongestTextString = InsertVolumeListViewItems(hWndDialog,uIndexofListView,IDS_LABEL_MFT_RECORD_COUNT,
  1038. IDS_LABEL_EQUAL_SIGN,InsertCommaIntoText(buffer),TRUE,uLongestTextString);
  1039. uIndexofListView++;
  1040. // Total MFT Size
  1041. swprintf(buffer, L"%I64d", pTextData->MFTBytes);
  1042. InsertCommaIntoText(buffer);
  1043. textBlock.FormatNum(GetDfrgResHandle(), pTextData->MFTBytes, buffer);
  1044. uLongestTextString = InsertVolumeListViewItems(hWndDialog,uIndexofListView,IDS_LABEL_TOTAL_MFT_SIZE,
  1045. IDS_LABEL_EQUAL_SIGN,buffer,TRUE,uLongestTextString);
  1046. uIndexofListView++;
  1047. // MFT Fragmentation Header
  1048. uLongestTextString = InsertVolumeListViewItems(hWndDialog,uIndexofListView,IDS_LABEL_MFT_FRAGMENTATION_HEADING,
  1049. NULL,L"",FALSE,uLongestTextString);
  1050. uIndexofListView++;
  1051. }
  1052. // Excess directory fragments
  1053. swprintf(buffer, L"%I64d", pTextData->ExcessDirFrags);
  1054. uLongestTextString = InsertVolumeListViewItems(hWndDialog,uIndexofListView,IDS_LABEL_EXCESS_DIRECTORY_FRAGMENTS,
  1055. IDS_LABEL_EQUAL_SIGN,InsertCommaIntoText(buffer),TRUE,uLongestTextString);
  1056. uIndexofListView++;
  1057. // Fragmented Directories
  1058. swprintf(buffer, L"%I64d", pTextData->FragmentedDirectories);
  1059. uLongestTextString = InsertVolumeListViewItems(hWndDialog,uIndexofListView,IDS_LABEL_FRAGMENTED_DIRECTORIES,
  1060. IDS_LABEL_EQUAL_SIGN,InsertCommaIntoText(buffer),TRUE,uLongestTextString);
  1061. uIndexofListView++;
  1062. // Total Directories
  1063. swprintf(buffer, L"%I64d", pTextData->TotalDirectories);
  1064. uLongestTextString = InsertVolumeListViewItems(hWndDialog,uIndexofListView,IDS_LABEL_TOTAL_DIRECTORIES,
  1065. IDS_LABEL_EQUAL_SIGN,InsertCommaIntoText(buffer),TRUE,uLongestTextString);
  1066. uIndexofListView++;
  1067. // Directory Fragmentation Header
  1068. uLongestTextString = InsertVolumeListViewItems(hWndDialog,uIndexofListView,IDS_LABEL_DIRECTORY_FRAGMENTATION_HEADING
  1069. ,NULL,L"",FALSE,uLongestTextString);
  1070. uIndexofListView++;
  1071. // Total Fragments
  1072. swprintf(buffer, L"%I64d", pTextData->PagefileFrags);
  1073. uLongestTextString = InsertVolumeListViewItems(hWndDialog,uIndexofListView,IDS_LABEL_TOTAL_FRAGMENTS,
  1074. IDS_LABEL_EQUAL_SIGN,InsertCommaIntoText(buffer),TRUE,uLongestTextString);
  1075. uIndexofListView++;
  1076. // Pagefile Size
  1077. swprintf(buffer, L"%I64d", pTextData->PagefileBytes);
  1078. InsertCommaIntoText(buffer);
  1079. textBlock.FormatNum(GetDfrgResHandle(), pTextData->PagefileBytes, buffer);
  1080. uLongestTextString = InsertVolumeListViewItems(hWndDialog,uIndexofListView,IDS_LABEL_PAGEFILE_SIZE,
  1081. IDS_LABEL_EQUAL_SIGN,buffer,TRUE,uLongestTextString);
  1082. uIndexofListView++;
  1083. // Pagefile Fragmentation Header
  1084. uLongestTextString = InsertVolumeListViewItems(hWndDialog,uIndexofListView,IDS_LABEL_PAGEFILE_FRAGMENTATION_HEADING
  1085. ,NULL,L"",FALSE,uLongestTextString);
  1086. uIndexofListView++;
  1087. // Average Fragments per File (CHECK THE MATH AND THE UNITS ON THIS ONE!!!)
  1088. struct lconv *locals = localeconv();
  1089. swprintf(buffer, L"%d%c%02d", (UINT)pTextData->AvgFragsPerFile/100,
  1090. ((locals && (locals->decimal_point)) ? *(locals->decimal_point) : '.'),
  1091. (UINT)pTextData->AvgFragsPerFile%100);
  1092. uLongestTextString = InsertVolumeListViewItems(hWndDialog,uIndexofListView,IDS_LABEL_AVERAGE_FRAGMENTS_PER_FILE,
  1093. IDS_LABEL_EQUAL_SIGN,buffer,TRUE,uLongestTextString);
  1094. uIndexofListView++;
  1095. // Total excess fragments
  1096. swprintf(buffer, L"%I64d", pTextData->NumExcessFrags);
  1097. uLongestTextString = InsertVolumeListViewItems(hWndDialog,uIndexofListView,IDS_LABEL_TOTAL_EXCESS_FRAGMENTS,
  1098. IDS_LABEL_EQUAL_SIGN,InsertCommaIntoText(buffer),TRUE,uLongestTextString);
  1099. uIndexofListView++;
  1100. // Total fragmented files
  1101. swprintf(buffer, L"%I64d", pTextData->NumFraggedFiles);
  1102. uLongestTextString = InsertVolumeListViewItems(hWndDialog,uIndexofListView,IDS_LABEL_TOTAL_FRAGMENTED_FILES,
  1103. IDS_LABEL_EQUAL_SIGN,InsertCommaIntoText(buffer),TRUE,uLongestTextString);
  1104. uIndexofListView++;
  1105. // Average Files Size
  1106. swprintf(buffer, L"%I64d", pTextData->AvgFileSize);
  1107. InsertCommaIntoText(buffer);
  1108. textBlock.FormatNum(GetDfrgResHandle(), pTextData->AvgFileSize, buffer);
  1109. uLongestTextString = InsertVolumeListViewItems(hWndDialog,uIndexofListView,IDS_LABEL_AVERAGE_FILE_SIZE,
  1110. IDS_LABEL_EQUAL_SIGN,buffer,TRUE,uLongestTextString);
  1111. uIndexofListView++;
  1112. // Total Files
  1113. swprintf(buffer, L"%I64d", pTextData->TotalFiles);
  1114. InsertCommaIntoText(buffer);
  1115. uLongestTextString = InsertVolumeListViewItems(hWndDialog,uIndexofListView,IDS_LABEL_TOTAL_FILES
  1116. ,IDS_LABEL_EQUAL_SIGN,buffer,TRUE,uLongestTextString);
  1117. uIndexofListView++;
  1118. // File Fragmentation Header
  1119. uLongestTextString = InsertVolumeListViewItems(hWndDialog,uIndexofListView,IDS_LABEL_FILE_FRAGMENTATION_HEADING
  1120. ,NULL,L"",FALSE,uLongestTextString);
  1121. uIndexofListView++;
  1122. // % Free Space Fragmentation
  1123. swprintf(buffer, L"%d", pTextData->FreeSpaceFragPercent);
  1124. uLongestTextString = InsertVolumeListViewItems(hWndDialog,uIndexofListView,IDS_LABEL_FREE_SPACE_FRAGMENTATION,
  1125. IDS_LABEL_EQUAL_SIGN,buffer,IDS_LABEL_PERCENT_SIGN,TRUE,uLongestTextString);
  1126. uIndexofListView++;
  1127. // % File Fragmentation
  1128. swprintf(buffer, L"%d", pTextData->PercentDiskFragged);
  1129. uLongestTextString = InsertVolumeListViewItems(hWndDialog,uIndexofListView,IDS_LABEL_FILE_FRAGMENTATION,
  1130. IDS_LABEL_EQUAL_SIGN,buffer,IDS_LABEL_PERCENT_SIGN,TRUE,uLongestTextString);
  1131. uIndexofListView++;
  1132. // % Total Fragmentation
  1133. swprintf(buffer, L"%d", (pTextData->PercentDiskFragged + pTextData->FreeSpaceFragPercent) / 2);
  1134. uLongestTextString = InsertVolumeListViewItems(hWndDialog,uIndexofListView,IDS_LABEL_TOTAL_FRAGMENTATION,
  1135. IDS_LABEL_EQUAL_SIGN,buffer,IDS_LABEL_PERCENT_SIGN,TRUE,uLongestTextString);
  1136. uIndexofListView++;
  1137. // Volume Fragmentation Header
  1138. uLongestTextString = InsertVolumeListViewItems(hWndDialog,uIndexofListView,IDS_LABEL_VOLUME_FRAGMENTATION_HEADING
  1139. ,NULL,L"",FALSE,uLongestTextString);
  1140. uIndexofListView++;
  1141. // % Free Space
  1142. swprintf(buffer, L"%d", pTextData->FreeSpacePercent);
  1143. uLongestTextString = InsertVolumeListViewItems(hWndDialog,uIndexofListView,IDS_LABEL_PERCENT_FREE_SPACE,
  1144. IDS_LABEL_EQUAL_SIGN,buffer,IDS_LABEL_PERCENT_SIGN,TRUE,uLongestTextString);
  1145. uIndexofListView++;
  1146. // Free Space
  1147. swprintf(buffer, L"%I64d", pTextData->FreeSpace);
  1148. InsertCommaIntoText(buffer);
  1149. textBlock.FormatNum(GetDfrgResHandle(), pTextData->FreeSpace, buffer);
  1150. uLongestTextString = InsertVolumeListViewItems(hWndDialog,uIndexofListView,IDS_LABEL_FREE_SPACE,IDS_LABEL_EQUAL_SIGN,
  1151. buffer,TRUE,uLongestTextString);
  1152. uIndexofListView++;
  1153. // Used Space
  1154. swprintf(buffer, L"%I64d", pTextData->UsedSpace);
  1155. InsertCommaIntoText(buffer);
  1156. textBlock.FormatNum(GetDfrgResHandle(), pTextData->UsedSpace, buffer);
  1157. uLongestTextString = InsertVolumeListViewItems(hWndDialog,uIndexofListView,IDS_LABEL_USED_SPACE,IDS_LABEL_EQUAL_SIGN,
  1158. buffer,TRUE,uLongestTextString);
  1159. uIndexofListView++;
  1160. // Cluster Size
  1161. swprintf(buffer, L"%I64d", pTextData->BytesPerCluster);
  1162. InsertCommaIntoText(buffer);
  1163. textBlock.FormatNum(GetDfrgResHandle(), pTextData->BytesPerCluster, buffer);
  1164. uLongestTextString = InsertVolumeListViewItems(hWndDialog,uIndexofListView,IDS_LABEL_CLUSTER_SIZE,IDS_LABEL_EQUAL_SIGN,
  1165. buffer,TRUE,uLongestTextString);
  1166. uIndexofListView++;
  1167. ///////////////////////////////////////////////////////////////////////////
  1168. // Volume Size
  1169. swprintf(buffer, L"%I64d", pTextData->DiskSize);
  1170. InsertCommaIntoText(buffer);
  1171. textBlock.FormatNum(GetDfrgResHandle(), pTextData->DiskSize, buffer);
  1172. uLongestTextString = InsertVolumeListViewItems(hWndDialog,uIndexofListView,IDS_LABEL_VOLUME_SIZE,IDS_LABEL_EQUAL_SIGN,
  1173. buffer,TRUE,uLongestTextString);
  1174. uIndexofListView++;
  1175. // if there are >1 mount points, print them all out
  1176. // yes, this will duplicate the same as the display label
  1177. // refresh the mount point list
  1178. #ifndef VER4
  1179. pLocalVolume->GetVolumeMountPointList();
  1180. if (pLocalVolume->MountPointCount() > 1){
  1181. for (UINT i=0; i<pLocalVolume->MountPointCount(); i++){
  1182. LoadString(GetDfrgResHandle(), IDS_MOUNTED_VOLUME, tempBuffer, sizeof(tempBuffer)/sizeof(TCHAR));
  1183. swprintf(buffer, L"%s %s", tempBuffer, pLocalVolume->MountPoint(i));
  1184. uLongestTextString = InsertVolumeListViewItems(hWndDialog,uIndexofListView,buffer,
  1185. NULL,L"",FALSE,uLongestTextString);
  1186. uIndexofListView++;
  1187. }
  1188. }
  1189. #endif
  1190. // write out the display label (usually the drive letter/label)
  1191. LoadString(GetDfrgResHandle(), IDS_LABEL_VOLUME, tempBuffer, sizeof(tempBuffer)/sizeof(TCHAR));
  1192. swprintf(buffer, L"%s %s", tempBuffer,pLocalVolume->DisplayLabel());
  1193. uLongestTextString = InsertVolumeListViewItems(hWndDialog,uIndexofListView,buffer
  1194. ,NULL,L"",FALSE,uLongestTextString);
  1195. uIndexofListView++;
  1196. // InsertVolumeListViewItems(hWndDialog,uIndexofListView,IDS_PRODUCT_NAME,NULL,L"",FALSE);
  1197. return uLongestTextString;
  1198. }
  1199. /***************************************************************************************************************
  1200. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  1201. DESCRIPTION:
  1202. This will write the fragmented file list into a memory buffer that can be displayed.
  1203. DATA STRUCTURES:
  1204. None.
  1205. GLOBALS:
  1206. INPUT:
  1207. hText - The handle to the memory to write the report to.
  1208. pText - A pointer to the same.
  1209. dwFlags - Contains flags specifying how to generate the report, (unicode vs. ascii, and cr lf instead of newline.)
  1210. RETURN:
  1211. TRUE - Success.
  1212. FALSE - Fatal error.
  1213. */
  1214. static BOOL
  1215. WriteFraggedReportInMemory(
  1216. CTextBlock &textBlock,
  1217. DWORD dwFlags
  1218. )
  1219. {
  1220. const colWidth0 = 16;
  1221. const colWidth1 = 16;
  1222. const colWidth2 = 55;
  1223. // set up the text block
  1224. textBlock.SetResourceHandle(GetDfrgResHandle());
  1225. textBlock.SetUseCRLF(TRUE);
  1226. // print the title
  1227. if (dwFlags & PRINT_DEFRAG_TITLE){
  1228. textBlock.WriteToBuffer(IDS_PRODUCT_NAME);
  1229. textBlock.EndOfLine();
  1230. // write out the display label (usually the drive letter/label)
  1231. textBlock.WriteToBuffer(IDS_LABEL_VOLUME);
  1232. textBlock.WriteToBuffer(L" %s", pLocalVolume->DisplayLabel());
  1233. textBlock.EndOfLine();
  1234. // if there are >1 mount points, print them all out
  1235. // yes, this will duplicate the same as the display label
  1236. // refresh the mount point list
  1237. #ifndef VER4
  1238. pLocalVolume->GetVolumeMountPointList();
  1239. if (pLocalVolume->MountPointCount() > 1){
  1240. for (UINT i=0; i<pLocalVolume->MountPointCount(); i++){
  1241. textBlock.WriteToBuffer(IDS_MOUNTED_VOLUME);
  1242. textBlock.WriteToBuffer(L": %s", pLocalVolume->MountPoint(i));
  1243. textBlock.EndOfLine();
  1244. }
  1245. }
  1246. #endif
  1247. textBlock.EndOfLine();
  1248. }
  1249. else { // otherwise add a dividing line
  1250. textBlock.EndOfLine();
  1251. textBlock.WriteToBuffer(L"--------------------------------------------------------------------------------");
  1252. textBlock.EndOfLine();
  1253. }
  1254. // if no tabs, then set the fixed columns
  1255. if (dwFlags & ADD_TABS_REPORT){
  1256. textBlock.SetUseTabs(TRUE);
  1257. }
  1258. else{
  1259. textBlock.SetFixedColumnWidth(TRUE);
  1260. textBlock.SetColumnCount(3);
  1261. textBlock.SetColumnWidth(0, colWidth0); // fragments
  1262. textBlock.SetColumnWidth(1, colWidth1); // file size
  1263. textBlock.SetColumnWidth(2, colWidth2); // file name
  1264. }
  1265. // header
  1266. textBlock.WriteToBuffer(IDS_NUM_FRAGMENTS);
  1267. textBlock.WriteTab();
  1268. textBlock.WriteToBuffer(IDS_FRAGGED_FILESIZE);
  1269. textBlock.WriteTab();
  1270. if(pLocalVolume->DefragMode() == ANALYZE)
  1271. textBlock.WriteToBuffer(IDS_LABEL_MOST_FRAGMENTED_FILE);
  1272. else
  1273. textBlock.WriteToBuffer(IDS_FILE_NO_DEFRAG);
  1274. textBlock.EndOfLine();
  1275. //If there are no items in the list, print "None"
  1276. if(pLocalVolume->m_FraggedFileList.Size() == 0){
  1277. textBlock.WriteToBuffer(IDS_LABEL_NONE);
  1278. textBlock.EndOfLine();
  1279. }
  1280. else{
  1281. CFraggedFile *pFraggedFile;
  1282. for(UINT i=0; i<pLocalVolume->m_FraggedFileList.Size(); i++){
  1283. pFraggedFile = pLocalVolume->m_FraggedFileList.GetAt(i);
  1284. // write the data columns
  1285. textBlock.WriteToBuffer(pFraggedFile->cExtentCount());
  1286. textBlock.WriteTab();
  1287. textBlock.WriteToBuffer(pFraggedFile->cFileSize());
  1288. textBlock.WriteTab();
  1289. if (pFraggedFile->FileNameLen() >= 4 * MAX_PATH) {
  1290. textBlock.WriteToBuffer(L"\\...%s", pFraggedFile->FileNameTruncated(4 * MAX_PATH - 5));
  1291. }
  1292. else {
  1293. textBlock.WriteToBuffer(pFraggedFile->FileName());
  1294. }
  1295. textBlock.EndOfLine();
  1296. }
  1297. }
  1298. return TRUE;
  1299. }
  1300. /***************************************************************************************************************
  1301. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  1302. DESCRIPTION:
  1303. This function will create a text report that can be dumped into a dialog, saved to a file or printed.
  1304. Flags are passed in to determine what type of report should be generated.
  1305. Memory is allocated, filled in with the report, and the handle is returned and must be freed by the caller.
  1306. DATA STRUCTURES:
  1307. GLOBALS:
  1308. None.
  1309. INPUT:
  1310. dwFlags - MOST_FRAGGED_REPORT will create a most fragged list.
  1311. NULL_TERMINATE_REPORT will add a null terminator to the end of the report.
  1312. ASCII_REPORT will cause the report to be generated in ASCII
  1313. UNICODE_REPORT will cause the report to be generated in UNICODE (default).
  1314. CR_LF_REPORT will cause carriage returns and line feeds to be placed at the end of each line so
  1315. the text can be written to a file.
  1316. NO_TABS_REPORT will cause the report to contain spaces rather than tabs. Tabs should be used for a proportional font,
  1317. spaces for a fixed font.
  1318. ***NOTE: Right now, only ASCII_REPORT works and is the default. UNICODE is not implemented yet in this report system.
  1319. RETURN:
  1320. A handle to the memory containing the report.
  1321. */
  1322. static BOOL
  1323. CreateTextReportInMemory(
  1324. CTextBlock &textBlock,
  1325. DWORD dwFlags
  1326. )
  1327. {
  1328. // Create the basic text report that will tell how many fragged files, etc.
  1329. WriteTextReportInMemory(textBlock, dwFlags);
  1330. if(dwFlags & MOST_FRAGGED_REPORT){
  1331. //textBlock.EndOfLine();
  1332. //textBlock.WriteToBuffer
  1333. // (L"--------------------------------------------------------------------------------");
  1334. //textBlock.EndOfLine();
  1335. // Create the most fragged file list.
  1336. WriteFraggedReportInMemory(textBlock, dwFlags);
  1337. }
  1338. textBlock.WriteNULL();
  1339. return TRUE;
  1340. }
  1341. /***************************************************************************************************************
  1342. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  1343. DESCRIPTION:
  1344. This function saves the data from the drive report as a text file.
  1345. DATA STRUCTURES:
  1346. None.
  1347. GLOBALS:
  1348. INPUT:
  1349. RETURN:
  1350. None.
  1351. */
  1352. static BOOL
  1353. SaveDriveData(
  1354. IN HWND hWndDialog
  1355. )
  1356. {
  1357. CTextBlock textBlock;
  1358. OPENFILENAME ofn = {0};
  1359. TCHAR cFile[MAX_PATH + 50];
  1360. TCHAR szFilter[300];
  1361. TEXT_DATA* pTextData = &(pLocalVolume->m_TextData);
  1362. DWORD commError = 0;
  1363. BOOL done = FALSE;
  1364. VString saveStatsLabel(IDS_LABEL_SAVE_DISK_STATS, GetDfrgResHandle());
  1365. VString textFilesLabel(IDS_LABEL_TEXT_FILES, GetDfrgResHandle());
  1366. VString allFilesLabel(IDS_LABEL_ALL_FILES, GetDfrgResHandle());
  1367. // get the My Documents path
  1368. LPITEMIDLIST pidl;
  1369. TCHAR myDocsPath[MAX_PATH];
  1370. SHGetSpecialFolderLocation(hWndDialog, CSIDL_PERSONAL, &pidl);
  1371. if (SHGetPathFromIDList(pidl, myDocsPath))
  1372. ofn.lpstrInitialDir = myDocsPath; // it was found
  1373. else
  1374. ofn.lpstrInitialDir = NULL; // My Docs dir not found - default to current dir
  1375. // Concoct a file name from the Drive letter if there is one
  1376. // otherwise use the display label
  1377. VString volume;
  1378. if (pLocalVolume->Drive()) {
  1379. volume.LoadString(IDS_LABEL_VOLUME, GetDfrgResHandle());
  1380. wsprintf(cFile, TEXT("%s%c.txt"), volume.GetBuffer(), pLocalVolume->Drive());
  1381. }
  1382. else if (_tcslen(pLocalVolume->VolumeLabel()) > 0) {
  1383. wsprintf(cFile, TEXT("%s.txt"), pLocalVolume->VolumeLabel());
  1384. }
  1385. else {
  1386. volume.LoadString(IDS_LABEL_MOUNTED_VOLUME, GetDfrgResHandle());
  1387. wsprintf(cFile, TEXT("%s.txt"), volume.GetBuffer());
  1388. }
  1389. #ifdef VER4
  1390. ofn.lStructSize = sizeof(OPENFILENAME);
  1391. #else
  1392. // sizeof doesn't work under nt5
  1393. // special size was placed in header by MS
  1394. ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
  1395. #endif
  1396. ofn.hwndOwner = pLocalVolume->m_pDfrgCtl->m_hWndCD;
  1397. ofn.hInstance = _Module.GetModuleInstance();
  1398. ofn.lpstrCustomFilter = NULL;
  1399. ofn.nMaxCustFilter = 0;
  1400. ofn.nFilterIndex = 1;
  1401. ofn.lpstrFile = cFile;
  1402. ofn.nMaxFile = MAX_PATH;
  1403. ofn.lpstrFileTitle = NULL;
  1404. ofn.nMaxFileTitle = 0;
  1405. ofn.lpstrTitle = saveStatsLabel.GetBuffer();
  1406. ofn.nFileOffset = 0;
  1407. ofn.nFileExtension = 0;
  1408. ofn.lpstrDefExt = NULL;
  1409. ofn.lCustData = 0;
  1410. ofn.Flags = OFN_EXPLORER|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT;
  1411. ofn.lpstrFilter = szFilter;
  1412. //IDS_ANY_FILES_FILTER - "Analysis Files"
  1413. //IDS_ALL_FILES_FILTER - "All Files"
  1414. wsprintf((PTCHAR)ofn.lpstrFilter, TEXT("%s (*.txt)"), textFilesLabel.GetBuffer());
  1415. ofn.lpstrFilter += lstrlen(ofn.lpstrFilter)+1;
  1416. lstrcpy((PTCHAR)ofn.lpstrFilter, TEXT("*.txt"));
  1417. ofn.lpstrFilter += lstrlen(ofn.lpstrFilter)+1;
  1418. wsprintf((PTCHAR)ofn.lpstrFilter, TEXT("%s (*.*)"), allFilesLabel.GetBuffer());
  1419. ofn.lpstrFilter += lstrlen(ofn.lpstrFilter)+1;
  1420. lstrcpy((PTCHAR)ofn.lpstrFilter, TEXT("*.*"));
  1421. ofn.lpstrFilter += lstrlen(ofn.lpstrFilter)+1;
  1422. *(PTCHAR)ofn.lpstrFilter = 0;
  1423. ofn.lpstrFilter = szFilter;
  1424. // Disable the report dialog box
  1425. EnableWindow(hWndDialog, FALSE);
  1426. do {
  1427. // Create the Save dialog box - it is a mutated Open file common dialog.
  1428. BOOL isOK = GetSaveFileName(&ofn);
  1429. // inspect this if the GetSaveFileName() function fails
  1430. if (!isOK){
  1431. commError = CommDlgExtendedError();
  1432. }
  1433. // the GetSaveFileName() function failed. Bummer.
  1434. if (isOK) {
  1435. // Create a text report in memory that we can dump to the screen.
  1436. if (CreateTextReportInMemory(textBlock, MOST_FRAGGED_REPORT)) {
  1437. TCHAR cExtension[MAX_PATH+2];
  1438. _tsplitpath(cFile, NULL, NULL, NULL, cExtension);
  1439. if (_tcsclen(cExtension) != 4){
  1440. _tcscat(cFile, _T(".txt"));
  1441. }
  1442. // save the data to a text file (this method puts the Unicode marker in the file)
  1443. if (textBlock.StoreFile(cFile, CREATE_ALWAYS)) {
  1444. // enable the report dialog box
  1445. EnableWindow(hWndDialog, TRUE);
  1446. SetFocus(hWndDialog);
  1447. return TRUE;
  1448. }
  1449. }
  1450. }
  1451. else {
  1452. if (0 == commError) {
  1453. // enable the report dialog box
  1454. EnableWindow(hWndDialog, TRUE);
  1455. SetFocus(hWndDialog);
  1456. // User hit cancel, so all's well
  1457. return TRUE;
  1458. }
  1459. }
  1460. //
  1461. // We were unable to save the report. Put up a message box, and let
  1462. // the user try again
  1463. //
  1464. VString errFormat(IDS_ERR_UNABLE_TO_SAVE_REPORT, GetDfrgResHandle());
  1465. LPTSTR lpErrorMessage = new TCHAR[errFormat.GetLength() + _tcslen(cFile) + 2];
  1466. wsprintf(lpErrorMessage, errFormat, (LPCTSTR) cFile);
  1467. done = (IDCANCEL == MessageBoxW(hWndDialog, lpErrorMessage, saveStatsLabel.GetBuffer(), MB_OKCANCEL | MB_ICONWARNING));
  1468. delete [] lpErrorMessage;
  1469. } while (!done);
  1470. // enable the report dialog box
  1471. EnableWindow(hWndDialog, TRUE);
  1472. SetFocus(hWndDialog);
  1473. return TRUE;
  1474. }
  1475. /***************************************************************************************************************
  1476. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  1477. DESCRIPTION:
  1478. This function prints the data from the drive report as a text file.
  1479. DATA STRUCTURES:
  1480. None.
  1481. GLOBALS:
  1482. INPUT:
  1483. RETURN:
  1484. None.
  1485. */
  1486. static BOOL
  1487. PrintDriveData(
  1488. IN HWND hWndDialog
  1489. )
  1490. {
  1491. PRINTDLG pd = {0};
  1492. DOCINFO di = {0};
  1493. RECT Rect;
  1494. HBRUSH hBrush;
  1495. TEXT_DATA* pTextData = &(pLocalVolume->m_TextData);
  1496. pd.lStructSize = sizeof(PRINTDLG);
  1497. pd.hwndOwner = pLocalVolume->m_pDfrgCtl->m_hWndCD;
  1498. pd.hDevMode = (HANDLE)NULL;
  1499. pd.hDevNames = (HANDLE)NULL;
  1500. pd.nFromPage = 0;
  1501. pd.nToPage = 0;
  1502. pd.nMinPage = 0;
  1503. pd.nMaxPage = 0;
  1504. pd.nCopies = 0;
  1505. pd.hInstance = _Module.GetModuleInstance();
  1506. pd.Flags = PD_RETURNDC|PD_USEDEVMODECOPIES|PD_COLLATE|PD_NOSELECTION;//|PD_PRINTSETUP;
  1507. pd.lpfnSetupHook = (LPSETUPHOOKPROC)(FARPROC)NULL;
  1508. pd.lpSetupTemplateName = (LPTSTR)NULL;
  1509. pd.lpfnPrintHook = (LPPRINTHOOKPROC)(FARPROC)NULL;
  1510. pd.lpPrintTemplateName = (LPTSTR)NULL;
  1511. // Disable the report dialog box
  1512. EnableWindow(hWndDialog, FALSE);
  1513. // raise the system print dialog
  1514. BOOL isOK = PrintDlg(&pd);
  1515. // enable the report dialog box
  1516. EnableWindow(hWndDialog, TRUE);
  1517. SetFocus(hWndDialog);
  1518. if (!isOK)
  1519. return FALSE;
  1520. di.cbSize = sizeof(DOCINFO);
  1521. TCHAR docName[200];
  1522. EH_ASSERT(LoadString(GetDfrgResHandle(), IDS_DEFRAG_REPORT_DOC_NAME, docName, sizeof(docName)/sizeof(TCHAR)));
  1523. di.lpszDocName = docName;
  1524. di.lpszOutput = (LPTSTR)NULL;
  1525. di.fwType = 0;
  1526. StartDoc(pd.hDC, &di);
  1527. StartPage(pd.hDC);
  1528. Rect.top = 0.1 * GetDeviceCaps(pd.hDC, VERTRES);
  1529. Rect.bottom = 0.9 * GetDeviceCaps(pd.hDC, VERTRES);
  1530. Rect.left = 0.1 * GetDeviceCaps(pd.hDC, HORZRES);;
  1531. Rect.right = 0.9 * GetDeviceCaps(pd.hDC, HORZRES);
  1532. hBrush = (HBRUSH)GetStockObject(WHITE_BRUSH);
  1533. EF_ASSERT(hBrush);
  1534. FillRect(pd.hDC, &Rect, hBrush);
  1535. // get the extended window styles
  1536. LONG styles = ::GetWindowLong(hWndDialog, GWL_EXSTYLE);
  1537. // check the window styles for a right to left layout
  1538. UINT uFormat = DT_LEFT;
  1539. if (styles & WS_EX_LAYOUTRTL){
  1540. uFormat = DT_RIGHT | DT_RTLREADING;
  1541. }
  1542. // Create the basic text report
  1543. CTextBlock page1text;
  1544. WriteTextReportInMemory(page1text, MOST_FRAGGED_REPORT|PRINT_DEFRAG_TITLE);
  1545. // if we have a short list of fragged files, put it all on one page
  1546. if (pLocalVolume->m_FraggedFileList.Size() <= 5){
  1547. // get the text report
  1548. WriteFraggedReportInMemory(page1text, MOST_FRAGGED_REPORT);
  1549. // write the report to the printer
  1550. DrawText(pd.hDC, page1text.GetBuffer(), wcslen(page1text.GetBuffer()), &Rect, uFormat);
  1551. }
  1552. else { // if we have a long list of fragged files, then do a page break
  1553. // write the text (upper) portion to the printer
  1554. DrawText(pd.hDC, page1text.GetBuffer(), wcslen(page1text.GetBuffer()), &Rect, uFormat);
  1555. // do a page break and clear the rectangle
  1556. EndPage(pd.hDC);
  1557. FillRect(pd.hDC, &Rect, hBrush);
  1558. // create the fragged file list report in memory
  1559. CTextBlock page2text;
  1560. WriteFraggedReportInMemory(page2text, MOST_FRAGGED_REPORT|PRINT_DEFRAG_TITLE);
  1561. // send the fragged file list to the printer, page 2
  1562. DrawText(pd.hDC, page2text.GetBuffer(), wcslen(page2text.GetBuffer()), &Rect, uFormat);
  1563. }
  1564. // end of page
  1565. if(EndPage(pd.hDC) <= 0){
  1566. AbortDoc(pd.hDC);
  1567. return FALSE;
  1568. }
  1569. // end of print job
  1570. EndDoc(pd.hDC);
  1571. DeleteDC(pd.hDC);
  1572. if(pd.hDevMode){
  1573. EH_ASSERT(GlobalFree(pd.hDevMode) == NULL);
  1574. }
  1575. if(pd.hDevNames){
  1576. EH_ASSERT(GlobalFree(pd.hDevNames) == NULL);
  1577. }
  1578. return TRUE;
  1579. }
  1580. /***************************************************************************************************************
  1581. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  1582. DESCRIPTION:
  1583. This function initializes data for the report dialog box
  1584. DATA STRUCTURES:
  1585. None.
  1586. GLOBALS:
  1587. INPUT:
  1588. hWndDialog - handle to the dialog box
  1589. RETURN:
  1590. None.
  1591. */
  1592. static void
  1593. InitializeFragListView(
  1594. IN HWND hWndDialog
  1595. )
  1596. {
  1597. int iColumnWidth[MAX_FRAGGED_FILE_COLUMNS] = {65, 65, 223};
  1598. int iColumnID[MAX_FRAGGED_FILE_COLUMNS] = {
  1599. IDS_NUM_FRAGMENTS,
  1600. IDS_FRAGGED_FILESIZE,
  1601. IDS_FRAGGED_FILENAME
  1602. };
  1603. int iColumnFormat[MAX_FRAGGED_FILE_COLUMNS] = {
  1604. LVCFMT_RIGHT,
  1605. LVCFMT_RIGHT,
  1606. LVCFMT_LEFT
  1607. };
  1608. // Initialize the LVCOLUMN structure.
  1609. LVCOLUMN lvc = {0};
  1610. TCHAR cTemp[200];
  1611. lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM;
  1612. lvc.pszText = cTemp;
  1613. // Get handle to the Fragged listview
  1614. HWND hListView = GetDlgItem(hWndDialog, IDC_MOST_FRAGMENTED);
  1615. EV_ASSERT(hListView);
  1616. // Insert the columns into the Listview.
  1617. int col;
  1618. for (col = 0; col < MAX_FRAGGED_FILE_COLUMNS; col++) {
  1619. lvc.fmt = iColumnFormat[col];
  1620. lvc.iSubItem = col;
  1621. LoadString(
  1622. GetDfrgResHandle(),
  1623. iColumnID[col],
  1624. cTemp,
  1625. sizeof(cTemp)/sizeof(TCHAR));
  1626. // Insert the columns into the ListView.
  1627. if (ListView_InsertColumn(hListView, col, &lvc) == -1) {
  1628. Message(TEXT("InitializeFragListView - ListView_InsertColumn."), E_FAIL, 0);
  1629. return;
  1630. }
  1631. }
  1632. // Go back thru and update columns.
  1633. for (col = 0; col < MAX_FRAGGED_FILE_COLUMNS; col++) {
  1634. // Size column to header text.
  1635. if (!ListView_SetColumnWidth(hListView, col, LVSCW_AUTOSIZE_USEHEADER)) {
  1636. Message(TEXT("InitializeFragListView - ListView_SetColumnWidth."), E_FAIL, 0);
  1637. }
  1638. // Grow width if needed.
  1639. int tmpStrWidth = ListView_GetColumnWidth(hListView, col);
  1640. if (tmpStrWidth < iColumnWidth[col]) {
  1641. if (!ListView_SetColumnWidth(hListView, col, iColumnWidth[col])) {
  1642. Message(TEXT("InitializeFragListView - 2nd ListView_SetColumnWidth."), E_FAIL, 0);
  1643. }
  1644. }
  1645. }
  1646. // Tell the left column that he is RIGHT JUSTIFIED!!!
  1647. // The formatting sent with the InsertColumn does not
  1648. // stick for some reason.
  1649. // You can comment this code out and see if it is fixed if you wanna.
  1650. // Or maybe you can find the fix. But after 3 hours of trying, this
  1651. // was my solution...
  1652. lvc.mask = LVCF_FMT;
  1653. lvc.fmt = LVCFMT_RIGHT;
  1654. if (ListView_SetColumn(hListView, 0, &lvc) == -1) {
  1655. Message(TEXT("InitializeFragListView - ListView_SetColumn."), E_FAIL, 0);
  1656. return;
  1657. }
  1658. // make the listview hilite the entire row
  1659. ListView_SetExtendedListViewStyle(hListView, LVS_EX_FULLROWSELECT);
  1660. }
  1661. /***************************************************************************************************************
  1662. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  1663. DESCRIPTION:
  1664. This function initializes data for the report dialog box
  1665. DATA STRUCTURES:
  1666. None.
  1667. INPUT:
  1668. hWndDialog - handle to the dialog box
  1669. RETURN:
  1670. None.
  1671. */
  1672. static void
  1673. InitializeVolumeListView(
  1674. IN HWND hWndDialog
  1675. )
  1676. {
  1677. int iColumnWidth[MAX_VOLUME_INFO_COLUMNS] = {200,5,50};
  1678. //not needed, no column labels
  1679. int iColumnID[MAX_VOLUME_INFO_COLUMNS] = {
  1680. NULL,
  1681. NULL,
  1682. NULL
  1683. };
  1684. int iColumnFormat[MAX_VOLUME_INFO_COLUMNS] = {
  1685. LVCFMT_LEFT,
  1686. LVCFMT_RIGHT,
  1687. LVCFMT_LEFT
  1688. };
  1689. // Initialize the LVCOLUMN structure.
  1690. LVCOLUMN lvc = {0};
  1691. TCHAR cTemp[200];
  1692. lvc.mask = LVCF_FMT | LVCF_TEXT | LVCF_SUBITEM;
  1693. lvc.pszText = cTemp;
  1694. // Get handle to the Fragged listview
  1695. HWND hListView = GetDlgItem(hWndDialog, IDC_VOLUME_INFORMATION);
  1696. EV_ASSERT(hListView);
  1697. // Insert the columns into the Listview.
  1698. int col = 0;
  1699. for (col = 0; col < MAX_VOLUME_INFO_COLUMNS; col++) {
  1700. lvc.fmt = iColumnFormat[col];
  1701. lvc.iSubItem = col;
  1702. // LoadString(
  1703. // GetDfrgResHandle(),
  1704. // iColumnID[col],
  1705. // cTemp,
  1706. // sizeof(cTemp)/sizeof(TCHAR));
  1707. // Insert the columns into the ListView.
  1708. if (ListView_InsertColumn(hListView, col, &lvc) == -1) {
  1709. Message(TEXT("InitializeFragListView - ListView_InsertColumn."), E_FAIL, 0);
  1710. return;
  1711. }
  1712. }
  1713. // Go back thru and update columns.
  1714. for (col = 0; col < MAX_VOLUME_INFO_COLUMNS; col++) {
  1715. // Size column to header text.
  1716. if (!ListView_SetColumnWidth(hListView, col, iColumnWidth[col])) {
  1717. Message(TEXT("InitializeFragListView - ListView_SetColumnWidth."), E_FAIL, 0);
  1718. }
  1719. // Grow width if needed.
  1720. int tmpStrWidth = ListView_GetColumnWidth(hListView, col);
  1721. if (tmpStrWidth < iColumnWidth[col])
  1722. {
  1723. if (!ListView_SetColumnWidth(hListView, col, iColumnWidth[col])) {
  1724. Message(TEXT("InitializeFragListView - 2nd ListView_SetColumnWidth."), E_FAIL, 0);
  1725. }
  1726. }
  1727. }
  1728. // Tell the left column that he is RIGHT JUSTIFIED!!!
  1729. // The formatting sent with the InsertColumn does not
  1730. // stick for some reason.
  1731. // You can comment this code out and see if it is fixed if you wanna.
  1732. // Or maybe you can find the fix. But after 3 hours of trying, this
  1733. // was my solution...
  1734. lvc.mask = LVCF_FMT;
  1735. lvc.fmt = LVCFMT_LEFT;
  1736. if (ListView_SetColumn(hListView, 0, &lvc) == -1) {
  1737. Message(TEXT("InitializeFragListView - ListView_SetColumn."), E_FAIL, 0);
  1738. return;
  1739. }
  1740. // make the listview hilite the entire row
  1741. ListView_SetExtendedListViewStyle(hListView, LVS_EX_FULLROWSELECT);
  1742. }
  1743. /***************************************************************************************************************
  1744. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  1745. DESCRIPTION:
  1746. This function initializes data for the report dialog box
  1747. DATA STRUCTURES:
  1748. None.
  1749. INPUT:
  1750. hWndDialog - handle to the dialog box
  1751. RETURN:
  1752. None.
  1753. */
  1754. static void
  1755. ResizeVolumeListViewColumns(
  1756. IN HWND hWndDialog, IN UINT uWidthFirstColumn,
  1757. IN UINT uWidthSecondColumn, IN UINT uWidthThirdColumn
  1758. )
  1759. {
  1760. // Get handle to the Fragged listview
  1761. HWND hListView = GetDlgItem(hWndDialog, IDC_VOLUME_INFORMATION);
  1762. EV_ASSERT(hListView);
  1763. // Go back thru and update columns.
  1764. if (!ListView_SetColumnWidth(hListView, 0, LVSCW_AUTOSIZE))
  1765. {
  1766. Message(TEXT("InitializeFragListView - ListView_SetColumnWidth."), E_FAIL, 0);
  1767. }
  1768. if (!ListView_SetColumnWidth(hListView, 1, LVSCW_AUTOSIZE))
  1769. {
  1770. Message(TEXT("InitializeFragListView - ListView_SetColumnWidth."), E_FAIL, 0);
  1771. }
  1772. if (!ListView_SetColumnWidth(hListView, 2, LVSCW_AUTOSIZE))
  1773. {
  1774. Message(TEXT("InitializeFragListView - ListView_SetColumnWidth."), E_FAIL, 0);
  1775. }
  1776. }
  1777. /**************************************************************************************************
  1778. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  1779. ROUTINE DESCRIPTION:
  1780. Displays a pre-formated items on the pop-up list view screen.
  1781. DATA STRUCTURES:
  1782. None.
  1783. GLOBALS:
  1784. None.
  1785. INPUT:
  1786. IN HANDLE hListView,- handle to report dialog
  1787. RETURN:
  1788. None.
  1789. */
  1790. static void
  1791. InsertListViewItems(
  1792. IN HWND hWndDialog,
  1793. CVolume *pLocalVolume
  1794. )
  1795. {
  1796. // Get handle to the Fragged listview
  1797. HWND hListView = GetDlgItem(hWndDialog, IDC_MOST_FRAGMENTED);
  1798. EV_ASSERT(hListView);
  1799. LVITEM lvi = {0};
  1800. lvi.mask = LVIF_TEXT | LVIF_PARAM;
  1801. lvi.pszText = LPSTR_TEXTCALLBACK; // will be populated by the callback
  1802. // Add each item to the listview.
  1803. for (UINT i=0; i<pLocalVolume->m_FraggedFileList.Size(); i++) {
  1804. lvi.iItem = i;
  1805. // address of fragged file object
  1806. lvi.lParam = (LPARAM) pLocalVolume->m_FraggedFileList.GetAt(i);
  1807. // Send the data to the list view box.
  1808. if (ListView_InsertItem(hListView, &lvi) == -1){
  1809. Message(TEXT("InsertListViewItems - ListView_InsertItem"), E_FAIL, 0);
  1810. return;
  1811. }
  1812. for (UINT iSubItem = 0; iSubItem < MAX_FRAGGED_FILE_COLUMNS; iSubItem++) {
  1813. ListView_SetItemText(
  1814. hListView,
  1815. lvi.iItem,
  1816. iSubItem,
  1817. LPSTR_TEXTCALLBACK);
  1818. }
  1819. }
  1820. }
  1821. /**************************************************************************************************
  1822. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  1823. ROUTINE DESCRIPTION:
  1824. Displays a pre-formated items on the pop-up list view screen.
  1825. DATA STRUCTURES:
  1826. None.
  1827. GLOBALS:
  1828. None.
  1829. INPUT:
  1830. IN HANDLE hListView,- handle to report dialog
  1831. RETURN:
  1832. None.
  1833. */
  1834. static UINT
  1835. InsertVolumeListViewItems(
  1836. IN HWND hWndDialog, IN UINT iListItemNumber, IN UINT resourceIDText, IN UINT resourceIDSeperator,
  1837. IN TCHAR* pTextStr, BOOL bIndentText, UINT uLongestTextString
  1838. )
  1839. {
  1840. // Get handle to the Fragged listview
  1841. HWND hListView = GetDlgItem(hWndDialog, IDC_VOLUME_INFORMATION);
  1842. assert(hListView);
  1843. TCHAR buffer[256];
  1844. LVITEM lvi = {0};
  1845. lvi.mask = LVIF_TEXT | LVIF_PARAM;
  1846. lvi.pszText = LPSTR_TEXTCALLBACK; // will be populated by the callback
  1847. // lvi.item = iListItemNumber;
  1848. // Send the data to the list view box.
  1849. if (ListView_InsertItem(hListView, &lvi) == -1){
  1850. Message(TEXT("InsertVolumeListViewItems Failed"), E_FAIL, 0);
  1851. return 0;
  1852. }
  1853. TCHAR tempBuffer[300];
  1854. //load the resourceIDText
  1855. LoadString(GetDfrgResHandle(), resourceIDText, buffer, sizeof(buffer)/sizeof(TCHAR));
  1856. if(bIndentText)
  1857. {
  1858. swprintf(tempBuffer, L" %s", buffer);
  1859. } else
  1860. {
  1861. swprintf(tempBuffer, L"%s", buffer);
  1862. }
  1863. //need to make the string 30% longer and fill with spaces
  1864. UINT uTempStrLen = _tcslen(tempBuffer);
  1865. UINT uExtraStrLen = uTempStrLen * 3 / 10;
  1866. UINT i = 0;
  1867. if ((uTempStrLen + uExtraStrLen) < 255) //buffer already at maximum length
  1868. {
  1869. for(i=0;i<uExtraStrLen;i++)
  1870. {
  1871. _tcscat(tempBuffer, L" ");
  1872. }
  1873. }
  1874. uTempStrLen = _tcslen(tempBuffer);
  1875. if(uTempStrLen > uLongestTextString)
  1876. {
  1877. uLongestTextString = uTempStrLen;
  1878. }
  1879. ListView_SetItemText(
  1880. hListView,
  1881. lvi.iItem,
  1882. 0,
  1883. tempBuffer);
  1884. //load the resourceIDSeperator
  1885. LoadString(GetDfrgResHandle(), resourceIDSeperator, buffer, sizeof(buffer)/sizeof(TCHAR));
  1886. ListView_SetItemText(
  1887. hListView,
  1888. lvi.iItem,
  1889. 1,
  1890. buffer);
  1891. //load the pTextStr
  1892. ListView_SetItemText(
  1893. hListView,
  1894. lvi.iItem,
  1895. 2,
  1896. pTextStr);
  1897. return uLongestTextString;
  1898. }
  1899. /**************************************************************************************************
  1900. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  1901. ROUTINE DESCRIPTION:
  1902. Displays a pre-formated items on the pop-up list view screen.
  1903. DATA STRUCTURES:
  1904. None.
  1905. GLOBALS:
  1906. None.
  1907. INPUT:
  1908. IN HANDLE hListView,- handle to report dialog
  1909. RETURN:
  1910. None.
  1911. */
  1912. static UINT
  1913. InsertVolumeListViewItems(
  1914. IN HWND hWndDialog, IN UINT iListItemNumber, IN TCHAR* itemOneText, IN UINT resourceIDSeperator,
  1915. IN TCHAR* pTextStr, BOOL bIndentText, UINT uLongestTextString
  1916. )
  1917. {
  1918. // Get handle to the Fragged listview
  1919. HWND hListView = GetDlgItem(hWndDialog, IDC_VOLUME_INFORMATION);
  1920. assert(hListView);
  1921. TCHAR buffer[256];
  1922. LVITEM lvi = {0};
  1923. lvi.mask = LVIF_TEXT | LVIF_PARAM;
  1924. lvi.pszText = LPSTR_TEXTCALLBACK; // will be populated by the callback
  1925. // lvi.item = iListItemNumber;
  1926. // Send the data to the list view box.
  1927. if (ListView_InsertItem(hListView, &lvi) == -1){
  1928. Message(TEXT("InsertVolumeListViewItems Failed"), E_FAIL, 0);
  1929. return 0;
  1930. }
  1931. TCHAR tempBuffer[300];
  1932. //load the resourceIDText
  1933. if(bIndentText)
  1934. {
  1935. swprintf(tempBuffer, L" %s", itemOneText);
  1936. } else
  1937. {
  1938. swprintf(tempBuffer, L"%s", itemOneText);
  1939. }
  1940. UINT uTempStrLen = _tcslen(itemOneText);
  1941. if(uTempStrLen > uLongestTextString)
  1942. {
  1943. uLongestTextString = uTempStrLen;
  1944. }
  1945. //load the resourceIDText
  1946. ListView_SetItemText(
  1947. hListView,
  1948. lvi.iItem,
  1949. 0,
  1950. itemOneText);
  1951. //load the resourceIDSeperator
  1952. LoadString(GetDfrgResHandle(), resourceIDSeperator, buffer, sizeof(buffer)/sizeof(TCHAR));
  1953. ListView_SetItemText(
  1954. hListView,
  1955. lvi.iItem,
  1956. 1,
  1957. buffer);
  1958. //load the pTextStr
  1959. ListView_SetItemText(
  1960. hListView,
  1961. lvi.iItem,
  1962. 2,
  1963. pTextStr);
  1964. return uLongestTextString;
  1965. }
  1966. static UINT
  1967. InsertVolumeListViewItems(
  1968. IN HWND hWndDialog, IN UINT iListItemNumber, IN UINT resourceIDText, IN UINT resourceIDSeperator,
  1969. IN TCHAR* pTextStr, IN UINT resourceIDPercent, BOOL bIndentText, UINT uLongestTextString
  1970. )
  1971. {
  1972. // Get handle to the Fragged listview
  1973. HWND hListView = GetDlgItem(hWndDialog, IDC_VOLUME_INFORMATION);
  1974. assert(hListView);
  1975. TCHAR buffer[256];
  1976. TCHAR tempbuffer[256];
  1977. LVITEM lvi = {0};
  1978. lvi.mask = LVIF_TEXT | LVIF_PARAM;
  1979. lvi.pszText = LPSTR_TEXTCALLBACK; // will be populated by the callback
  1980. // lvi.item = iListItemNumber;
  1981. // Send the data to the list view box.
  1982. if (ListView_InsertItem(hListView, &lvi) == -1){
  1983. Message(TEXT("InsertVolumeListViewItems Failed"), E_FAIL, 0);
  1984. return 0;
  1985. }
  1986. TCHAR tempBuffer[300];
  1987. //load the resourceIDText
  1988. LoadString(GetDfrgResHandle(), resourceIDText, buffer, sizeof(buffer)/sizeof(TCHAR));
  1989. if(bIndentText)
  1990. {
  1991. swprintf(tempBuffer, L" %s", buffer);
  1992. } else
  1993. {
  1994. swprintf(tempBuffer, L"%s", buffer);
  1995. }
  1996. UINT uTempStrLen = _tcslen(tempBuffer);
  1997. if(uTempStrLen > uLongestTextString)
  1998. {
  1999. uLongestTextString = uTempStrLen;
  2000. }
  2001. ListView_SetItemText(
  2002. hListView,
  2003. lvi.iItem,
  2004. 0,
  2005. tempBuffer);
  2006. //load the resourceIDSeperator
  2007. LoadString(GetDfrgResHandle(), resourceIDSeperator, buffer, sizeof(buffer)/sizeof(TCHAR));
  2008. ListView_SetItemText(
  2009. hListView,
  2010. lvi.iItem,
  2011. 1,
  2012. buffer);
  2013. LoadString(GetDfrgResHandle(), resourceIDPercent, buffer, sizeof(buffer)/sizeof(TCHAR));
  2014. swprintf(tempbuffer, L"%s %s", pTextStr,buffer);
  2015. //load the pTextStr
  2016. ListView_SetItemText(
  2017. hListView,
  2018. lvi.iItem,
  2019. 2,
  2020. tempbuffer);
  2021. return uLongestTextString;
  2022. }
  2023. /***************************************************************************************************************
  2024. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  2025. DESCRIPTION:
  2026. This function deallocate resources for the report dialog
  2027. DATA STRUCTURES:
  2028. None.
  2029. INPUT:
  2030. hWndDialog - handle to the dialog box
  2031. RETURN:
  2032. None.
  2033. */
  2034. static void
  2035. ExitReport(
  2036. IN HWND hWndDialog
  2037. )
  2038. {
  2039. ::DeleteObject(hDlgFont);
  2040. EndDialog(hWndDialog, 0);
  2041. }
  2042. /***************************************************************************************************************
  2043. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  2044. DESCRIPTION:
  2045. This function deallocate resources for the report dialog
  2046. DATA STRUCTURES:
  2047. None.
  2048. INPUT:
  2049. hWndDialog - handle to the dialog box
  2050. RETURN:
  2051. None.
  2052. */
  2053. TCHAR*
  2054. InsertCommaIntoText(
  2055. IN TCHAR* stringBuffer
  2056. )
  2057. {
  2058. TCHAR targetString[256];
  2059. TCHAR sourceString[256];
  2060. TCHAR tcThousandsSep[2] = {TEXT(','), 0};
  2061. _tcscpy(sourceString, stringBuffer);
  2062. if(_tcslen(sourceString) == 0) {
  2063. return TEXT("");
  2064. }
  2065. struct lconv *locals = localeconv();
  2066. if (locals && (locals->thousands_sep) && (*(locals->thousands_sep) != 0)) {
  2067. _stprintf(tcThousandsSep, TEXT("%C"), *(locals->thousands_sep));
  2068. }
  2069. UINT uGrouping = 0;
  2070. if (locals && (locals->grouping)) {
  2071. uGrouping = atoi(locals->grouping);
  2072. }
  2073. if(uGrouping == 0) {
  2074. uGrouping = 3; //default value if its not supported
  2075. }
  2076. // point the source pointer at the null terminator
  2077. PTCHAR pSource = sourceString + _tcslen(sourceString);
  2078. // put the target pointer at the end of the target buffer
  2079. PTCHAR pTarget = targetString + sizeof(targetString) / sizeof(TCHAR) - 1;
  2080. // write the null terminator
  2081. *pTarget = NULL;
  2082. for (UINT i=0; i<_tcslen(sourceString); i++){
  2083. if (i>0 && i%uGrouping == 0){
  2084. pTarget--;
  2085. *pTarget = tcThousandsSep[0];
  2086. }
  2087. pTarget--;
  2088. pSource--;
  2089. *pTarget = *pSource;
  2090. }
  2091. // if (stringBufferLength > _tcslen(pTarget)){
  2092. _tcscpy(stringBuffer, pTarget);
  2093. // }
  2094. // else{
  2095. // _tcscpy(stringBuffer, TEXT(""));
  2096. // }
  2097. return stringBuffer;
  2098. }
  2099. /***************************************************************************************************************
  2100. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  2101. DESCRIPTION:
  2102. This method resizes the buttons
  2103. DATA STRUCTURES:
  2104. genericButton structure.
  2105. INPUT:
  2106. hWndDialog - handle to the dialog box
  2107. RETURN:
  2108. None.
  2109. */
  2110. void GetButtonDimensions(HWND hWndDialog, BOOL bIsAnalysisReport)
  2111. {
  2112. HDC OutputDC = GetDC(hWndDialog);
  2113. EV_ASSERT(OutputDC);
  2114. HDC WorkDC = ::CreateCompatibleDC(OutputDC);
  2115. EV_ASSERT(WorkDC);
  2116. ::SelectObject(WorkDC, hDlgFont);
  2117. const bigButtonSpacer = 20;
  2118. adjustedButtonHeight = __max((UINT)(1.5 * uFontHeight), m_ButtonHeight);
  2119. //need to know the total width of the buttons before setting location
  2120. totalButtonWidth = 0;
  2121. TCHAR buffer[256];
  2122. //width of the Close button
  2123. SendDlgItemMessage(hWndDialog, IDCANCEL, WM_GETTEXT, (WPARAM) 255, (LPARAM) buffer);
  2124. adjustedButtonWidthClose = __max(m_ButtonSpacer + GetStringWidth(buffer, WorkDC), m_ButtonWidth);
  2125. totalButtonWidth += adjustedButtonWidthClose + 2 * m_ButtonSpacer;
  2126. //width of the Defragment button
  2127. if(bIsAnalysisReport) //need to include the Defragment button if we are using the analysis report
  2128. {
  2129. SendDlgItemMessage(hWndDialog, IDC_DEFRAGMENT, WM_GETTEXT, (WPARAM) 255, (LPARAM) buffer);
  2130. adjustedButtonWidthDefrag = __max(m_ButtonSpacer + GetStringWidth(buffer, WorkDC), m_ButtonWidth);
  2131. totalButtonWidth += adjustedButtonWidthDefrag + m_ButtonSpacer;
  2132. } else //add another close button to make the dialog wide enough
  2133. {
  2134. totalButtonWidth += adjustedButtonWidthClose + 2 * m_ButtonSpacer;
  2135. }
  2136. //width of the Save As button
  2137. SendDlgItemMessage(hWndDialog, IDC_SAVE, WM_GETTEXT, (WPARAM) 255, (LPARAM) buffer);
  2138. adjustedButtonWidthSave = __max(m_ButtonSpacer + GetStringWidth(buffer, WorkDC), m_ButtonWidth);
  2139. totalButtonWidth += adjustedButtonWidthSave + m_ButtonSpacer;
  2140. //width of the Print button
  2141. SendDlgItemMessage(hWndDialog, IDC_PRINT, WM_GETTEXT, (WPARAM) 255, (LPARAM) buffer);
  2142. adjustedButtonWidthPrint = __max(m_ButtonSpacer + GetStringWidth(buffer, WorkDC), m_ButtonWidth);
  2143. totalButtonWidth += adjustedButtonWidthPrint + m_ButtonSpacer;
  2144. minimumDialogWidth = __max(minimumDialogWidth,totalButtonWidth);
  2145. DeleteDC(OutputDC); // handle to device context
  2146. DeleteDC(WorkDC); // handle to device context
  2147. }
  2148. /***************************************************************************************************************
  2149. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  2150. DESCRIPTION:
  2151. This method positons the buttons
  2152. DATA STRUCTURES:
  2153. genericButton structure.
  2154. INPUT:
  2155. hWndDialog - handle to the dialog box
  2156. RETURN:
  2157. None.
  2158. */
  2159. void PositionButtons(HWND hWndDialog, RECT rDlg, BOOL bIsAnalysisReport)
  2160. {
  2161. HDC OutputDC = GetDC(hWndDialog);
  2162. EV_ASSERT(OutputDC);
  2163. HDC WorkDC = ::CreateCompatibleDC(OutputDC);
  2164. EV_ASSERT(WorkDC);
  2165. ::SelectObject(WorkDC, hDlgFont);
  2166. // Calculate Close Button position and size.
  2167. GetWindowRect(GetDlgItem(hWndDialog, IDCANCEL), &rcButtonClose);
  2168. rcButtonClose.right = rDlg.right - rDlg.left - m_ButtonFloat;
  2169. rcButtonClose.left = rcButtonClose.right - adjustedButtonWidthClose;
  2170. rcButtonClose.bottom = rDlg.bottom - rDlg.top - (1.75 * adjustedButtonHeight);
  2171. rcButtonClose.top = rcButtonClose.bottom - adjustedButtonHeight;
  2172. PositionButton(&rcButtonClose,GetDlgItem(hWndDialog, IDCANCEL));
  2173. if(bIsAnalysisReport)
  2174. {
  2175. GetWindowRect(GetDlgItem(hWndDialog, IDC_DEFRAGMENT), &rcButtonDefrag);
  2176. rcButtonDefrag.right = rcButtonClose.left - m_ButtonSpacer;
  2177. rcButtonDefrag.left = rcButtonDefrag.right - adjustedButtonWidthDefrag;
  2178. rcButtonDefrag.bottom = rDlg.bottom - rDlg.top - (1.75 * adjustedButtonHeight);
  2179. rcButtonDefrag.top = rcButtonDefrag.bottom - adjustedButtonHeight;
  2180. PositionButton(&rcButtonDefrag,GetDlgItem(hWndDialog, IDC_DEFRAGMENT));
  2181. //need to do the Save As button also
  2182. GetWindowRect(GetDlgItem(hWndDialog, IDC_SAVE), &rcButtonSave);
  2183. rcButtonSave.right = rcButtonDefrag.left - m_ButtonSpacer;
  2184. rcButtonSave.left = rcButtonSave.right - adjustedButtonWidthSave;
  2185. rcButtonSave.bottom = rDlg.bottom - rDlg.top - (1.75 * adjustedButtonHeight);
  2186. rcButtonSave.top = rcButtonSave.bottom - adjustedButtonHeight;
  2187. PositionButton(&rcButtonSave,GetDlgItem(hWndDialog, IDC_SAVE));
  2188. } else
  2189. {
  2190. //we position the Save Button next to the Close Button
  2191. GetWindowRect(GetDlgItem(hWndDialog, IDC_SAVE), &rcButtonSave);
  2192. rcButtonSave.right = rcButtonClose.left - m_ButtonSpacer;
  2193. rcButtonSave.left = rcButtonSave.right - adjustedButtonWidthSave;
  2194. rcButtonSave.bottom = rDlg.bottom - rDlg.top - (1.75 * adjustedButtonHeight);
  2195. rcButtonSave.top = rcButtonSave.bottom - adjustedButtonHeight;
  2196. PositionButton(&rcButtonSave,GetDlgItem(hWndDialog, IDC_SAVE));
  2197. }
  2198. GetWindowRect(GetDlgItem(hWndDialog, IDC_PRINT), &rcButtonPrint);
  2199. rcButtonPrint.right = rcButtonSave.left - m_ButtonSpacer;
  2200. rcButtonPrint.left = rcButtonPrint.right - adjustedButtonWidthPrint;
  2201. rcButtonPrint.bottom = rDlg.bottom - rDlg.top - (1.75 * adjustedButtonHeight);
  2202. rcButtonPrint.top = rcButtonPrint.bottom - adjustedButtonHeight;
  2203. PositionButton(&rcButtonPrint,GetDlgItem(hWndDialog, IDC_PRINT));
  2204. ::DeleteDC(WorkDC);
  2205. ::DeleteDC(OutputDC);
  2206. }
  2207. /***************************************************************************************************************
  2208. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  2209. DESCRIPTION:
  2210. This method positons the buttons
  2211. DATA STRUCTURES:
  2212. genericButton structure.
  2213. INPUT:
  2214. hWndDialog - handle to the dialog box
  2215. RETURN:
  2216. None.
  2217. */
  2218. void PositionControls(HWND hWndDialog, RECT rDlg)
  2219. {
  2220. }
  2221. /***************************************************************************************************************
  2222. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  2223. DESCRIPTION:
  2224. This method repositions the buttons
  2225. DATA STRUCTURES:
  2226. genericButton structure.
  2227. INPUT:
  2228. hWndDialog - handle to the dialog box
  2229. RECT - Defining the location of where the button is going
  2230. RETURN:
  2231. None.
  2232. */
  2233. void PositionButton(RECT* prcPos, HWND hWndDialog)
  2234. {
  2235. if (hWndDialog != NULL){
  2236. MoveWindow(hWndDialog,
  2237. prcPos->left,
  2238. prcPos->top,
  2239. prcPos->right - prcPos->left,
  2240. prcPos->bottom - prcPos->top,
  2241. TRUE);
  2242. }
  2243. }
  2244. /***************************************************************************************************************
  2245. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  2246. DESCRIPTION:
  2247. This method finds the longest string inside the VString terminated by a \n
  2248. DATA STRUCTURES:
  2249. genericButton structure.
  2250. INPUT:
  2251. PTCHAR - buffer that contains the string
  2252. HDC - Handle to a device context (DC) on the screen.
  2253. RETURN:
  2254. Width of the character.
  2255. */
  2256. UINT GetStringWidth(PTCHAR stringBuf, HDC WorkDC)
  2257. {
  2258. if (!stringBuf){
  2259. return 0;
  2260. }
  2261. UINT iStringWidth = 0;
  2262. int iCharWidth = 0;
  2263. for (UINT i=0; i<_tcslen(stringBuf); i++){
  2264. if (::GetCharWidth32(
  2265. WorkDC,
  2266. stringBuf[i],
  2267. stringBuf[i],
  2268. &iCharWidth)) {
  2269. iStringWidth += iCharWidth;
  2270. }
  2271. }
  2272. return iStringWidth;
  2273. }
  2274. /***************************************************************************************************************
  2275. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  2276. DESCRIPTION:
  2277. This method resizes the dialog in response to the user resizing the dialog
  2278. DATA STRUCTURES:
  2279. None.
  2280. INPUT:
  2281. None.
  2282. RETURN:
  2283. None.
  2284. */
  2285. void ResizeDialog(HWND hWndDialog)
  2286. {
  2287. UINT dialogBoxFinalWidth;
  2288. UINT dialogBoxFinalHeight;
  2289. //get the new dimensions of the dialog
  2290. GetWindowRect(hWndDialog, &rcNewDialogSize);
  2291. if((rcNewDialogSize.bottom - rcNewDialogSize.top) < (rcOriginalDialogSize.bottom - rcOriginalDialogSize.top) ||
  2292. (rcNewDialogSize.right - rcNewDialogSize.left) < (rcOriginalDialogSize.right - rcOriginalDialogSize.left))
  2293. {
  2294. dialogBoxFinalWidth = rcOriginalDialogSize.right - rcOriginalDialogSize.left;
  2295. dialogBoxFinalHeight = rcOriginalDialogSize.bottom - rcOriginalDialogSize.top;
  2296. //set back to original size
  2297. MoveWindow(hWndDialog, rcOriginalDialogSize.left, rcOriginalDialogSize.top, dialogBoxFinalWidth, dialogBoxFinalHeight, TRUE);
  2298. return;
  2299. }
  2300. //if its not smaller, it must be bigger or the same, no matter, reposition the stuff
  2301. m_ButtonFloat = ((rcNewDialogSize.right - rcNewDialogSize.left) - totalButtonWidth) / 2;
  2302. PositionButtons(hWndDialog, rcNewDialogSize,TRUE);
  2303. InvalidateRect(
  2304. hWndDialog, // handle of window with changed update region
  2305. &rcNewDialogSize, // address of rectangle coordinates
  2306. TRUE // erase-background flag
  2307. );
  2308. }
  2309. /***************************************************************************************************************
  2310. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  2311. DESCRIPTION:
  2312. This method finds the longest string inside the VString terminated by a \n
  2313. DATA STRUCTURES:
  2314. genericButton structure.
  2315. INPUT:
  2316. VString - string in the editbox
  2317. RETURN:
  2318. Longest line in the editbox terminated by a \n.
  2319. */
  2320. UINT FindMaxEditboxStringWidth(VString vstring)
  2321. {
  2322. int iLongestLine = 0, iEndofString = 0, iCurrentSearchLocation = 0;
  2323. iEndofString = vstring.GetLength();
  2324. if(iEndofString == 0) //oops no string return 0
  2325. {
  2326. return(0);
  2327. }
  2328. while(iCurrentSearchLocation < iEndofString)
  2329. {
  2330. iCurrentSearchLocation = vstring.Find(TEXT("\n"));
  2331. if(iCurrentSearchLocation == -1) //I didnt find any more
  2332. {
  2333. if (0 == iLongestLine) {
  2334. iLongestLine = iEndofString;
  2335. }
  2336. break;
  2337. }
  2338. if(iCurrentSearchLocation > iLongestLine)
  2339. {
  2340. iLongestLine = iCurrentSearchLocation;
  2341. }
  2342. vstring = vstring.Mid(iCurrentSearchLocation+1); //sub string the original chopping off the front
  2343. iEndofString = vstring.GetLength();
  2344. iCurrentSearchLocation = 0;
  2345. }
  2346. return(iLongestLine);
  2347. }
  2348. /***************************************************************************************************************
  2349. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  2350. DESCRIPTION:
  2351. This method counts the number of \n inside the VString for the editbox
  2352. DATA STRUCTURES:
  2353. genericButton structure.
  2354. INPUT:
  2355. VString - editbox string
  2356. RETURN:
  2357. Number of lines in the editbox.
  2358. */
  2359. UINT FindMaxEditboxStringHeight(VString vstring)
  2360. {
  2361. int iNumberofLines = 0, iEndofString = 0, iCurrentSearchLocation = 0;
  2362. iEndofString = vstring.GetLength();
  2363. if(iEndofString == 0) //oops no string return 0
  2364. {
  2365. return(0);
  2366. }
  2367. while(iCurrentSearchLocation < iEndofString)
  2368. {
  2369. iCurrentSearchLocation = vstring.Find(TEXT("\n"));
  2370. if(iCurrentSearchLocation == -1) //I didnt find any more
  2371. {
  2372. break;
  2373. }
  2374. iNumberofLines++;
  2375. vstring = vstring.Mid(iCurrentSearchLocation+1); //sub string the original chopping off the front
  2376. iEndofString = vstring.GetLength();
  2377. iCurrentSearchLocation = 0;
  2378. }
  2379. return(++iNumberofLines); //add 1 more since the last line does not have a \n
  2380. }
  2381. /***************************************************************************************************************
  2382. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  2383. DESCRIPTION:
  2384. checks for negative values and returns 0 for negative numbers.
  2385. DATA STRUCTURES:
  2386. none.
  2387. INPUT:
  2388. LONGLONG - lldatavalue
  2389. RETURN:
  2390. either lldatavalue or zero.
  2391. */
  2392. LONGLONG checkForNegativeValues(LONGLONG lldatavalue)
  2393. {
  2394. if(lldatavalue > 0)
  2395. {
  2396. return(lldatavalue);
  2397. } else
  2398. {
  2399. return 0;
  2400. }
  2401. }