summaryrefslogblamecommitdiffstats
path: root/private/utils/fdisk/fddlgs.c
blob: a7412cbfc50991b6b8c5714eed72c8353ace5a13 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































                                                                                                                                                                                               
/*++

Copyright (c) 1990  Microsoft Corporation

Module Name:

    fddlgs.c

Abstract:

    Dialog routines and dialog support subroutines.

Author:

    Ted Miller (tedm) 7-Jan-1992

--*/

#include "fdisk.h"

// used in color dialog to indicate what the user has chosen for
// the various graph element types

DWORD SelectedColor[LEGEND_STRING_COUNT];
DWORD SelectedHatch[LEGEND_STRING_COUNT];

// used in color dialog, contains element (ie, partition, logical volume,
// etc) we're selecting for (ie, which item is diaplyed in static text of
// combo box).

DWORD CurrentElement;

// handle of active color dialogs box.  Used by rectangle custom control.

HWND hDlgColor;

BOOL
InitColorDlg(
    IN HWND  hdlg
    );

VOID
CenterDialog(
    HWND hwnd
    )

/*++

Routine Description:

    Centers a dialog relative to the app's main window

Arguments:

    hwnd - window handle of dialog to center

Return Value:

    None.

--*/

{
    RECT  rcFrame,
          rcWindow;
    LONG  x,
          y,
          w,
          h;
    POINT point;
    LONG  sx = GetSystemMetrics(SM_CXSCREEN),
          sy = GetSystemMetrics(SM_CYSCREEN);

    point.x = point.y = 0;
    ClientToScreen(hwndFrame,&point);
    GetWindowRect (hwnd     ,&rcWindow);
    GetClientRect (hwndFrame,&rcFrame );

    w = rcWindow.right  - rcWindow.left + 1;
    h = rcWindow.bottom - rcWindow.top  + 1;
    x = point.x + ((rcFrame.right  - rcFrame.left + 1 - w) / 2);
    y = point.y + ((rcFrame.bottom - rcFrame.top  + 1 - h) / 2);

    if (x + w > sx) {
        x = sx - w;
    } else if (x < 0) {
        x = 0;
    }
    if (y + h > sy) {
        y = sy - h;
    } else if (y < 0) {
        y = 0;
    }

    MoveWindow(hwnd,x,y,w,h,FALSE);
}

BOOL
MinMaxDlgProc(
    IN HWND  hwnd,
    IN UINT  msg,
    IN DWORD wParam,
    IN LONG  lParam
    )

/*++

Routine Description:

    Dialog procedure for the enter size dialog box.  This dialog
    allows the user to enter a size for a partition, or use
    spin controls (a tiny scroll bar) to select the size.
    Possible outcomes are cancel or OK.  In the latter case the
    EndDialog code is the size.  In the former it is 0.

Arguments:

    hwnd - window handle of dialog box

    msg - message #

    wParam - msg specific data

    lParam - msg specific data

Return Value:

    msg dependent

--*/

