Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

976 lines
25 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. fddlgs.c
  5. Abstract:
  6. Dialog routines and dialog support subroutines.
  7. Author:
  8. Ted Miller (tedm) 7-Jan-1992
  9. --*/
  10. #include "fdisk.h"
  11. // used in color dialog to indicate what the user has chosen for
  12. // the various graph element types
  13. DWORD SelectedColor[LEGEND_STRING_COUNT];
  14. DWORD SelectedHatch[LEGEND_STRING_COUNT];
  15. // used in color dialog, contains element (ie, partition, logical volume,
  16. // etc) we're selecting for (ie, which item is diaplyed in static text of
  17. // combo box).
  18. DWORD CurrentElement;
  19. // handle of active color dialogs box. Used by rectangle custom control.
  20. HWND hDlgColor;
  21. BOOL
  22. InitColorDlg(
  23. IN HWND hdlg
  24. );
  25. VOID
  26. CenterDialog(
  27. HWND hwnd
  28. )
  29. /*++
  30. Routine Description:
  31. Centers a dialog relative to the app's main window
  32. Arguments:
  33. hwnd - window handle of dialog to center
  34. Return Value:
  35. None.
  36. --*/
  37. {
  38. RECT rcFrame,
  39. rcWindow;
  40. LONG x,
  41. y,
  42. w,
  43. h;
  44. POINT point;
  45. LONG sx = GetSystemMetrics(SM_CXSCREEN),
  46. sy = GetSystemMetrics(SM_CYSCREEN);
  47. point.x = point.y = 0;
  48. ClientToScreen(hwndFrame,&point);
  49. GetWindowRect (hwnd ,&rcWindow);
  50. GetClientRect (hwndFrame,&rcFrame );
  51. w = rcWindow.right - rcWindow.left + 1;
  52. h = rcWindow.bottom - rcWindow.top + 1;
  53. x = point.x + ((rcFrame.right - rcFrame.left + 1 - w) / 2);
  54. y = point.y + ((rcFrame.bottom - rcFrame.top + 1 - h) / 2);
  55. if (x + w > sx) {
  56. x = sx - w;
  57. } else if (x < 0) {
  58. x = 0;
  59. }
  60. if (y + h > sy) {
  61. y = sy - h;
  62. } else if (y < 0) {
  63. y = 0;
  64. }
  65. MoveWindow(hwnd,x,y,w,h,FALSE);
  66. }
  67. BOOL CALLBACK
  68. MinMaxDlgProc(
  69. IN HWND hwnd,
  70. IN UINT msg,
  71. IN WPARAM wParam,
  72. IN LPARAM lParam
  73. )
  74. /*++
  75. Routine Description:
  76. Dialog procedure for the enter size dialog box. This dialog
  77. allows the user to enter a size for a partition, or use
  78. spin controls (a tiny scroll bar) to select the size.
  79. Possible outcomes are cancel or OK. In the latter case the
  80. EndDialog code is the size. In the former it is 0.
  81. Arguments:
  82. hwnd - window handle of dialog box
  83. msg - message #
  84. wParam - msg specific data
  85. lParam - msg specific data
  86. Return Value:
  87. msg dependent
  88. --*/
  89. {
  90. TCHAR outputString[MESSAGE_BUFFER_SIZE];
  91. PMINMAXDLG_PARAMS params;
  92. BOOL validNumber;
  93. DWORD sizeMB;
  94. static DWORD minSizeMB,
  95. maxSizeMB,
  96. helpContextId;
  97. switch (msg) {
  98. case WM_INITDIALOG:
  99. CenterDialog(hwnd);
  100. params = (PMINMAXDLG_PARAMS)lParam;
  101. // set up caption
  102. LoadString(hModule, params->CaptionStringID, outputString, sizeof(outputString)/sizeof(TCHAR));
  103. SetWindowText(hwnd, outputString);
  104. // set up minimum/maximum text
  105. LoadString(hModule, params->MinimumStringID, outputString, sizeof(outputString)/sizeof(TCHAR));
  106. SetDlgItemText(hwnd, IDC_MINMAX_MINLABEL, outputString);
  107. LoadString(hModule, params->MaximumStringID, outputString, sizeof(outputString)/sizeof(TCHAR));
  108. SetDlgItemText(hwnd, IDC_MINMAX_MAXLABEL, outputString);
  109. LoadString(hModule, params->SizeStringID, outputString, sizeof(outputString)/sizeof(TCHAR));
  110. SetDlgItemText(hwnd, IDC_MINMAX_SIZLABEL, outputString);
  111. minSizeMB = params->MinSizeMB;
  112. maxSizeMB = params->MaxSizeMB;
  113. helpContextId = params->HelpContextId;
  114. wsprintf(outputString, TEXT("%u"), minSizeMB);
  115. SetDlgItemText(hwnd, IDC_MINMAX_MIN, outputString);
  116. wsprintf(outputString, TEXT("%u"), maxSizeMB);
  117. SetDlgItemText(hwnd, IDC_MINMAX_MAX, outputString);
  118. // also put the size in the edit control and select the text
  119. wsprintf(outputString, TEXT("%u"), maxSizeMB);
  120. SetDlgItemText(hwnd, IDC_MINMAX_SIZE, outputString);
  121. SendDlgItemMessage(hwnd, IDC_MINMAX_SIZE, EM_SETSEL, 0, -1);
  122. SetFocus(GetDlgItem(hwnd, IDC_MINMAX_SIZE));
  123. return FALSE; // indicate focus set to a control
  124. case WM_VSCROLL:
  125. switch (LOWORD(wParam)) {
  126. case SB_LINEDOWN:
  127. case SB_LINEUP:
  128. sizeMB = GetDlgItemInt(hwnd, IDC_MINMAX_SIZE, &validNumber, FALSE);
  129. if (!validNumber) {
  130. Beep(500,100);
  131. } else {
  132. if (((sizeMB > minSizeMB) && (LOWORD(wParam) == SB_LINEDOWN))
  133. || ((sizeMB < maxSizeMB) && (LOWORD(wParam) == SB_LINEUP )))
  134. {
  135. if (sizeMB > maxSizeMB) {
  136. sizeMB = maxSizeMB;
  137. } else if (LOWORD(wParam) == SB_LINEUP) {
  138. sizeMB++;
  139. } else {
  140. sizeMB--;
  141. }
  142. wsprintf(outputString, TEXT("%u"), sizeMB);
  143. SetDlgItemText(hwnd, IDC_MINMAX_SIZE, outputString);
  144. SendDlgItemMessage(hwnd, IDC_MINMAX_SIZE, EM_SETSEL, 0, -1);
  145. } else {
  146. Beep(500,100);
  147. }
  148. }
  149. }
  150. break;
  151. case WM_COMMAND:
  152. switch (LOWORD(wParam)) {
  153. case IDOK:
  154. sizeMB = GetDlgItemInt(hwnd, IDC_MINMAX_SIZE, &validNumber, FALSE);
  155. if (!validNumber || !sizeMB || (sizeMB > maxSizeMB) || (sizeMB < minSizeMB)) {
  156. ErrorDialog(MSG_INVALID_SIZE);
  157. } else {
  158. EndDialog(hwnd, sizeMB);
  159. }
  160. break;
  161. case IDCANCEL:
  162. EndDialog(hwnd, 0);
  163. break;
  164. case FD_IDHELP:
  165. DialogHelp(helpContextId);
  166. break;
  167. default:
  168. return FALSE;
  169. }
  170. break;
  171. default:
  172. return FALSE;
  173. }
  174. return TRUE;
  175. }
  176. BOOL CALLBACK
  177. DriveLetterDlgProc(
  178. IN HWND hdlg,
  179. IN UINT msg,
  180. IN WPARAM wParam,
  181. IN LPARAM lParam
  182. )
  183. /*++
  184. Routine Description:
  185. Dialog for allowing the user to select a drive letter for a
  186. partition, logical drive, volume set, or stripe set.
  187. The EndDialog codes are as follows:
  188. 0 - user cancelled
  189. NO_DRIVE_LETTER_EVER - user opted not to assign a drive letter
  190. other - the drive letter chosen by the user
  191. Arguments:
  192. hdlg - window handle of dialog box
  193. msg - message #
  194. wParam - msg specific data
  195. lParam - msg specific data
  196. Return Value:
  197. msg dependent
  198. --*/
  199. {
  200. static HWND hwndCombo;
  201. static DWORD currentSelection;
  202. TCHAR driveLetter;
  203. TCHAR driveLetterString[3];
  204. DWORD defRadioButton,
  205. selection;
  206. PREGION_DESCRIPTOR regionDescriptor;
  207. PFT_OBJECT ftObject;
  208. TCHAR description[256];
  209. switch (msg) {
  210. case WM_INITDIALOG:
  211. // lParam points to the region descriptor
  212. regionDescriptor = (PREGION_DESCRIPTOR)lParam;
  213. FDASSERT(DmSignificantRegion(regionDescriptor));
  214. hwndCombo = GetDlgItem(hdlg,IDC_DRIVELET_COMBOBOX);
  215. CenterDialog(hdlg);
  216. // Add each available drive letter to the list of available
  217. // drive letters.
  218. driveLetterString[1] = TEXT(':');
  219. driveLetterString[2] = 0;
  220. for (driveLetter='C'; driveLetter <= 'Z'; driveLetter++) {
  221. if (DriveLetterIsAvailable((CHAR)driveLetter)) {
  222. *driveLetterString = driveLetter;
  223. SendMessage(hwndCombo, CB_ADDSTRING, 0, (LONG)driveLetterString);
  224. }
  225. }
  226. // Format the description of the partition.
  227. if (ftObject = GET_FT_OBJECT(regionDescriptor)) {
  228. TCHAR descr[256];
  229. DWORD resid = 0;
  230. // Ft. Description is something like "Stripe set with parity #0"
  231. switch (ftObject->Set->Type) {
  232. case Mirror:
  233. resid = IDS_DLGCAP_MIRROR;
  234. break;
  235. case Stripe:
  236. resid = IDS_STATUS_STRIPESET;
  237. break;
  238. case StripeWithParity:
  239. resid = IDS_DLGCAP_PARITY;
  240. break;
  241. case VolumeSet:
  242. resid = IDS_STATUS_VOLUMESET;
  243. break;
  244. default:
  245. FDASSERT(FALSE);
  246. }
  247. LoadString(hModule, resid, descr, sizeof(descr)/sizeof(TCHAR));
  248. wsprintf(description, descr, ftObject->Set->Ordinal);
  249. } else {
  250. // Non-ft. Description is something like '500 MB Unformatted
  251. // logical drive on disk 3' or '400 MB HPFS partition on disk 4'
  252. LPTSTR args[4];
  253. TCHAR sizeStr[20],
  254. partTypeStr[100],
  255. diskNoStr[10],
  256. typeName[150];
  257. TCHAR formatString[256];
  258. args[0] = sizeStr;
  259. args[1] = typeName;
  260. args[2] = partTypeStr;
  261. args[3] = diskNoStr;
  262. wsprintf(sizeStr, "%u", regionDescriptor->SizeMB);
  263. wsprintf(typeName, "%ws", PERSISTENT_DATA(regionDescriptor)->TypeName);
  264. LoadString(hModule, regionDescriptor->RegionType == REGION_LOGICAL ? IDS_LOGICALVOLUME : IDS_PARTITION, partTypeStr, sizeof(partTypeStr)/sizeof(TCHAR));
  265. wsprintf(diskNoStr, "%u", regionDescriptor->Disk);
  266. LoadString(hModule, IDS_DRIVELET_DESCR, formatString, sizeof(formatString)/sizeof(TCHAR));
  267. FormatMessage(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY,
  268. formatString,
  269. 0,
  270. 0,
  271. description,
  272. sizeof(description),
  273. (va_list *)args);
  274. }
  275. SetWindowText(GetDlgItem(hdlg, IDC_DRIVELET_DESCR), description);
  276. driveLetter = (TCHAR)PERSISTENT_DATA(regionDescriptor)->DriveLetter;
  277. if ((driveLetter != NO_DRIVE_LETTER_YET) && (driveLetter != NO_DRIVE_LETTER_EVER)) {
  278. DWORD itemIndex;
  279. // There is a default drive letter. Place it on the list,
  280. // check the correct radio button, and set the correct default
  281. // in the combo box.
  282. driveLetterString[0] = (TCHAR)driveLetter;
  283. itemIndex = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LONG)driveLetterString);
  284. SendMessage(hwndCombo, CB_SETCURSEL, itemIndex, 0);
  285. defRadioButton = IDC_DRIVELET_RBASSIGN;
  286. SetFocus(hwndCombo);
  287. currentSelection = itemIndex;
  288. } else {
  289. // Default is no drive letter. Disable the combo box. Select
  290. // the correct radio button.
  291. EnableWindow(hwndCombo, FALSE);
  292. defRadioButton = IDC_DRIVELET_RBNOASSIGN;
  293. SendMessage(hwndCombo, CB_SETCURSEL, (DWORD)(-1), 0);
  294. SetFocus(GetDlgItem(hdlg, IDC_DRIVELET_RBNOASSIGN));
  295. currentSelection = 0;
  296. }
  297. CheckRadioButton(hdlg, IDC_DRIVELET_RBASSIGN, IDC_DRIVELET_RBNOASSIGN, defRadioButton);
  298. return FALSE; // focus set to control
  299. case WM_COMMAND:
  300. switch (LOWORD(wParam)) {
  301. case IDOK:
  302. // If the 'no letter' button is checked, return NO_DRIVE_LETTER_EVER
  303. if (IsDlgButtonChecked(hdlg, IDC_DRIVELET_RBNOASSIGN)) {
  304. EndDialog(hdlg, NO_DRIVE_LETTER_EVER);
  305. break;
  306. }
  307. // Otherwise, get the currently selected item in the listbox.
  308. selection = SendMessage(hwndCombo, CB_GETCURSEL, 0, 0);
  309. SendMessage(hwndCombo, CB_GETLBTEXT, selection, (LONG)driveLetterString);
  310. EndDialog(hdlg,(int)(unsigned)(*driveLetterString));
  311. break;
  312. case IDCANCEL:
  313. EndDialog(hdlg, 0);
  314. break;
  315. case FD_IDHELP:
  316. DialogHelp(HC_DM_DLG_DRIVELETTER);
  317. break;
  318. case IDC_DRIVELET_RBASSIGN:
  319. if (HIWORD(wParam) == BN_CLICKED) {
  320. EnableWindow(hwndCombo, TRUE);
  321. SendMessage(hwndCombo, CB_SETCURSEL, currentSelection, 0);
  322. SetFocus(hwndCombo);
  323. }
  324. break;
  325. case IDC_DRIVELET_RBNOASSIGN:
  326. if (HIWORD(wParam) == BN_CLICKED) {
  327. currentSelection = SendMessage(hwndCombo, CB_GETCURSEL, 0, 0);
  328. SendMessage(hwndCombo, CB_SETCURSEL, (DWORD)-1, 0);
  329. EnableWindow(hwndCombo, FALSE);
  330. }
  331. break;
  332. default:
  333. return FALSE;
  334. }
  335. break;
  336. default:
  337. return FALSE;
  338. }
  339. return TRUE;
  340. }
  341. BOOL CALLBACK
  342. DisplayOptionsDlgProc(
  343. IN HWND hdlg,
  344. IN UINT msg,
  345. IN WPARAM wParam,
  346. IN LPARAM lParam
  347. )
  348. /*++
  349. Routine Description:
  350. Dialog procedure for display options. Currently the only display option
  351. is to alter the graph type (proportional/equal) on each disk.
  352. For this dialog, lParam on creation must point to a buffer into which
  353. this dialog procedure will place the user's new choices for the graph
  354. display type for each disk.
  355. Arguments:
  356. hdlg - window handle of dialog box
  357. msg - message #
  358. wParam - msg specific data
  359. lParam - msg specific data
  360. Return Value:
  361. msg dependent
  362. --*/
  363. {
  364. static PBAR_TYPE newBarTypes;
  365. static HWND hwndCombo;
  366. DWORD selection;
  367. DWORD i;
  368. switch (msg) {
  369. case WM_INITDIALOG:
  370. CenterDialog(hdlg);
  371. newBarTypes = (PBAR_TYPE)lParam;
  372. hwndCombo = GetDlgItem(hdlg, IDC_DISK_COMBOBOX);
  373. // Add each disk to the combo box.
  374. for (i=0; i<DiskCount; i++) {
  375. TCHAR str[10];
  376. wsprintf(str,TEXT("%u"),i);
  377. SendMessage(hwndCombo, CB_ADDSTRING, 0, (DWORD)str);
  378. }
  379. // select the zeroth item in the combobox
  380. SendMessage(hwndCombo, CB_SETCURSEL, 0, 0);
  381. SendMessage(hdlg,
  382. WM_COMMAND,
  383. MAKELONG(IDC_DISK_COMBOBOX,CBN_SELCHANGE),
  384. 0);
  385. break;
  386. case WM_COMMAND:
  387. switch (LOWORD(wParam)) {
  388. case IDOK:
  389. EndDialog(hdlg, IDOK);
  390. break;
  391. case IDCANCEL:
  392. EndDialog(hdlg, IDCANCEL);
  393. break;
  394. case FD_IDHELP:
  395. DialogHelp(HC_DM_DLG_DISPLAYOPTION);
  396. break;
  397. case IDC_DISK_COMBOBOX:
  398. if (HIWORD(wParam) == CBN_SELCHANGE) {
  399. int rb = 0;
  400. // Selection in the combobox has changed; update the radio buttons
  401. selection = SendMessage(hwndCombo, CB_GETCURSEL, 0, 0);
  402. switch (newBarTypes[selection]) {
  403. case BarProportional:
  404. rb = IDC_RBPROPORTIONAL;
  405. break;
  406. case BarEqual:
  407. rb = IDC_RBEQUAL;
  408. break;
  409. case BarAuto:
  410. rb = IDC_RBAUTO;
  411. break;
  412. default:
  413. FDASSERT(0);
  414. }
  415. CheckRadioButton(hdlg, IDC_RBPROPORTIONAL, IDC_RBAUTO, rb);
  416. }
  417. break;
  418. case IDC_RESETALL:
  419. if (HIWORD(wParam) == BN_CLICKED) {
  420. for (i=0; i<DiskCount; i++) {
  421. newBarTypes[i] = BarAuto;
  422. }
  423. CheckRadioButton(hdlg, IDC_RBPROPORTIONAL, IDC_RBAUTO, IDC_RBAUTO);
  424. }
  425. break;
  426. case IDC_RBPROPORTIONAL:
  427. if (HIWORD(wParam) == BN_CLICKED) {
  428. selection = SendMessage(hwndCombo, CB_GETCURSEL, 0, 0);
  429. newBarTypes[selection] = BarProportional;
  430. }
  431. break;
  432. case IDC_RBEQUAL:
  433. if (HIWORD(wParam) == BN_CLICKED) {
  434. selection = SendMessage(hwndCombo, CB_GETCURSEL, 0, 0);
  435. newBarTypes[selection] = BarEqual;
  436. }
  437. break;
  438. case IDC_RBAUTO:
  439. if (HIWORD(wParam) == BN_CLICKED) {
  440. selection = SendMessage(hwndCombo, CB_GETCURSEL, 0, 0);
  441. newBarTypes[selection] = BarAuto;
  442. }
  443. break;
  444. default:
  445. return FALSE;
  446. }
  447. break;
  448. default:
  449. return FALSE;
  450. }
  451. return TRUE;
  452. }
  453. BOOL CALLBACK
  454. ColorDlgProc(
  455. IN HWND hdlg,
  456. IN UINT msg,
  457. IN WPARAM wParam,
  458. IN LPARAM lParam
  459. )
  460. /*++
  461. Routine Description:
  462. Dialog for the select colors/patterns dialog box. Note that this dialog
  463. uses a rectangle custom control, defined below.
  464. Arguments:
  465. hwnd - window handle of dialog box
  466. msg - message #
  467. wParam - msg specific data
  468. lParam - msg specific data
  469. Return Value:
  470. msg dependent
  471. --*/
  472. {
  473. unsigned i;
  474. switch (msg) {
  475. case WM_INITDIALOG:
  476. #if BRUSH_ARRAY_SIZE != LEGEND_STRING_COUNT
  477. #error legend label array and brush array are out of sync
  478. #endif
  479. if (!InitColorDlg(hdlg)) {
  480. EndDialog(hdlg, -1);
  481. }
  482. break;
  483. case WM_COMMAND:
  484. switch (LOWORD(wParam)) {
  485. case IDOK:
  486. for (i=0; i<LEGEND_STRING_COUNT; i++) {
  487. SelectedColor[i] -= IDC_COLOR1;
  488. SelectedHatch[i] -= IDC_PATTERN1;
  489. }
  490. EndDialog(hdlg, IDOK);
  491. break;
  492. case IDCANCEL:
  493. EndDialog(hdlg, IDCANCEL);
  494. break;
  495. case FD_IDHELP:
  496. DialogHelp(HC_DM_COLORSANDPATTERNS);
  497. break;
  498. case IDC_COLORDLGCOMBO:
  499. switch (HIWORD(wParam)) {
  500. case CBN_SELCHANGE:
  501. // deselect previous color
  502. SendMessage(GetDlgItem(hdlg, SelectedColor[CurrentElement]),
  503. RM_SELECT,
  504. FALSE,
  505. 0);
  506. // deselect previous pattern
  507. SendMessage(GetDlgItem(hdlg, SelectedHatch[CurrentElement]),
  508. RM_SELECT,
  509. FALSE,
  510. 0);
  511. CurrentElement = SendMessage((HWND)lParam, CB_GETCURSEL, 0, 0);
  512. SendMessage(hdlg, WM_COMMAND, MAKELONG(SelectedColor[CurrentElement], 0), 0);
  513. SendMessage(hdlg, WM_COMMAND, MAKELONG(SelectedHatch[CurrentElement], 0), 0);
  514. break;
  515. default:
  516. return FALSE;
  517. }
  518. break;
  519. case IDC_COLOR1:
  520. case IDC_COLOR2:
  521. case IDC_COLOR3:
  522. case IDC_COLOR4:
  523. case IDC_COLOR5:
  524. case IDC_COLOR6:
  525. case IDC_COLOR7:
  526. case IDC_COLOR8:
  527. case IDC_COLOR9:
  528. case IDC_COLOR10:
  529. case IDC_COLOR11:
  530. case IDC_COLOR12:
  531. case IDC_COLOR13:
  532. case IDC_COLOR14:
  533. case IDC_COLOR15:
  534. case IDC_COLOR16:
  535. // deselect previous color
  536. SendMessage(GetDlgItem(hdlg, SelectedColor[CurrentElement]),
  537. RM_SELECT,
  538. FALSE,
  539. 0);
  540. SendMessage(GetDlgItem(hdlg, LOWORD(wParam)),
  541. RM_SELECT,
  542. TRUE,
  543. 0);
  544. SelectedColor[CurrentElement] = LOWORD(wParam);
  545. // now force patterns to be redrawn in selected color
  546. for (i=IDC_PATTERN1; i<=IDC_PATTERN5; i++) {
  547. InvalidateRect(GetDlgItem(hdlg, i), NULL, FALSE);
  548. }
  549. break;
  550. case IDC_PATTERN1:
  551. case IDC_PATTERN2:
  552. case IDC_PATTERN3:
  553. case IDC_PATTERN4:
  554. case IDC_PATTERN5:
  555. // deselect previous pattern
  556. SendMessage(GetDlgItem(hdlg, SelectedHatch[CurrentElement]),
  557. RM_SELECT,
  558. FALSE,
  559. 0);
  560. SendMessage(GetDlgItem(hdlg, LOWORD(wParam)),
  561. RM_SELECT,
  562. TRUE,
  563. 0);
  564. SelectedHatch[CurrentElement] = LOWORD(wParam);
  565. break;
  566. }
  567. break;
  568. default:
  569. return FALSE;
  570. }
  571. return TRUE;
  572. }
  573. BOOL
  574. InitColorDlg(
  575. IN HWND hdlg
  576. )
  577. /*++
  578. Routine Description:
  579. Initialize the color selection dialog.
  580. Arguments:
  581. hdlg - the dialog handle.
  582. Return Value:
  583. TRUE - successfully set up the dialog.
  584. --*/
  585. {
  586. unsigned i;
  587. LONG ec;
  588. HWND hwndCombo = GetDlgItem(hdlg, IDC_COLORDLGCOMBO);
  589. hDlgColor = hdlg;
  590. CenterDialog(hdlg);
  591. for (i=0; i<LEGEND_STRING_COUNT; i++) {
  592. ec = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LONG)LegendLabels[i]);
  593. if ((ec == CB_ERR) || (ec == CB_ERRSPACE)) {
  594. return FALSE;
  595. }
  596. SelectedColor[i] = IDC_COLOR1 + BrushColors[i];
  597. SelectedHatch[i] = IDC_PATTERN1 + BrushHatches[i];
  598. }
  599. SendMessage(hwndCombo, CB_SETCURSEL, CurrentElement=0, 0);
  600. SendMessage(hdlg, WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndCombo), CBN_SELCHANGE), (LONG)hwndCombo);
  601. return TRUE;
  602. }
  603. LONG
  604. RectWndProc(
  605. IN HWND hwnd,
  606. IN DWORD msg,
  607. IN DWORD wParam,
  608. IN LONG lParam
  609. )
  610. /*++
  611. Routine Description:
  612. This is a pre-process routine for all access to the disk
  613. bar display region of the WinDisk interface.
  614. Arguments:
  615. hwnd - the dialog handle
  616. msg - the windows message for the dialog
  617. wParam/lParam - windows dialog parameters.
  618. Return Value:
  619. Standard dialog requirements.
  620. --*/
  621. {
  622. LONG res = 1;
  623. PAINTSTRUCT ps;
  624. RECT rc;
  625. int CtlID;
  626. HBRUSH hbr,
  627. hbrT;
  628. DWORD style;
  629. switch (msg) {
  630. case WM_CREATE:
  631. FDASSERT(GetWindowLong(hwnd, GWL_STYLE) & (RS_PATTERN | RS_COLOR));
  632. SetWindowWord(hwnd, GWW_SELECTED, FALSE);
  633. break;
  634. case WM_LBUTTONDOWN:
  635. SetFocus(hwnd);
  636. break;
  637. case WM_SETFOCUS:
  638. SendMessage(GetParent(hwnd), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwnd), RN_CLICKED), (LONG)hwnd);
  639. break;
  640. case WM_PAINT:
  641. GetClientRect(hwnd, &rc);
  642. CtlID = GetDlgCtrlID(hwnd);
  643. BeginPaint(hwnd, &ps);
  644. hbr = CreateSolidBrush(GetWindowWord(hwnd, GWW_SELECTED)
  645. ? (~GetSysColor(COLOR_WINDOW)) & 0xffffff
  646. : GetSysColor(COLOR_WINDOW));
  647. hbrT = SelectObject(ps.hdc,hbr);
  648. SelectObject(ps.hdc, hPenNull);
  649. Rectangle(ps.hdc, rc.left, rc.top, rc.right, rc.bottom);
  650. if (hbrT) {
  651. SelectObject(ps.hdc, hbrT);
  652. }
  653. DeleteObject(hbr);
  654. InflateRect(&rc, -2, -2);
  655. rc.right--;
  656. rc.bottom--;
  657. if (GetWindowLong(hwnd, GWL_STYLE) & RS_COLOR) {
  658. hbr = CreateSolidBrush(AvailableColors[CtlID-IDC_COLOR1]);
  659. } else {
  660. hbr = CreateHatchBrush(AvailableHatches[CtlID-IDC_PATTERN1], AvailableColors[SelectedColor[SendMessage(GetDlgItem(hDlgColor, IDC_COLORDLGCOMBO), CB_GETCURSEL, 0, 0)]-IDC_COLOR1]);
  661. }
  662. hbrT = SelectObject(ps.hdc, hbr);
  663. SelectObject(ps.hdc, hPenThinSolid);
  664. Rectangle(ps.hdc, rc.left, rc.top, rc.right, rc.bottom);
  665. if (hbrT) {
  666. SelectObject(ps.hdc, hbrT);
  667. }
  668. DeleteObject(hbr);
  669. EndPaint(hwnd, &ps);
  670. break;
  671. case RM_SELECT:
  672. // wParam = TRUE/FALSE for selected/not selected
  673. if (GetWindowWord(hwnd, GWW_SELECTED) != (WORD)wParam) {
  674. SetWindowWord(hwnd, GWW_SELECTED, (WORD)wParam);
  675. InvalidateRect(hwnd, NULL, FALSE);
  676. // make keyboard interface work correctly
  677. style = (DWORD)GetWindowLong(hwnd, GWL_STYLE);
  678. style = wParam ? style | WS_TABSTOP : style & ~WS_TABSTOP;
  679. SetWindowLong(hwnd, GWL_STYLE, (LONG)style);
  680. }
  681. break;
  682. default:
  683. return DefWindowProc(hwnd, msg, wParam, lParam);
  684. }
  685. return res;
  686. }
  687. VOID
  688. InitRectControl(
  689. VOID
  690. )
  691. /*++
  692. Routine Description:
  693. Register the windows class for the selection control.
  694. Arguments:
  695. None
  696. Return Value:
  697. None
  698. --*/
  699. {
  700. WNDCLASS wc;
  701. wc.style = 0;
  702. wc.lpfnWndProc = RectWndProc;
  703. wc.cbClsExtra = 0;
  704. wc.cbWndExtra = RECTCONTROL_WNDEXTRA;
  705. wc.hInstance = hModule;
  706. wc.hIcon = NULL;
  707. wc.hCursor = NULL;
  708. wc.hbrBackground = NULL;
  709. wc.lpszMenuName = NULL;
  710. wc.lpszClassName = TEXT(RECTCONTROL);
  711. RegisterClass(&wc);
  712. }