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.

1159 lines
32 KiB

  1. /*****************************************************************************************************************
  2. FILENAME: GenericDialog.cpp
  3. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  4. */
  5. #include "stdafx.h"
  6. #ifndef SNAPIN
  7. #ifndef NOWINDOWSH
  8. #include <windows.h>
  9. #endif
  10. #endif
  11. #include "assert.h"
  12. #include "DfrgUI.h"
  13. #include "DfrgCmn.h"
  14. #include "DfrgCtl.h"
  15. #include "resource.h"
  16. #include "GetDfrgRes.h"
  17. #include "DfrgHlp.h"
  18. #include "genericdialog.h"
  19. #include "expand.h"
  20. static CVolume *pLocalVolume = NULL;
  21. static HFONT hDlgFont = NULL;
  22. static BOOL bIsIconVisible = FALSE;
  23. static HANDLE hgenericDialogIcon = NULL;
  24. static RECT rcButton0;
  25. static RECT rcButton1;
  26. static RECT rcButton2;
  27. static RECT rcButton3;
  28. static RECT rcButton4;
  29. static RECT rButton;
  30. static RECT rcIcon;
  31. static RECT rcOriginalDialogSize;
  32. static RECT rcNewDialogSize;
  33. static UINT totalButtonWidth;
  34. static UINT m_ButtonTopBottomSpacer;
  35. static UINT m_ButtonHeight;
  36. static UINT m_ButtonWidth;
  37. static UINT m_ButtonSpacer;
  38. static UINT m_Margin;
  39. static UINT m_ButtonFloat;
  40. static UINT minimumDialogWidth;
  41. static UINT minimumDialogHeight;
  42. static UINT iconSize;
  43. static UINT minimumNumberOfCaractersWide;
  44. static UINT minimumNumberOfLinesLong;
  45. static UINT adjustedButtonWidth0;
  46. static UINT adjustedButtonWidth1;
  47. static UINT adjustedButtonWidth2;
  48. static UINT adjustedButtonWidth3;
  49. static UINT adjustedButtonWidth4;
  50. static UINT adjustedButtonHeight;
  51. static UINT wNormalHeight; // height of reduced dialog box (which
  52. // extends just past the ID_MORE button vertically)
  53. static WORD wExpandedHeight; // height of full size dialog box
  54. static BOOL fExpanded = FALSE;
  55. static WORD wFontHeight;
  56. static WORD wEditBoxHeight;
  57. static WORD wEditBoxWidth;
  58. //structure for the buttons
  59. typedef struct{
  60. TCHAR m_buttonText[200];
  61. TCHAR m_buttonHelp[200];
  62. BOOL m_buttonVisible;
  63. } GENERICBUTTONARRAY;
  64. static GENERICBUTTONARRAY genericButtonArray[5];
  65. //structure for the help buttons
  66. //the structure consists of pairs of DWORDS
  67. //the first DWORD is the control identifier
  68. //the second DWORD is the help context identifier from the help file
  69. typedef struct{
  70. DWORD dHelpControlIdentifier;
  71. DWORD dHelpContextIdentifier;
  72. } GENERICHELPIDARRAY;
  73. static GENERICHELPIDARRAY genericHelpIDArray[5];
  74. static TCHAR genericDialogTitle[200];
  75. static TCHAR genericHelpFilePath[MAX_PATH + 30];
  76. static TCHAR genericEditBoxText[1024];
  77. static UINT iKeyPressedByUser;
  78. BOOL InitializeGenericDialog(IN HWND hWndDialog);
  79. void ExitAnalyzeDone(IN HWND hWndDialog);
  80. BOOL CALLBACK GenericDialogProc(
  81. IN HWND hWndDialog,
  82. IN UINT uMessage,
  83. IN WPARAM wParam,
  84. IN LPARAM lParam
  85. );
  86. static void SetButtonsandIcon(HWND hWndDialog);
  87. static UINT FindMaxEditboxStringWidth(VString vstring);
  88. static UINT FindMaxEditboxStringHeight(VString vstring);
  89. static void PositionButton(RECT* prcPos, HWND hWndDialog);
  90. static void SizeButtons(HWND hWndDialog);
  91. static void PositionButtons(HWND hWndDialog, RECT rDlg);
  92. static UINT GetStringWidth(PTCHAR stringBuf, HDC WorkDC);
  93. static void ResizeDialog(HWND hWndDialog);
  94. static void DrawIconOnDialog(HWND hWndDialog);
  95. /*****************************************************************************************************************
  96. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  97. ROUTINE DESCRIPTION:
  98. Constructor for GenericDialog Class
  99. INPUT:
  100. IN pVolume - address of volume that has just completed Analyzing
  101. RETURN:
  102. */
  103. CGenericDialog::CGenericDialog(void)
  104. {
  105. int i;
  106. for(i=0;i<=4;i++)
  107. {
  108. genericButtonArray[i].m_buttonVisible = FALSE;
  109. }
  110. bIsIconVisible = FALSE;
  111. iconSize = 0;
  112. m_ButtonTopBottomSpacer = 24;
  113. m_ButtonHeight = 26;
  114. m_ButtonWidth = 84;
  115. m_ButtonSpacer = 22;
  116. m_Margin = 20;
  117. m_ButtonFloat = 20;
  118. minimumDialogWidth = 250;
  119. minimumDialogHeight = 75;
  120. minimumNumberOfCaractersWide = 40;
  121. minimumNumberOfLinesLong = 2;
  122. //initialize the helpID array
  123. genericHelpIDArray[0].dHelpControlIdentifier = ID_GENERIC_BUTTON0;
  124. genericHelpIDArray[1].dHelpControlIdentifier = ID_GENERIC_BUTTON1;
  125. genericHelpIDArray[2].dHelpControlIdentifier = ID_GENERIC_BUTTON2;
  126. genericHelpIDArray[3].dHelpControlIdentifier = ID_GENERIC_BUTTON3;
  127. genericHelpIDArray[4].dHelpControlIdentifier = ID_GENERIC_BUTTON4;
  128. }
  129. /*****************************************************************************************************************
  130. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  131. ROUTINE DESCRIPTION:
  132. Destructor for GenericDialog Class
  133. INPUT:
  134. IN pVolume - address of volume that has just completed Analyzing
  135. RETURN:
  136. */
  137. CGenericDialog::~CGenericDialog(void)
  138. {
  139. }
  140. /*****************************************************************************************************************
  141. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  142. ROUTINE DESCRIPTION:
  143. Raises the Analyze Complete dialog
  144. INPUT:
  145. IN pVolume - address of volume that has just completed Analyzing
  146. RETURN:
  147. TRUE - Worked OK
  148. FALSE - Failure
  149. */
  150. UINT CGenericDialog::DoModal(HWND hWndDialog)
  151. {
  152. iKeyPressedByUser = NULL;
  153. INT_PTR ret = DialogBoxParam(
  154. GetDfrgResHandle(),
  155. MAKEINTRESOURCE(IDD_GENERIC_DIALOG),
  156. hWndDialog,
  157. (DLGPROC)GenericDialogProc,
  158. NULL
  159. );
  160. return iKeyPressedByUser;
  161. }
  162. /***************************************************************************************************************
  163. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  164. DESCRIPTION:
  165. sets the genericDialog title string from a string
  166. DATA STRUCTURES:
  167. None.
  168. INPUT:
  169. TCHAR * - Title string for genericDialog
  170. RETURN:
  171. None.
  172. */
  173. void CGenericDialog::SetTitle(TCHAR * tDialogBoxTitle)
  174. {
  175. //assert if tDialogBoxTitle lenght = 0
  176. assert(_tcslen(tDialogBoxTitle) == 0);
  177. _tcscpy(genericDialogTitle, tDialogBoxTitle);
  178. }
  179. /***************************************************************************************************************
  180. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  181. DESCRIPTION:
  182. sets the genericDialog title string from a resource ID
  183. DATA STRUCTURES:
  184. None.
  185. INPUT:
  186. UINT resource ID for the title string
  187. RETURN:
  188. None.
  189. */
  190. void CGenericDialog::SetTitle(UINT uResID)
  191. {
  192. ::LoadString(GetDfrgResHandle(), uResID, genericDialogTitle, sizeof(genericDialogTitle)/sizeof(TCHAR));
  193. //assert if nothing got loaded
  194. assert((_tcslen(genericDialogTitle) > 0));
  195. }
  196. /***************************************************************************************************************
  197. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  198. DESCRIPTION:
  199. sets the button text from a TCHAR string
  200. DATA STRUCTURES:
  201. None.
  202. INPUT:
  203. UINT - Index for the button, must be in the range 0 to 4
  204. TCHAR * - button string
  205. RETURN:
  206. None.
  207. */
  208. void CGenericDialog::SetButtonText(UINT uIndex, TCHAR * tButtonText)
  209. {
  210. //assert if index out of range
  211. assert(uIndex<5);
  212. //assert if tButtonText length = 0
  213. assert(_tcslen(tButtonText) == 0);
  214. //set button to visible
  215. genericButtonArray[uIndex].m_buttonVisible = TRUE;
  216. //copy button text to the button structure
  217. _tcscpy(genericButtonArray[uIndex].m_buttonText, tButtonText);
  218. }
  219. /***************************************************************************************************************
  220. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  221. DESCRIPTION:
  222. sets the button text from a resource ID
  223. DATA STRUCTURES:
  224. None.
  225. INPUT:
  226. UINT - Index for the button, must be in the range 0 to 4
  227. UINT - resource ID for the button string
  228. RETURN:
  229. None.
  230. */
  231. void CGenericDialog::SetButtonText(UINT uIndex, UINT uResID)
  232. {
  233. //assert if index out of range
  234. assert(uIndex<5);
  235. TCHAR tTempButtonString[200];
  236. //set button to visible
  237. genericButtonArray[uIndex].m_buttonVisible = TRUE;
  238. //get the button text from the resource
  239. ::LoadString(GetDfrgResHandle(), uResID, tTempButtonString, sizeof(tTempButtonString)/sizeof(TCHAR));
  240. //assert if tTempButtonString length = 0
  241. assert(_tcslen(tTempButtonString) > 0);
  242. //copy button text to the button structure
  243. _tcscpy(genericButtonArray[uIndex].m_buttonText, tTempButtonString);
  244. }
  245. /***************************************************************************************************************
  246. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  247. DESCRIPTION:
  248. sets the button help using Help Context ID
  249. DATA STRUCTURES:
  250. None.
  251. INPUT:
  252. UINT - Index for the button, must be in the range 0 to 4
  253. DWORD - Help Context ID
  254. RETURN:
  255. None.
  256. */
  257. void CGenericDialog::SetButtonHelp(UINT uIndex, DWORD dHelpContextID)
  258. {
  259. //assert if index out of range
  260. assert(uIndex<5);
  261. //set the contect identifiers
  262. genericHelpIDArray[uIndex].dHelpContextIdentifier = dHelpContextID;
  263. }
  264. /***************************************************************************************************************
  265. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  266. DESCRIPTION:
  267. sets the help file path
  268. DATA STRUCTURES:
  269. None.
  270. INPUT:
  271. TCHAR * - the location of the help file
  272. RETURN:
  273. None.
  274. */
  275. void CGenericDialog::SetHelpFilePath()
  276. {
  277. _tcscpy(genericHelpFilePath, GetHelpFilePath());
  278. }
  279. /***************************************************************************************************************
  280. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  281. DESCRIPTION:
  282. This changes the ICON for the genericdialog
  283. DATA STRUCTURES:
  284. None.
  285. INPUT:
  286. UINT - resource ID for the Icon
  287. RETURN:
  288. None.
  289. */
  290. void CGenericDialog::SetIcon(UINT uResID)
  291. {
  292. bIsIconVisible = TRUE;
  293. hgenericDialogIcon = LoadImage(
  294. GetDfrgResHandle(), // handle of the instance containing the image
  295. MAKEINTRESOURCE(uResID), // name or identifier of image
  296. IMAGE_ICON, // type of image
  297. 0, // desired width
  298. 0, // desired height
  299. LR_DEFAULTSIZE // load flags
  300. );
  301. assert(hgenericDialogIcon);
  302. }
  303. /***************************************************************************************************************
  304. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  305. DESCRIPTION:
  306. sets the text for the EditBox
  307. DATA STRUCTURES:
  308. None.
  309. INPUT:
  310. TCHAR * - string for the EditBox
  311. RETURN:
  312. None.
  313. */
  314. void CGenericDialog::SetText(TCHAR * tEditBoxText)
  315. {
  316. //assert if tEditBoxText length = 0
  317. assert(_tcslen(tEditBoxText) > 0 && _tcslen(tEditBoxText)<1025);
  318. _tcscpy(genericEditBoxText, tEditBoxText);
  319. }
  320. /***************************************************************************************************************
  321. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  322. DESCRIPTION:
  323. sets the text for the EditBox
  324. DATA STRUCTURES:
  325. None.
  326. INPUT:
  327. UINT - resource ID for the editBox text
  328. RETURN:
  329. None.
  330. */
  331. void CGenericDialog::SetText(UINT uResID)
  332. {
  333. TCHAR tTempEditBoxString[1024];
  334. //get the editbox text from the resource
  335. ::LoadString(GetDfrgResHandle(), uResID, tTempEditBoxString, sizeof(tTempEditBoxString)/sizeof(TCHAR));
  336. //assert if tTempEditBoxString length = 0
  337. assert(_tcslen(tTempEditBoxString) > 0);
  338. //copy button text to the button structure
  339. _tcscpy(genericEditBoxText, tTempEditBoxString);
  340. }
  341. /*****************************************************************************************************************
  342. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  343. ROUTINE DESCRIPTION:
  344. The Report dialog callback
  345. INPUT:
  346. IN HWND hWndDialog, - handle to dialog
  347. IN UINT uMessage, - window message
  348. IN WPARAM wParam, - message flags
  349. IN LPARAM lParam - message flags
  350. RETURN:
  351. TRUE - processed message
  352. FALSE - message not processed.
  353. */
  354. BOOL CALLBACK
  355. GenericDialogProc(
  356. IN HWND hWndDialog,
  357. IN UINT uMessage,
  358. IN WPARAM wParam,
  359. IN LPARAM lParam
  360. )
  361. {
  362. switch(uMessage) {
  363. case WM_INITDIALOG:
  364. if(!InitializeGenericDialog(hWndDialog)) {
  365. ExitAnalyzeDone(hWndDialog);
  366. }
  367. break;
  368. case WM_CLOSE:
  369. iKeyPressedByUser = 9999999; //make it this value so that I will not act like a zero
  370. ExitAnalyzeDone(hWndDialog);
  371. break;
  372. case WM_SIZE:
  373. break;
  374. case WM_EXITSIZEMOVE:
  375. ResizeDialog(hWndDialog);
  376. break;
  377. case WM_COMMAND:
  378. switch(LOWORD(wParam)) {
  379. case ID_GENERIC_BUTTON0:
  380. iKeyPressedByUser = 0;
  381. ExitAnalyzeDone(hWndDialog);
  382. break;
  383. case ID_GENERIC_BUTTON1:
  384. iKeyPressedByUser = 1;
  385. ExitAnalyzeDone(hWndDialog);
  386. break;
  387. case ID_GENERIC_BUTTON2:
  388. iKeyPressedByUser = 2;
  389. ExitAnalyzeDone(hWndDialog);
  390. break;
  391. case ID_GENERIC_BUTTON3:
  392. iKeyPressedByUser = 3;
  393. ExitAnalyzeDone(hWndDialog);
  394. break;
  395. case ID_GENERIC_BUTTON4:
  396. iKeyPressedByUser = 4;
  397. ExitAnalyzeDone(hWndDialog);
  398. break;
  399. default:
  400. return FALSE;
  401. }
  402. break;
  403. case WM_HELP:
  404. if(((int)((LPHELPINFO)lParam)->iCtrlId != IDC_STATIC_TEXT) && ((int)((LPHELPINFO)lParam)->iCtrlId != IDC_STATIC_TEXT2)){
  405. EF(WinHelp ((HWND)((LPHELPINFO)lParam)->hItemHandle, genericHelpFilePath, HELP_WM_HELP, (DWORD_PTR)genericHelpIDArray));
  406. }
  407. break;
  408. case WM_CONTEXTMENU:
  409. switch(GetDlgCtrlID((HWND)wParam)){
  410. case 0:
  411. case IDC_STATIC_TEXT:
  412. case IDC_STATIC_TEXT2:
  413. break;
  414. default:
  415. WinHelp (hWndDialog, genericHelpFilePath, HELP_CONTEXTMENU, (DWORD_PTR)genericHelpIDArray);
  416. break;
  417. }
  418. break;
  419. default:
  420. return FALSE;
  421. }
  422. return TRUE;
  423. }
  424. /***************************************************************************************************************
  425. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  426. DESCRIPTION:
  427. This function initializes data for the report dialog box
  428. DATA STRUCTURES:
  429. None.
  430. INPUT:
  431. hWndDialog - handle to the dialog box
  432. RETURN:
  433. TRUE = success
  434. FALSE = error
  435. */
  436. BOOL
  437. InitializeGenericDialog(
  438. IN HWND hWndDialog
  439. )
  440. {
  441. RECT rDlg, rect;
  442. HDC hDC = GetDC(hWndDialog);
  443. ZeroMemory(&rect, sizeof(RECT));
  444. //set the dialog box title
  445. SetWindowText(hWndDialog, genericDialogTitle);
  446. GetWindowRect(GetDlgItem(hWndDialog, IDC_GENERIC_EDITBOX), &rButton);
  447. GetWindowRect(hWndDialog, &rDlg);
  448. // set up the font
  449. NONCLIENTMETRICS ncm;
  450. ncm.cbSize = sizeof(ncm);
  451. ::SystemParametersInfo (SPI_GETNONCLIENTMETRICS, sizeof (ncm), &ncm, 0);
  452. ncm.lfStatusFont.lfWeight = FW_NORMAL;
  453. hDlgFont = ::CreateFontIndirect(&ncm.lfStatusFont);
  454. //set the font for the edit box
  455. SendDlgItemMessage(hWndDialog, IDC_GENERIC_EDITBOX, WM_SETFONT, (WPARAM) hDlgFont, 0L);
  456. //set the font for the buttons
  457. SendDlgItemMessage(hWndDialog, ID_GENERIC_BUTTON0, WM_SETFONT, (WPARAM) hDlgFont, 0L);
  458. SendDlgItemMessage(hWndDialog, ID_GENERIC_BUTTON1, WM_SETFONT, (WPARAM) hDlgFont, 0L);
  459. SendDlgItemMessage(hWndDialog, ID_GENERIC_BUTTON2, WM_SETFONT, (WPARAM) hDlgFont, 0L);
  460. SendDlgItemMessage(hWndDialog, ID_GENERIC_BUTTON3, WM_SETFONT, (WPARAM) hDlgFont, 0L);
  461. SendDlgItemMessage(hWndDialog, ID_GENERIC_BUTTON4, WM_SETFONT, (WPARAM) hDlgFont, 0L);
  462. VString dlgText;
  463. dlgText.Empty();
  464. dlgText += (LPCTSTR)genericEditBoxText;
  465. wFontHeight = -ncm.lfCaptionFont.lfHeight;
  466. rect.left = 0;
  467. rect.right = wFontHeight * 20;
  468. rect.top = 0;
  469. rect.bottom = 0;
  470. if (dlgText.GetLength()) {
  471. DrawTextEx(hDC, dlgText.GetBuffer(), -1, &rect, DT_CALCRECT, NULL);
  472. }
  473. wEditBoxWidth = __max((rect.right - rect.left), (wFontHeight * 20)) ;
  474. wEditBoxHeight = __max((rect.bottom - rect.top), (wFontHeight * (FindMaxEditboxStringHeight(dlgText) + 1)));
  475. //check for minimum size of the edit box
  476. m_ButtonTopBottomSpacer = wFontHeight;
  477. m_Margin = wFontHeight;
  478. SetButtonsandIcon(hWndDialog);
  479. SizeButtons(hWndDialog);
  480. // Resize the dialog box so it extends just past the
  481. // ID_MORE button vertically. Keep the upper left
  482. // coordinates and the width the same.
  483. rDlg.bottom = rDlg.top + wEditBoxHeight+ (2 * m_ButtonTopBottomSpacer) +
  484. (adjustedButtonHeight * 2) + ncm.iMenuHeight;
  485. rDlg.right = rDlg.left + wEditBoxWidth + iconSize + 3 * m_Margin;
  486. //calculate to final size of the dialog and adjust if necessary
  487. UINT dialogBoxFinalWidth = rDlg.right - rDlg.left;// + 3 * m_Margin + iconSize;
  488. UINT dialogBoxFinalHeight = rDlg.bottom - rDlg.top;
  489. dialogBoxFinalWidth = __max(dialogBoxFinalWidth,minimumDialogWidth);
  490. dialogBoxFinalHeight = __max(dialogBoxFinalHeight,minimumDialogHeight);
  491. m_ButtonFloat = (dialogBoxFinalWidth - totalButtonWidth) / 2;
  492. //move the icon
  493. MoveWindow(GetDlgItem(hWndDialog, IDC_GENERIC_ICON), m_Margin, m_ButtonTopBottomSpacer, iconSize, iconSize, TRUE);
  494. //resize the edit box
  495. MoveWindow(GetDlgItem(hWndDialog, IDC_GENERIC_EDITBOX), 2 * m_Margin + iconSize, m_ButtonTopBottomSpacer, wEditBoxWidth, wEditBoxHeight, TRUE);
  496. InvalidateRect(GetDlgItem(hWndDialog, IDC_GENERIC_EDITBOX), // handle of window with changed update region
  497. &rDlg, // address of rectangle coordinates
  498. TRUE // erase-background flag
  499. );
  500. // write the defrag recommendation
  501. SetDlgItemText(hWndDialog, IDC_GENERIC_EDITBOX, dlgText.GetBuffer());
  502. //resize the dialog
  503. MoveWindow(hWndDialog, rDlg.left, rDlg.top, dialogBoxFinalWidth, dialogBoxFinalHeight, TRUE);
  504. GetWindowRect(hWndDialog, &rDlg);
  505. PositionButtons(hWndDialog, rDlg);
  506. //save the original dimensions of the dialog
  507. GetWindowRect(hWndDialog, &rcOriginalDialogSize);
  508. ReleaseDC(hWndDialog, hDC); // handle to device context
  509. return TRUE;
  510. }
  511. /***************************************************************************************************************
  512. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  513. DESCRIPTION:
  514. This function deallocate resources for the report dialog
  515. DATA STRUCTURES:
  516. None.
  517. INPUT:
  518. hWndDialog - handle to the dialog box
  519. RETURN:
  520. None.
  521. */
  522. void
  523. ExitAnalyzeDone(
  524. IN HWND hWndDialog
  525. )
  526. {
  527. ::DeleteObject(hDlgFont);
  528. EndDialog(hWndDialog, 0);
  529. }
  530. /***************************************************************************************************************
  531. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  532. DESCRIPTION:
  533. This method hides/shows the buttons on the dialog according to the values in genericButtonArray structure.
  534. It also loads the text into the buttons from the same structure.
  535. DATA STRUCTURES:
  536. genericButton structure.
  537. INPUT:
  538. hWndDialog - handle to the dialog box
  539. RETURN:
  540. None.
  541. */
  542. void SetButtonsandIcon(HWND hWndDialog)
  543. {
  544. if(!bIsIconVisible)
  545. {
  546. ::ShowWindow(GetDlgItem(hWndDialog, IDC_GENERIC_ICON),SW_HIDE);
  547. } else
  548. {
  549. GetWindowRect(GetDlgItem(hWndDialog, IDC_GENERIC_ICON), &rcIcon);
  550. iconSize = rcIcon.right - rcIcon.left;
  551. DrawIconOnDialog(hWndDialog);
  552. }
  553. if(!genericButtonArray[0].m_buttonVisible)
  554. {
  555. ::ShowWindow(GetDlgItem(hWndDialog, ID_GENERIC_BUTTON0),SW_HIDE);
  556. } else
  557. {
  558. SetWindowText(GetDlgItem(hWndDialog, ID_GENERIC_BUTTON0), genericButtonArray[0].m_buttonText );
  559. }
  560. if(!genericButtonArray[1].m_buttonVisible)
  561. {
  562. ::ShowWindow(GetDlgItem(hWndDialog, ID_GENERIC_BUTTON1),SW_HIDE);
  563. }else
  564. {
  565. SetWindowText(GetDlgItem(hWndDialog, ID_GENERIC_BUTTON1), genericButtonArray[1].m_buttonText );
  566. }
  567. if(!genericButtonArray[2].m_buttonVisible)
  568. {
  569. ::ShowWindow(GetDlgItem(hWndDialog, ID_GENERIC_BUTTON2),SW_HIDE);
  570. }else
  571. {
  572. SetWindowText(GetDlgItem(hWndDialog, ID_GENERIC_BUTTON2), genericButtonArray[2].m_buttonText );
  573. }
  574. if(!genericButtonArray[3].m_buttonVisible)
  575. {
  576. ::ShowWindow(GetDlgItem(hWndDialog, ID_GENERIC_BUTTON3),SW_HIDE);
  577. }else
  578. {
  579. SetWindowText(GetDlgItem(hWndDialog, ID_GENERIC_BUTTON3), genericButtonArray[3].m_buttonText );
  580. }
  581. if(!genericButtonArray[4].m_buttonVisible)
  582. {
  583. ::ShowWindow(GetDlgItem(hWndDialog, ID_GENERIC_BUTTON4),SW_HIDE);
  584. }else
  585. {
  586. SetWindowText(GetDlgItem(hWndDialog, ID_GENERIC_BUTTON4), genericButtonArray[4].m_buttonText );
  587. }
  588. }
  589. /***************************************************************************************************************
  590. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  591. DESCRIPTION:
  592. This method finds the longest string inside the VString terminated by a \n
  593. DATA STRUCTURES:
  594. genericButton structure.
  595. INPUT:
  596. VString - string in the editbox
  597. RETURN:
  598. Longest line in the editbox terminated by a \n.
  599. */
  600. UINT FindMaxEditboxStringWidth(VString vstring)
  601. {
  602. int iLongestLine = 0, iEndofString = 0, iCurrentSearchLocation = 0;
  603. iEndofString = vstring.GetLength();
  604. if(iEndofString == 0) //oops no string return 0
  605. {
  606. return(0);
  607. }
  608. while(iCurrentSearchLocation < iEndofString)
  609. {
  610. iCurrentSearchLocation = vstring.Find((LPTSTR)TEXT("\n"));
  611. if(iCurrentSearchLocation == -1) //I didnt find any more
  612. {
  613. if (iLongestLine == 0) {
  614. iLongestLine = iEndofString;
  615. }
  616. break;
  617. }
  618. if(iCurrentSearchLocation > iLongestLine)
  619. {
  620. iLongestLine = iCurrentSearchLocation;
  621. }
  622. vstring = vstring.Mid(iCurrentSearchLocation+1); //sub string the original chopping off the front
  623. iEndofString = vstring.GetLength();
  624. iCurrentSearchLocation = 0;
  625. }
  626. return(iLongestLine);
  627. }
  628. /***************************************************************************************************************
  629. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  630. DESCRIPTION:
  631. This method counts the number of \n inside the VString for the editbox
  632. DATA STRUCTURES:
  633. genericButton structure.
  634. INPUT:
  635. VString - editbox string
  636. RETURN:
  637. Number of lines in the editbox.
  638. */
  639. UINT FindMaxEditboxStringHeight(VString vstring)
  640. {
  641. int iNumberofLines = 0, iEndofString = 0, iCurrentSearchLocation = 0;
  642. iEndofString = vstring.GetLength();
  643. if(iEndofString == 0) //oops no string return 0
  644. {
  645. return(0);
  646. }
  647. while(iCurrentSearchLocation < iEndofString)
  648. {
  649. iCurrentSearchLocation = vstring.Find((LPTSTR)TEXT("\n"));
  650. if(iCurrentSearchLocation == -1) //I didnt find any more
  651. {
  652. break;
  653. }
  654. iNumberofLines++;
  655. vstring = vstring.Mid(iCurrentSearchLocation+1); //sub string the original chopping off the front
  656. iEndofString = vstring.GetLength();
  657. iCurrentSearchLocation = 0;
  658. }
  659. return(++iNumberofLines); //add 1 more since the last line does not have a \n
  660. }
  661. /***************************************************************************************************************
  662. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  663. DESCRIPTION:
  664. This method resizes the buttons
  665. DATA STRUCTURES:
  666. genericButton structure.
  667. INPUT:
  668. hWndDialog - handle to the dialog box
  669. RETURN:
  670. None.
  671. */
  672. void SizeButtons(HWND hWndDialog)
  673. {
  674. HDC OutputDC = GetDC(hWndDialog);
  675. EV_ASSERT(OutputDC);
  676. HDC WorkDC = ::CreateCompatibleDC(OutputDC);
  677. EV_ASSERT(WorkDC);
  678. ::SelectObject(WorkDC, hDlgFont);
  679. const bigButtonSpacer = 20;
  680. adjustedButtonHeight = __max((UINT)(1.5 * wFontHeight), m_ButtonHeight);
  681. //need to know the total width of the buttons before setting location
  682. totalButtonWidth = 0;
  683. if(genericButtonArray[0].m_buttonVisible)
  684. {
  685. adjustedButtonWidth0 = __max(m_ButtonSpacer + GetStringWidth(genericButtonArray[0].m_buttonText, WorkDC), m_ButtonWidth);
  686. totalButtonWidth += adjustedButtonWidth0 + m_ButtonSpacer;
  687. }
  688. if(genericButtonArray[1].m_buttonVisible)
  689. {
  690. adjustedButtonWidth1 = __max(m_ButtonSpacer + GetStringWidth(genericButtonArray[1].m_buttonText, WorkDC), m_ButtonWidth);
  691. totalButtonWidth += adjustedButtonWidth1 + m_ButtonSpacer;
  692. }
  693. if(genericButtonArray[2].m_buttonVisible)
  694. {
  695. adjustedButtonWidth2 = __max(m_ButtonSpacer + GetStringWidth(genericButtonArray[2].m_buttonText, WorkDC), m_ButtonWidth);
  696. totalButtonWidth += adjustedButtonWidth2 + m_ButtonSpacer;
  697. }
  698. if(genericButtonArray[3].m_buttonVisible)
  699. {
  700. adjustedButtonWidth3 = __max(m_ButtonSpacer + GetStringWidth(genericButtonArray[3].m_buttonText, WorkDC), m_ButtonWidth);
  701. totalButtonWidth += adjustedButtonWidth3 + m_ButtonSpacer;
  702. }
  703. if(genericButtonArray[4].m_buttonVisible)
  704. {
  705. adjustedButtonWidth4 = __max(m_ButtonSpacer + GetStringWidth(genericButtonArray[4].m_buttonText, WorkDC), m_ButtonWidth);
  706. totalButtonWidth += adjustedButtonWidth4 + m_ButtonSpacer;
  707. }
  708. minimumDialogWidth = __max(minimumDialogWidth,totalButtonWidth + m_ButtonSpacer*2);
  709. ReleaseDC(hWndDialog, OutputDC); // handle to device context
  710. DeleteDC(WorkDC); // handle to device context
  711. }
  712. /***************************************************************************************************************
  713. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  714. DESCRIPTION:
  715. This method resizes the buttons
  716. DATA STRUCTURES:
  717. genericButton structure.
  718. INPUT:
  719. hWndDialog - handle to the dialog box
  720. RETURN:
  721. None.
  722. */
  723. void PositionButtons(HWND hWndDialog, RECT rDlg)
  724. {
  725. HDC OutputDC = GetDC(hWndDialog);
  726. EV_ASSERT(OutputDC);
  727. HDC WorkDC = ::CreateCompatibleDC(OutputDC);
  728. EV_ASSERT(WorkDC);
  729. ::SelectObject(WorkDC, hDlgFont);
  730. // Calculate Button0 position and size.
  731. if(genericButtonArray[0].m_buttonVisible)
  732. {
  733. rcButton0.right = rDlg.right - rDlg.left - m_ButtonFloat;
  734. rcButton0.left = rcButton0.right - adjustedButtonWidth0;
  735. rcButton0.bottom = rDlg.bottom - rDlg.top - (1.50 * adjustedButtonHeight);
  736. rcButton0.top = rcButton0.bottom - adjustedButtonHeight;
  737. PositionButton(&rcButton0,GetDlgItem(hWndDialog, ID_GENERIC_BUTTON0));
  738. }
  739. if(genericButtonArray[1].m_buttonVisible)
  740. {
  741. rcButton1.right = rcButton0.left - m_ButtonSpacer;
  742. rcButton1.left = rcButton1.right - adjustedButtonWidth1;
  743. rcButton1.bottom = rDlg.bottom - rDlg.top - (1.50 * adjustedButtonHeight);
  744. rcButton1.top = rcButton1.bottom - adjustedButtonHeight;
  745. PositionButton(&rcButton1,GetDlgItem(hWndDialog, ID_GENERIC_BUTTON1));
  746. }
  747. if(genericButtonArray[2].m_buttonVisible)
  748. {
  749. rcButton2.right = rcButton1.left - m_ButtonSpacer;
  750. rcButton2.left = rcButton2.right - adjustedButtonWidth2;
  751. rcButton2.bottom = rDlg.bottom - rDlg.top - (1.50 * adjustedButtonHeight);
  752. rcButton2.top = rcButton2.bottom - adjustedButtonHeight;
  753. PositionButton(&rcButton2,GetDlgItem(hWndDialog, ID_GENERIC_BUTTON2));
  754. }
  755. if(genericButtonArray[3].m_buttonVisible)
  756. {
  757. rcButton3.right = rcButton2.left - m_ButtonSpacer;
  758. rcButton3.left = rcButton3.right - adjustedButtonWidth3;
  759. rcButton3.bottom = rDlg.bottom - rDlg.top - (1.50 * adjustedButtonHeight);
  760. rcButton3.top = rcButton3.bottom - adjustedButtonHeight;
  761. PositionButton(&rcButton3,GetDlgItem(hWndDialog, ID_GENERIC_BUTTON3));
  762. }
  763. if(genericButtonArray[4].m_buttonVisible)
  764. {
  765. rcButton4.right = rcButton3.left - m_ButtonSpacer;
  766. rcButton4.left = rcButton4.right - adjustedButtonWidth4;
  767. rcButton4.bottom = rDlg.bottom - rDlg.top - (1.50 * adjustedButtonHeight);
  768. rcButton4.top = rcButton4.bottom - adjustedButtonHeight;
  769. PositionButton(&rcButton4,GetDlgItem(hWndDialog, ID_GENERIC_BUTTON4));
  770. }
  771. ::DeleteDC(WorkDC);
  772. EH_ASSERT(ReleaseDC(hWndDialog, OutputDC));
  773. }
  774. /***************************************************************************************************************
  775. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  776. DESCRIPTION:
  777. This method repositions the buttons
  778. DATA STRUCTURES:
  779. genericButton structure.
  780. INPUT:
  781. hWndDialog - handle to the dialog box
  782. RECT - Defining the location of where the button is going
  783. RETURN:
  784. None.
  785. */
  786. void PositionButton(RECT* prcPos, HWND hWndDialog)
  787. {
  788. if (hWndDialog != NULL){
  789. MoveWindow(hWndDialog,
  790. prcPos->left,
  791. prcPos->top,
  792. prcPos->right - prcPos->left,
  793. prcPos->bottom - prcPos->top,
  794. TRUE);
  795. }
  796. }
  797. /***************************************************************************************************************
  798. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  799. DESCRIPTION:
  800. This method finds the longest string inside the VString terminated by a \n
  801. DATA STRUCTURES:
  802. genericButton structure.
  803. INPUT:
  804. PTCHAR - buffer that contains the string
  805. HDC - Handle to a device context (DC) on the screen.
  806. RETURN:
  807. Width of the character.
  808. */
  809. UINT GetStringWidth(PTCHAR stringBuf, HDC WorkDC)
  810. {
  811. if (!stringBuf){
  812. return 0;
  813. }
  814. UINT iStringWidth = 0;
  815. int iCharWidth;
  816. for (UINT i=0; i<_tcslen(stringBuf); i++){
  817. ::GetCharWidth32(
  818. WorkDC,
  819. stringBuf[i],
  820. stringBuf[i],
  821. &iCharWidth);
  822. iStringWidth += iCharWidth;
  823. }
  824. return iStringWidth;
  825. }
  826. /***************************************************************************************************************
  827. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  828. DESCRIPTION:
  829. This method resizes the dialog in response to the user resizing the dialog
  830. DATA STRUCTURES:
  831. None.
  832. INPUT:
  833. None.
  834. RETURN:
  835. None.
  836. */
  837. void ResizeDialog(HWND hWndDialog)
  838. {
  839. UINT dialogBoxFinalWidth;
  840. UINT dialogBoxFinalHeight;
  841. //get the new dimensions of the dialog
  842. GetWindowRect(hWndDialog, &rcNewDialogSize);
  843. if((rcNewDialogSize.bottom - rcNewDialogSize.top) < (rcOriginalDialogSize.bottom - rcOriginalDialogSize.top) ||
  844. (rcNewDialogSize.right - rcNewDialogSize.left) < (rcOriginalDialogSize.right - rcOriginalDialogSize.left))
  845. {
  846. dialogBoxFinalWidth = rcOriginalDialogSize.right - rcOriginalDialogSize.left;
  847. dialogBoxFinalHeight = rcOriginalDialogSize.bottom - rcOriginalDialogSize.top;
  848. //set back to original size
  849. MoveWindow(hWndDialog, rcOriginalDialogSize.left, rcOriginalDialogSize.top, dialogBoxFinalWidth, dialogBoxFinalHeight, TRUE);
  850. return;
  851. }
  852. //if its not smaller, it must be bigger or the same, no matter, reposition the stuff
  853. m_ButtonFloat = ((rcNewDialogSize.right - rcNewDialogSize.left) - totalButtonWidth) / 2;
  854. PositionButtons(hWndDialog, rcNewDialogSize);
  855. InvalidateRect(
  856. hWndDialog, // handle of window with changed update region
  857. &rcNewDialogSize, // address of rectangle coordinates
  858. TRUE // erase-background flag
  859. );
  860. }
  861. /***************************************************************************************************************
  862. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  863. DESCRIPTION:
  864. This changes the ICON for the genericdialog
  865. DATA STRUCTURES:
  866. None.
  867. INPUT:
  868. hWndDialog - handle to the dialog box
  869. RETURN:
  870. None.
  871. */
  872. void DrawIconOnDialog(HWND hWndDialog)
  873. {
  874. ::SendDlgItemMessage(hWndDialog, //dialog box handle
  875. IDC_GENERIC_ICON, //icon identifier
  876. STM_SETIMAGE, //message to send
  877. (WPARAM) IMAGE_ICON, //image type
  878. (LPARAM) hgenericDialogIcon // icon handle
  879. );
  880. }