{
    TCHAR             outputString[MESSAGE_BUFFER_SIZE];
    PMINMAXDLG_PARAMS params;
    BOOL              validNumber;
    DWORD             sizeMB;
    static DWORD      minSizeMB,
                      maxSizeMB,
                      helpContextId;

    switch (msg) {

    case WM_INITDIALOG:

        CenterDialog(hwnd);
        params = (PMINMAXDLG_PARAMS)lParam;
        // set up caption

        LoadString(hModule, params->CaptionStringID, outputString, sizeof(outputString)/sizeof(TCHAR));
        SetWindowText(hwnd, outputString);

        // set up minimum/maximum text

        LoadString(hModule, params->MinimumStringID, outputString, sizeof(outputString)/sizeof(TCHAR));
        SetDlgItemText(hwnd, IDC_MINMAX_MINLABEL, outputString);
        LoadString(hModule, params->MaximumStringID, outputString, sizeof(outputString)/sizeof(TCHAR));
        SetDlgItemText(hwnd, IDC_MINMAX_MAXLABEL, outputString);
        LoadString(hModule, params->SizeStringID, outputString, sizeof(outputString)/sizeof(TCHAR));
        SetDlgItemText(hwnd, IDC_MINMAX_SIZLABEL, outputString);

        minSizeMB = params->MinSizeMB;
        maxSizeMB = params->MaxSizeMB;
        helpContextId = params->HelpContextId;

        wsprintf(outputString, TEXT("%u"), minSizeMB);
        SetDlgItemText(hwnd, IDC_MINMAX_MIN, outputString);
        wsprintf(outputString, TEXT("%u"), maxSizeMB);
        SetDlgItemText(hwnd, IDC_MINMAX_MAX, outputString);

        // also put the size in the edit control and select the text

        wsprintf(outputString, TEXT("%u"), maxSizeMB);
        SetDlgItemText(hwnd, IDC_MINMAX_SIZE, outputString);
        SendDlgItemMessage(hwnd, IDC_MINMAX_SIZE, EM_SETSEL, 0, -1);
        SetFocus(GetDlgItem(hwnd, IDC_MINMAX_SIZE));
        return FALSE;      // indicate focus set to a control

    case WM_VSCROLL:

        switch (LOWORD(wParam)) {
        case SB_LINEDOWN:
        case SB_LINEUP:
            sizeMB = GetDlgItemInt(hwnd, IDC_MINMAX_SIZE, &validNumber, FALSE);
            if (!validNumber) {
                Beep(500,100);
            } else {
                if (((sizeMB > minSizeMB) && (LOWORD(wParam) == SB_LINEDOWN))
                 || ((sizeMB < maxSizeMB) && (LOWORD(wParam) == SB_LINEUP  )))
                {
                    if (sizeMB > maxSizeMB) {
                        sizeMB = maxSizeMB;
                    } else if (LOWORD(wParam) == SB_LINEUP) {
                        sizeMB++;
                    } else {
                        sizeMB--;
                    }
                    wsprintf(outputString, TEXT("%u"), sizeMB);
                    SetDlgItemText(hwnd, IDC_MINMAX_SIZE, outputString);
                    SendDlgItemMessage(hwnd, IDC_MINMAX_SIZE, EM_SETSEL, 0, -1);
                } else {
                    Beep(500,100);
                }
            }
        }
        break;

    case WM_COMMAND:

        switch (LOWORD(wParam)) {

        case IDOK:

            sizeMB = GetDlgItemInt(hwnd, IDC_MINMAX_SIZE, &validNumber, FALSE);
            if (!validNumber || !sizeMB || (sizeMB > maxSizeMB) || (sizeMB < minSizeMB)) {
                ErrorDialog(MSG_INVALID_SIZE);
            } else {
                EndDialog(hwnd, sizeMB);
            }
            break;

        case IDCANCEL:

            EndDialog(hwnd, 0);
            break;

        case FD_IDHELP:

            DialogHelp(helpContextId);
            break;

        default:

            return FALSE;
        }
        break;

    default:

        return FALSE;
    }
    return TRUE;
}

BOOL
DriveLetterDlgProc(
    IN HWND  hdlg,
    IN DWORD msg,
    IN DWORD wParam,
    IN LONG  lParam
    )

/*++

Routine Description:

    Dialog for allowing the user to select a drive letter for a
    partition, logical drive, volume set, or stripe set.

    The EndDialog codes are as follows:

        0 - user cancelled
        NO_DRIVE_LETTER_EVER - user opted not to assign a drive letter
        other - the drive letter chosen by the user

Arguments:

    hdlg - window handle of dialog box

    msg - message #

    wParam - msg specific data

    lParam - msg specific data

Return Value:

    msg dependent

--*/

{
    static HWND        hwndCombo;
    static DWORD       currentSelection;
    TCHAR              driveLetter;
    TCHAR              driveLetterString[3];
    DWORD              defRadioButton,
                       selection;
    PREGION_DESCRIPTOR regionDescriptor;
    PFT_OBJECT         ftObject;
    TCHAR              description[256];

    switch (msg) {

    case WM_INITDIALOG:

        // lParam points to the region descriptor

        regionDescriptor = (PREGION_DESCRIPTOR)lParam;
        FDASSERT(DmSignificantRegion(regionDescriptor));

        hwndCombo = GetDlgItem(hdlg,IDC_DRIVELET_COMBOBOX);
        CenterDialog(hdlg);

        // Add each available drive letter to the list of available
        // drive letters.

        driveLetterString[1] = TEXT(':');
        driveLetterString[2] = 0;
        for (driveLetter='C'; driveLetter <= 'Z'; driveLetter++) {
            if (DriveLetterIsAvailable((CHAR)driveLetter)) {
                *driveLetterString = driveLetter;
                SendMessage(hwndCombo, CB_ADDSTRING, 0, (LONG)driveLetterString);
            }
        }

        // Format the description of the partition.

        if (ftObject = GET_FT_OBJECT(regionDescriptor)) {

            TCHAR descr[256];
            DWORD resid = 0;

            // Ft.  Description is something like "Stripe set with parity #0"

            switch (ftObject->Set->Type) {
            case Mirror:
                resid = IDS_DLGCAP_MIRROR;
                break;
            case Stripe:
                resid = IDS_STATUS_STRIPESET;
                break;
            case StripeWithParity:
                resid = IDS_DLGCAP_PARITY;
                break;
            case VolumeSet:
                resid = IDS_STATUS_VOLUMESET;
                break;
            default:
                FDASSERT(FALSE);
            }

            LoadString(hModule, resid, descr, sizeof(descr)/sizeof(TCHAR));
            wsprintf(description, descr, ftObject->Set->Ordinal);

        } else {

            // Non-ft.  Description is something like '500 MB Unformatted
            // logical drive on disk 3' or '400 MB HPFS partition on disk 4'

            LPTSTR args[4];
            TCHAR  sizeStr[20],
                   partTypeStr[100],
                   diskNoStr[10],
                   typeName[150];
            TCHAR  formatString[256];

            args[0] = sizeStr;
            args[1] = typeName;
            args[2] = partTypeStr;
            args[3] = diskNoStr;

            wsprintf(sizeStr, "%u", regionDescriptor->SizeMB);
            wsprintf(typeName, "%ws", PERSISTENT_DATA(regionDescriptor)->TypeName);
            LoadString(hModule, regionDescriptor->RegionType == REGION_LOGICAL ? IDS_LOGICALVOLUME : IDS_PARTITION, partTypeStr, sizeof(partTypeStr)/sizeof(TCHAR));
            wsprintf(diskNoStr, "%u", regionDescriptor->Disk);

            LoadString(hModule, IDS_DRIVELET_DESCR, formatString, sizeof(formatString)/sizeof(TCHAR));
            FormatMessage(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ARGUMENT_ARRAY,
                          formatString,
                          0,
                          0,
                          description,
                          sizeof(description),
                          (va_list *)args);
        }

        SetWindowText(GetDlgItem(hdlg, IDC_DRIVELET_DESCR), description);
        driveLetter = (TCHAR)PERSISTENT_DATA(regionDescriptor)->DriveLetter;

        if ((driveLetter != NO_DRIVE_LETTER_YET) && (driveLetter != NO_DRIVE_LETTER_EVER)) {

            DWORD itemIndex;

            // There is a default drive letter.  Place it on the list,
            // check the correct radio button, and set the correct default
            // in the combo box.

            driveLetterString[0] = (TCHAR)driveLetter;
            itemIndex = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LONG)driveLetterString);
            SendMessage(hwndCombo, CB_SETCURSEL, itemIndex, 0);
            defRadioButton = IDC_DRIVELET_RBASSIGN;
            SetFocus(hwndCombo);
            currentSelection = itemIndex;

        } else {

            // Default is no drive letter.  Disable the combo box.  Select
            // the correct radio button.

            EnableWindow(hwndCombo, FALSE);
            defRadioButton = IDC_DRIVELET_RBNOASSIGN;
            SendMessage(hwndCombo, CB_SETCURSEL, (DWORD)(-1), 0);
            SetFocus(GetDlgItem(hdlg, IDC_DRIVELET_RBNOASSIGN));
            currentSelection = 0;
        }

        CheckRadioButton(hdlg, IDC_DRIVELET_RBASSIGN, IDC_DRIVELET_RBNOASSIGN, defRadioButton);
        return FALSE;      // focus set to control

    case WM_COMMAND:

        switch (LOWORD(wParam)) {

        case IDOK:

            // If the 'no letter' button is checked, return NO_DRIVE_LETTER_EVER

            if (IsDlgButtonChecked(hdlg, IDC_DRIVELET_RBNOASSIGN)) {
                EndDialog(hdlg, NO_DRIVE_LETTER_EVER);
                break;
            }

            // Otherwise, get the currently selected item in the listbox.

            selection = SendMessage(hwndCombo, CB_GETCURSEL, 0, 0);
            SendMessage(hwndCombo, CB_GETLBTEXT, selection, (LONG)driveLetterString);
            EndDialog(hdlg,(int)(unsigned)(*driveLetterString));
            break;

        case IDCANCEL:

            EndDialog(hdlg, 0);
            break;

        case FD_IDHELP:

            DialogHelp(HC_DM_DLG_DRIVELETTER);
            break;

        case IDC_DRIVELET_RBASSIGN:

            if (HIWORD(wParam) == BN_CLICKED) {
                EnableWindow(hwndCombo, TRUE);
                SendMessage(hwndCombo, CB_SETCURSEL, currentSelection, 0);
                SetFocus(hwndCombo);
            }
            break;

        case IDC_DRIVELET_RBNOASSIGN:

            if (HIWORD(wParam) == BN_CLICKED) {
                currentSelection = SendMessage(hwndCombo, CB_GETCURSEL, 0, 0);
                SendMessage(hwndCombo, CB_SETCURSEL, (DWORD)-1, 0);
                EnableWindow(hwndCombo, FALSE);
            }
            break;

        default:

            return FALSE;
        }
        break;

    default:

        return FALSE;
    }
    return TRUE;
}

BOOL
DisplayOptionsDlgProc(
    IN HWND  hdlg,
    IN UINT  msg,
    IN DWORD wParam,
    IN LONG  lParam
    )

/*++

Routine Description:

    Dialog procedure for display options.  Currently the only display option
    is to alter the graph type (proportional/equal) on each disk.

    For this dialog, lParam on creation must point to a buffer into which
    this dialog procedure will place the user's new choices for the graph
    display type for each disk.

Arguments:

    hdlg - window handle of dialog box

    msg - message #

    wParam - msg specific data

    lParam - msg specific data

Return Value:

    msg dependent

--*/

{
    static PBAR_TYPE newBarTypes;
    static HWND      hwndCombo;
    DWORD            selection;
    DWORD            i;

    switch (msg) {

    case WM_INITDIALOG:

        CenterDialog(hdlg);
        newBarTypes = (PBAR_TYPE)lParam;
        hwndCombo = GetDlgItem(hdlg, IDC_DISK_COMBOBOX);

        // Add each disk to the combo box.

        for (i=0; i<DiskCount; i++) {

            TCHAR str[10];

            wsprintf(str,TEXT("%u"),i);
            SendMessage(hwndCombo, CB_ADDSTRING, 0, (DWORD)str);
        }

        // select the zeroth item in the combobox
        SendMessage(hwndCombo, CB_SETCURSEL, 0, 0);
        SendMessage(hdlg,
                    WM_COMMAND,
                    MAKELONG(IDC_DISK_COMBOBOX,CBN_SELCHANGE),
                    0);
        break;

    case WM_COMMAND:

        switch (LOWORD(wParam)) {

        case IDOK:
            EndDialog(hdlg, IDOK);
            break;

        case IDCANCEL:
            EndDialog(hdlg, IDCANCEL);
            break;

        case FD_IDHELP:
            DialogHelp(HC_DM_DLG_DISPLAYOPTION);
            break;

        case IDC_DISK_COMBOBOX:

            if (HIWORD(wParam) == CBN_SELCHANGE) {

                int rb = 0;

                // Selection in the combobox has changed; update the radio buttons

                selection = SendMessage(hwndCombo, CB_GETCURSEL, 0, 0);

                switch (newBarTypes[selection]) {
                case BarProportional:
                    rb = IDC_RBPROPORTIONAL;
                    break;
                case BarEqual:
                    rb = IDC_RBEQUAL;
                    break;
                case BarAuto:
                    rb = IDC_RBAUTO;
                    break;
                default:
                    FDASSERT(0);
                }

                CheckRadioButton(hdlg, IDC_RBPROPORTIONAL, IDC_RBAUTO, rb);
            }
            break;

        case IDC_RESETALL:

            if (HIWORD(wParam) == BN_CLICKED) {
                for (i=0; i<DiskCount; i++) {
                    newBarTypes[i] = BarAuto;
                }
                CheckRadioButton(hdlg, IDC_RBPROPORTIONAL, IDC_RBAUTO, IDC_RBAUTO);
            }
            break;

        case IDC_RBPROPORTIONAL:

            if (HIWORD(wParam) == BN_CLICKED) {
                selection = SendMessage(hwndCombo, CB_GETCURSEL, 0, 0);
                newBarTypes[selection] = BarProportional;
            }
            break;

        case IDC_RBEQUAL:

            if (HIWORD(wParam) == BN_CLICKED) {
                selection = SendMessage(hwndCombo, CB_GETCURSEL, 0, 0);
                newBarTypes[selection] = BarEqual;
            }
            break;

        case IDC_RBAUTO:

            if (HIWORD(wParam) == BN_CLICKED) {
                selection = SendMessage(hwndCombo, CB_GETCURSEL, 0, 0);
                newBarTypes[selection] = BarAuto;
            }
            break;

        default:
            return FALSE;
        }
        break;

    default:

        return FALSE;
    }
    return TRUE;
}

BOOL
ColorDlgProc(
    IN HWND  hdlg,
    IN DWORD msg,
    IN DWORD wParam,
    IN LONG  lParam
    )

/*++

Routine Description:

    Dialog for the select colors/patterns dialog box.  Note that this dialog
    uses a rectangle custom control, defined below.

Arguments:

    hwnd - window handle of dialog box

    msg - message #

    wParam - msg specific data

    lParam - msg specific data

Return Value:

    msg dependent

--*/

{
    unsigned i;

    switch (msg) {

    case WM_INITDIALOG:

        #if BRUSH_ARRAY_SIZE != LEGEND_STRING_COUNT
        #error legend label array and brush array are out of sync
        #endif

        if (!InitColorDlg(hdlg)) {
            EndDialog(hdlg, -1);
        }
        break;

    case WM_COMMAND:

        switch (LOWORD(wParam)) {

        case IDOK:

            for (i=0; i<LEGEND_STRING_COUNT; i++) {
                SelectedColor[i] -= IDC_COLOR1;
                SelectedHatch[i] -= IDC_PATTERN1;
            }
            EndDialog(hdlg, IDOK);
            break;

        case IDCANCEL:
            EndDialog(hdlg, IDCANCEL);
            break;

        case FD_IDHELP:
            DialogHelp(HC_DM_COLORSANDPATTERNS);
            break;

        case IDC_COLORDLGCOMBO:
            switch (HIWORD(wParam)) {
            case CBN_SELCHANGE:
                // deselect previous color
                SendMessage(GetDlgItem(hdlg, SelectedColor[CurrentElement]),
                            RM_SELECT,
                            FALSE,
                            0);
                // deselect previous pattern
                SendMessage(GetDlgItem(hdlg, SelectedHatch[CurrentElement]),
                            RM_SELECT,
                            FALSE,
                            0);
                CurrentElement = SendMessage((HWND)lParam, CB_GETCURSEL, 0, 0);
                SendMessage(hdlg, WM_COMMAND, MAKELONG(SelectedColor[CurrentElement], 0), 0);
                SendMessage(hdlg, WM_COMMAND, MAKELONG(SelectedHatch[CurrentElement], 0), 0);
                break;
            default:
                return FALSE;
            }
            break;

        case IDC_COLOR1:
        case IDC_COLOR2:
        case IDC_COLOR3:
        case IDC_COLOR4:
        case IDC_COLOR5:
        case IDC_COLOR6:
        case IDC_COLOR7:
        case IDC_COLOR8:
        case IDC_COLOR9:
        case IDC_COLOR10:
        case IDC_COLOR11:
        case IDC_COLOR12:
        case IDC_COLOR13:
        case IDC_COLOR14:
        case IDC_COLOR15:
        case IDC_COLOR16:
            // deselect previous color

            SendMessage(GetDlgItem(hdlg, SelectedColor[CurrentElement]),
                        RM_SELECT,
                        FALSE,
                        0);
            SendMessage(GetDlgItem(hdlg, LOWORD(wParam)),
                        RM_SELECT,
                        TRUE,
                        0);
            SelectedColor[CurrentElement] = LOWORD(wParam);

            // now force patterns to be redrawn in selected color

            for (i=IDC_PATTERN1; i<=IDC_PATTERN5; i++) {
                InvalidateRect(GetDlgItem(hdlg, i), NULL, FALSE);
            }
            break;

        case IDC_PATTERN1:
        case IDC_PATTERN2:
        case IDC_PATTERN3:
        case IDC_PATTERN4:
        case IDC_PATTERN5:
            // deselect previous pattern
            SendMessage(GetDlgItem(hdlg, SelectedHatch[CurrentElement]),
                        RM_SELECT,
                        FALSE,
                        0);
            SendMessage(GetDlgItem(hdlg, LOWORD(wParam)),
                        RM_SELECT,
                        TRUE,
                        0);
            SelectedHatch[CurrentElement] = LOWORD(wParam);
            break;
        }
        break;

    default:
        return FALSE;
    }
    return TRUE;
}

BOOL
InitColorDlg(
    IN HWND  hdlg
    )

/*++

Routine Description:

    Initialize the color selection dialog.

Arguments:

    hdlg - the dialog handle.

Return Value:

    TRUE - successfully set up the dialog.

--*/

{
    unsigned i;
    LONG     ec;
    HWND     hwndCombo = GetDlgItem(hdlg, IDC_COLORDLGCOMBO);

    hDlgColor = hdlg;

    CenterDialog(hdlg);

    for (i=0; i<LEGEND_STRING_COUNT; i++) {
        ec = SendMessage(hwndCombo, CB_ADDSTRING, 0, (LONG)LegendLabels[i]);
        if ((ec == CB_ERR) || (ec == CB_ERRSPACE)) {
            return FALSE;
        }
        SelectedColor[i] = IDC_COLOR1 + BrushColors[i];
        SelectedHatch[i] = IDC_PATTERN1 + BrushHatches[i];
    }
    SendMessage(hwndCombo, CB_SETCURSEL, CurrentElement=0, 0);
    SendMessage(hdlg, WM_COMMAND, MAKELONG(GetDlgCtrlID(hwndCombo), CBN_SELCHANGE), (LONG)hwndCombo);
    return TRUE;
}

LONG
RectWndProc(
    IN HWND  hwnd,
    IN DWORD msg,
    IN DWORD wParam,
    IN LONG  lParam
    )

/*++

Routine Description:

    This is a pre-process routine for all access to the disk
    bar display region of the WinDisk interface.

Arguments:

    hwnd - the dialog handle
    msg  - the windows message for the dialog
    wParam/lParam - windows dialog parameters.

Return Value:

    Standard dialog requirements.

--*/

{
    LONG        res = 1;
    PAINTSTRUCT ps;
    RECT        rc;
    int         CtlID;
    HBRUSH      hbr,
                hbrT;
    DWORD       style;

    switch (msg) {

    case WM_CREATE:

        FDASSERT(GetWindowLong(hwnd, GWL_STYLE) & (RS_PATTERN | RS_COLOR));
        SetWindowWord(hwnd, GWW_SELECTED, FALSE);
        break;

    case WM_LBUTTONDOWN:

        SetFocus(hwnd);
        break;

    case WM_SETFOCUS:

        SendMessage(GetParent(hwnd), WM_COMMAND, MAKELONG(GetDlgCtrlID(hwnd), RN_CLICKED), (LONG)hwnd);
        break;

    case WM_PAINT:

        GetClientRect(hwnd, &rc);
        CtlID = GetDlgCtrlID(hwnd);
        BeginPaint(hwnd, &ps);

        hbr = CreateSolidBrush(GetWindowWord(hwnd, GWW_SELECTED)
                               ? (~GetSysColor(COLOR_WINDOW)) & 0xffffff
                               : GetSysColor(COLOR_WINDOW));
        hbrT = SelectObject(ps.hdc,hbr);
        SelectObject(ps.hdc, hPenNull);
        Rectangle(ps.hdc, rc.left, rc.top, rc.right, rc.bottom);

        if (hbrT) {
            SelectObject(ps.hdc, hbrT);
        }
        DeleteObject(hbr);

        InflateRect(&rc, -2, -2);
        rc.right--;
        rc.bottom--;

        if (GetWindowLong(hwnd, GWL_STYLE) & RS_COLOR) {
            hbr = CreateSolidBrush(AvailableColors[CtlID-IDC_COLOR1]);
        } else {
            hbr = CreateHatchBrush(AvailableHatches[CtlID-IDC_PATTERN1], AvailableColors[SelectedColor[SendMessage(GetDlgItem(hDlgColor, IDC_COLORDLGCOMBO), CB_GETCURSEL, 0, 0)]-IDC_COLOR1]);
        }

        hbrT = SelectObject(ps.hdc, hbr);
        SelectObject(ps.hdc, hPenThinSolid);
        Rectangle(ps.hdc, rc.left, rc.top, rc.right, rc.bottom);

        if (hbrT) {
            SelectObject(ps.hdc, hbrT);
        }

        DeleteObject(hbr);

        EndPaint(hwnd, &ps);
        break;

    case RM_SELECT:

        // wParam = TRUE/FALSE for selected/not selected

        if (GetWindowWord(hwnd, GWW_SELECTED) != (WORD)wParam) {

            SetWindowWord(hwnd, GWW_SELECTED, (WORD)wParam);
            InvalidateRect(hwnd, NULL, FALSE);

            // make keyboard interface work correctly

            style = (DWORD)GetWindowLong(hwnd, GWL_STYLE);
            style = wParam ? style | WS_TABSTOP : style & ~WS_TABSTOP;
            SetWindowLong(hwnd, GWL_STYLE, (LONG)style);
        }

        break;

    default:
        return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return res;
}

VOID
InitRectControl(
    VOID
    )

/*++

Routine Description:

    Register the windows class for the selection control.

Arguments:

    None

Return Value:

    None

--*/

{
    WNDCLASS wc;

    wc.style         = 0;
    wc.lpfnWndProc   = (WNDPROC)RectWndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = RECTCONTROL_WNDEXTRA;
    wc.hInstance     = hModule;
    wc.hIcon         = NULL;
    wc.hCursor       = NULL;
    wc.hbrBackground = NULL;
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = TEXT(RECTCONTROL);

    RegisterClass(&wc);
}