summaryrefslogtreecommitdiffstats
path: root/private/unimodem/modemui/gen.c
blob: 3899f97b9eab0c633ae8df062d41c36c6771b716 (plain) (blame)
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
//---------------------------------------------------------------------------
//
// Copyrght (c) Microsoft Corporation 1993-1994
//
// File: gen.c
//
// This files contains the dialog code for the General property page.
//
// History:
//  1-14-94 ScottH     Created
//
//---------------------------------------------------------------------------


/////////////////////////////////////////////////////  INCLUDES

#include "proj.h"         // common headers

#ifdef WIN95
#include "..\..\..\..\win\core\inc\help.h"
#endif

/////////////////////////////////////////////////////  CONTROLLING DEFINES

/////////////////////////////////////////////////////  TYPEDEFS

#define SUBCLASS_PARALLEL   0
#define SUBCLASS_SERIAL     1
#define SUBCLASS_MODEM      2

#define MAX_NUM_VOLUME_TICS 4

typedef struct tagGEN
    {
    HWND hdlg;              // dialog handle
    HWND hwndPort;

    LPMODEMINFO pmi;        // modeminfo struct passed in to dialog
    HPORTMAP hportmap;
    int  ticVolume;
    int  iSelOriginal;

    int  ticVolumeMax;
    struct {                // volume tic mapping info
        DWORD dwVolume;
        DWORD dwMode;
        } tics[MAX_NUM_VOLUME_TICS];
    
    } GEN, FAR * PGEN;

/////////////////////////////////////////////////////  DEFINES

/////////////////////////////////////////////////////  MACROS

#define Gen_GetPtr(hwnd)           (PGEN)GetWindowLong(hwnd, DWL_USER)
#define Gen_SetPtr(hwnd, lp)       (PGEN)SetWindowLong(hwnd, DWL_USER, (LONG)(lp))

/////////////////////////////////////////////////////  MODULE DATA

#pragma data_seg(DATASEG_READONLY)

// This is the structure that is used to fill the 
// max speed listbox
struct _Bauds
    {
    DWORD   dwDTERate;
    int     ids;
    } const c_rgbauds[] = {
        // These numbers must increase monotonically
        { 110L,         IDS_BAUD_110     },
        { 300L,         IDS_BAUD_300     },
        { 1200L,        IDS_BAUD_1200    },
        { 2400L,        IDS_BAUD_2400    },
        { 4800L,        IDS_BAUD_4800    },
        { 9600L,        IDS_BAUD_9600    },
        { 19200,        IDS_BAUD_19200   },
        { 38400,        IDS_BAUD_38400   },
        { 57600,        IDS_BAUD_57600   },
        { 115200,       IDS_BAUD_115200  },
        { 230400,       IDS_BAUD_230400  },
        { 460800,       IDS_BAUD_460800  },
        { 921600,       IDS_BAUD_921600  },
        };

// Map driver type values to icon resource IDs
struct 
    {
    BYTE    nDeviceType;    // DT_ value
    UINT    idi;            // icon resource ID
    UINT    ids;            // string resource ID
    } const c_rgmapdt[] = {
        { DT_NULL_MODEM,     IDI_NULL_MODEM,     IDS_NULL_MODEM },
        { DT_EXTERNAL_MODEM, IDI_EXTERNAL_MODEM, IDS_EXTERNAL_MODEM },
        { DT_INTERNAL_MODEM, IDI_INTERNAL_MODEM, IDS_INTERNAL_MODEM },
        { DT_PCMCIA_MODEM,   IDI_PCMCIA_MODEM,   IDS_PCMCIA_MODEM },
        { DT_PARALLEL_PORT,  IDI_NULL_MODEM,     IDS_PARALLEL_PORT },
        { DT_PARALLEL_MODEM, IDI_EXTERNAL_MODEM, IDS_PARALLEL_MODEM } };

#pragma data_seg()


/*----------------------------------------------------------
Purpose: Returns the appropriate icon ID given the device
         type.

Returns: icon resource ID in pidi
         string resource ID in pids
Cond:    --
*/
void PRIVATE GetTypeIDs(
    BYTE nDeviceType,
    LPUINT pidi,
    LPUINT pids)
    {
    int i;

    for (i = 0; i < ARRAY_ELEMENTS(c_rgmapdt); i++)
        {
        if (nDeviceType == c_rgmapdt[i].nDeviceType)
            {
            *pidi = c_rgmapdt[i].idi;
            *pids = c_rgmapdt[i].ids;
            return;
            }
        }
    ASSERT(0);      // We should never get here
    }


/*----------------------------------------------------------
Purpose: Returns FALSE if the given port is not compatible with
         the device type.

Returns: see above
Cond:    --
*/
BOOL 
PRIVATE 
IsCompatiblePort(
    IN  DWORD nSubclass,
    IN  BYTE nDeviceType)
    {
    BOOL bRet = TRUE;

    // Is the port subclass appropriate for this modem type?
    // (Don't list lpt ports when it is a serial modem.)
    switch (nSubclass)
        {
    case PORT_SUBCLASS_SERIAL:
        if (DT_PARALLEL_PORT == nDeviceType ||
            DT_PARALLEL_MODEM == nDeviceType)
            {
            bRet = FALSE;
            }
        break;

    case PORT_SUBCLASS_PARALLEL:
        if (DT_PARALLEL_PORT != nDeviceType &&
            DT_PARALLEL_MODEM != nDeviceType)
            {
            bRet = FALSE;
            }
        break;

    default:
        ASSERT(0);
        break;
        }

    return bRet;
    }


/*----------------------------------------------------------
Purpose: Fill the port box with the available ports

Returns: TRUE to continue enumeration
Cond:    --
*/
BOOL WINAPI Gen_AddToPortBox(
    HPORTDATA hportdata,
    LPARAM lParam)
    {
    BOOL bRet;
    PORTDATA pd;

    pd.cbSize = sizeof(pd);
    bRet = PortData_GetProperties(hportdata, &pd);
    if (bRet)
        {
        PGEN this = (PGEN)lParam;

        if (IsCompatiblePort(pd.nSubclass, this->pmi->nDeviceType))
            {
            // Add the port to the list
            HWND hwndCB = this->hwndPort;
            int index = ComboBox_AddString(hwndCB, pd.szFriendly);

            if (IsSzEqual(pd.szPort, this->pmi->szPortName))
                ComboBox_SetCurSel(hwndCB, index);
            }
        }

    return bRet;
    }


/*----------------------------------------------------------
Purpose: Return the tic corresponding to bit flag value
Returns: tic index
Cond:    --
*/
int PRIVATE MapVolumeToTic(
    PGEN this)
    {
    DWORD dwVolume = this->pmi->ms.dwSpeakerVolume;
    DWORD dwMode = this->pmi->ms.dwSpeakerMode;
    int   i;

    ASSERT(ARRAY_ELEMENTS(this->tics) > this->ticVolumeMax);
    for (i = 0; i <= this->ticVolumeMax; i++)
        {
        if (this->tics[i].dwVolume == dwVolume &&
            this->tics[i].dwMode   == dwMode)
            {
            return i;
            }
        }

    return 0;
    }


/*----------------------------------------------------------
Purpose: Set the volume control
Returns: --
Cond:    --
*/
void PRIVATE Gen_SetVolume(
    PGEN this)
    {
    HWND hwndVol = GetDlgItem(this->hdlg, IDC_VOLUME);
    DWORD dwMode = this->pmi->devcaps.dwSpeakerMode;
    DWORD dwVolume = this->pmi->devcaps.dwSpeakerVolume;
    TCHAR sz[MAXSHORTLEN];
    int i;
    int iTicCount;
    static struct {
        DWORD dwVolBit;
        DWORD dwVolSetting;
        } rgvolumes[] = { 
            { MDMVOLFLAG_LOW,    MDMVOL_LOW},
            { MDMVOLFLAG_MEDIUM, MDMVOL_MEDIUM},
            { MDMVOLFLAG_HIGH,   MDMVOL_HIGH} };

    // Does the modem support volume control?
    if (0 == dwVolume && IsFlagSet(dwMode, MDMSPKRFLAG_OFF) &&
        (IsFlagSet(dwMode, MDMSPKRFLAG_ON) || IsFlagSet(dwMode, MDMSPKRFLAG_DIAL)))
        {
        // Set up the volume tic table.
        iTicCount = 2;
        this->tics[0].dwVolume = 0;  // doesn't matter because Volume isn't supported
        this->tics[0].dwMode   = MDMSPKR_OFF;
        this->tics[1].dwVolume = 0;  // doesn't matter because Volume isn't supported
        this->tics[1].dwMode   = IsFlagSet(dwMode, MDMSPKRFLAG_DIAL) ? MDMSPKR_DIAL : MDMSPKR_ON;

        // No Loud.  So change it to On.
        Static_SetText(GetDlgItem(this->hdlg, IDC_LOUD), SzFromIDS(g_hinst, IDS_ON, sz, SIZECHARS(sz)));
        }
    else
        {
        DWORD dwOnMode = IsFlagSet(dwMode, MDMSPKRFLAG_DIAL) 
                             ? MDMSPKR_DIAL
                             : IsFlagSet(dwMode, MDMSPKRFLAG_ON)
                                   ? MDMSPKR_ON
                                   : 0;

        // Init tic count
        iTicCount = 0;

        // MDMSPKR_OFF?
        if (IsFlagSet(dwMode, MDMSPKRFLAG_OFF))
            {
            for (i = 0; i < ARRAY_ELEMENTS(rgvolumes); i++)
                {
                if (IsFlagSet(dwVolume, rgvolumes[i].dwVolBit))
                    {
                    this->tics[iTicCount].dwVolume = rgvolumes[i].dwVolSetting;
                    break;
                    }
                }
            this->tics[iTicCount].dwMode   = MDMSPKR_OFF;
            iTicCount++;
            }
        else
            {
            // No Off.  So change it to Soft.
            Static_SetText(GetDlgItem(this->hdlg, IDC_LBL_OFF), SzFromIDS(g_hinst, IDS_SOFT, sz, SIZECHARS(sz)));
            }

        // MDMVOL_xxx?
        for (i = 0; i < ARRAY_ELEMENTS(rgvolumes); i++)
            {
            if (IsFlagSet(dwVolume, rgvolumes[i].dwVolBit))
                {
                this->tics[iTicCount].dwVolume = rgvolumes[i].dwVolSetting;
                this->tics[iTicCount].dwMode   = dwOnMode;
                iTicCount++;
                }
            }
        }

    // Set up the control.
    if (iTicCount > 0)
        {
        this->ticVolumeMax = iTicCount - 1;

        // Set the range
        SendMessage(hwndVol, TBM_SETRANGE, TRUE, MAKELPARAM(0, this->ticVolumeMax));

        // Set the volume to the current setting
        this->ticVolume = MapVolumeToTic(this);
        SendMessage(hwndVol, TBM_SETPOS, TRUE, MAKELPARAM(this->ticVolume, 0));
        }
    else
        {
        // No; disable the control
        EnableWindow(GetDlgItem(this->hdlg, IDC_SPEAKER), FALSE);
        EnableWindow(hwndVol, FALSE);
        EnableWindow(GetDlgItem(this->hdlg, IDC_LBL_OFF), FALSE);
        EnableWindow(GetDlgItem(this->hdlg, IDC_LOUD), FALSE);
        }
    }


/*----------------------------------------------------------
Purpose: Set the speed controls
Returns: --
Cond:    --
*/
void PRIVATE Gen_SetSpeed(
    PGEN this)
    {
    HWND hwndCB = GetDlgItem(this->hdlg, IDC_CB_SPEED);
    HWND hwndCH = GetDlgItem(this->hdlg, IDC_STRICTSPEED);
    WIN32DCB FAR * pdcb = &this->pmi->dcb;
    DWORD dwDTEMax = this->pmi->devcaps.dwMaxDTERate;
    int i;
    int n;
    int iMatch = -1;
    TCHAR sz[MAXMEDLEN];

    // Fill the listbox
    SetWindowRedraw(hwndCB, FALSE);
    ComboBox_ResetContent(hwndCB);
    for (i = 0; i < ARRAY_ELEMENTS(c_rgbauds); i++)
        {
        // Only fill up to the max DTE speed of the modem
        if (c_rgbauds[i].dwDTERate <= dwDTEMax)
            {
            n = ComboBox_AddString(hwndCB, SzFromIDS(g_hinst, c_rgbauds[i].ids, sz, SIZECHARS(sz)));
            ComboBox_SetItemData(hwndCB, n, c_rgbauds[i].dwDTERate);

            // Keep our eyes peeled for important values
            if (pdcb->BaudRate == c_rgbauds[i].dwDTERate)
                {
                iMatch = n;
                }
            }
        else
            break;
        }

    // Is the DCB baudrate >= the maximum possible DTE rate?
    if (pdcb->BaudRate >= dwDTEMax || -1 == iMatch)
        {
        // Yes; choose the highest possible (last) entry
        this->iSelOriginal = ComboBox_GetCount(hwndCB) - 1;
        }
    else 
        {
        // No; choose the matched value
        ASSERT(-1 != iMatch);
        this->iSelOriginal = iMatch;
        }
    ComboBox_SetCurSel(hwndCB, this->iSelOriginal);
    SetWindowRedraw(hwndCB, TRUE);

    // Can this modem adjust speed?
    if (IsFlagClear(this->pmi->devcaps.dwModemOptions, MDM_SPEED_ADJUST))
        {
        // No; disable the checkbox and check it
        Button_Enable(hwndCH, FALSE);
        Button_SetCheck(hwndCH, FALSE);
        }
    else
        {
        // Yes; enable the checkbox
        Button_Enable(hwndCH, TRUE);
        Button_SetCheck(hwndCH, IsFlagClear(this->pmi->ms.dwPreferredModemOptions, MDM_SPEED_ADJUST));
        }
    }


/*----------------------------------------------------------
Purpose: WM_INITDIALOG Handler
Returns: FALSE when we assign the control focus
Cond:    --
*/
BOOL PRIVATE Gen_OnInitDialog(
    PGEN this,
    HWND hwndFocus,
    LPARAM lParam)              // expected to be PROPSHEETINFO 
    {
    LPPROPSHEETPAGE lppsp = (LPPROPSHEETPAGE)lParam;
    HWND hdlg = this->hdlg;
    HWND hwndIcon;
    UINT idi;
    UINT ids;
    
    ASSERT((LPTSTR)lppsp->lParam);

    this->pmi = (LPMODEMINFO)lppsp->lParam;

    if (!PortMap_Create(&this->hportmap))
        {
        // Failure
        EndDialog(hdlg, -1);
        }

#ifdef WIN95
    // disable the static text control added for NT
    ShowWindow(GetDlgItem(hdlg, IDC_ST_PORT), SW_HIDE);

    // Does this modem have a fixed port?
    if (IsFlagSet(this->pmi->uFlags, MIF_PORT_IS_FIXED))
        {
        // Yes; the port name cannot be changed, so display it in a 
        // read-only edit control.
        // Don't try to find the friendly name, because no friendly
        // name exists for a devnode with a fixed port.
        this->hwndPort = GetDlgItem(hdlg, IDC_ED_PORT);
        Edit_SetText(this->hwndPort, this->pmi->szPortName);
        }
    else
        {
        // No; enumerate the ports and list them in a dropdown
        this->hwndPort = GetDlgItem(hdlg, IDC_CB_PORT);

        // Fill the Port combobox
        EnumeratePorts(Gen_AddToPortBox, (LPARAM)this);
        }

    // For whatever control we selected for the port, enable it and show it
    Edit_Enable(this->hwndPort, TRUE);
    ShowWindow(this->hwndPort, SW_SHOW);
#else
// Don't allow port to be changed in NT 4.0 - not fully implemented
        this->hwndPort = GetDlgItem(hdlg, IDC_ST_PORT);
        Edit_SetText(this->hwndPort, this->pmi->szPortName);
#endif

    // Set the icon
    hwndIcon = GetDlgItem(hdlg, IDC_GE_ICON);
    GetTypeIDs(this->pmi->nDeviceType, &idi, &ids);
    Static_SetIcon(hwndIcon, LoadIcon(g_hinst, MAKEINTRESOURCE(idi)));
    
    // Set the friendly name
    Edit_SetText(GetDlgItem(hdlg, IDC_ED_FRIENDLYNAME), this->pmi->szFriendlyName);

    Gen_SetVolume(this);
    // Speed is set in Gen_OnSetActive

    // Is this a parallel port?
    if (DT_PARALLEL_PORT == this->pmi->nDeviceType)
        {
        // Yes; hide the speed controls
        ShowWindow(GetDlgItem(hdlg, IDC_SPEED), SW_HIDE);
        EnableWindow(GetDlgItem(hdlg, IDC_SPEED), FALSE);

        ShowWindow(GetDlgItem(hdlg, IDC_CB_SPEED), SW_HIDE);
        EnableWindow(GetDlgItem(hdlg, IDC_CB_SPEED), FALSE);

        ShowWindow(GetDlgItem(hdlg, IDC_STRICTSPEED), SW_HIDE);
        EnableWindow(GetDlgItem(hdlg, IDC_STRICTSPEED), FALSE);
        }

    return TRUE;   // default initial focus
    }


/*----------------------------------------------------------
Purpose: WM_HSCROLL handler
Returns: --
Cond:    --
*/
void PRIVATE Gen_OnHScroll(
    PGEN this,
    HWND hwndCtl,
    UINT code,
    int pos)
    {
    // Handle for the volume control
    if (hwndCtl == GetDlgItem(this->hdlg, IDC_VOLUME))
        {
        int tic = this->ticVolume;

        switch (code)
            {
        case TB_LINEUP:
            tic--;
            break;

        case TB_LINEDOWN:
            tic++;
            break;

        case TB_PAGEUP:
            tic--;
            break;

        case TB_PAGEDOWN:
            tic++;
            break;

        case TB_THUMBPOSITION:
        case TB_THUMBTRACK:
            tic = pos;
            break;

        case TB_TOP:
            tic = 0;
            break;

        case TB_BOTTOM:
            tic = this->ticVolumeMax;
            break;

        case TB_ENDTRACK:
            return;
            }

        // Boundary check
        if (tic < 0)
            tic = 0;
        else if (tic > (this->ticVolumeMax))
            tic = this->ticVolumeMax;

        if (tic != this->ticVolume)
            {
            SendMessage(hwndCtl, TBM_SETPOS, TRUE, MAKELPARAM(tic, 0));
            }
        this->ticVolume = tic;
        }
    }


/*----------------------------------------------------------
Purpose: PSN_APPLY handler
Returns: --
Cond:    --
*/
void PRIVATE Gen_OnApply(
    PGEN this)
    {
    HWND hwndCB = GetDlgItem(this->hdlg, IDC_CB_SPEED);
    LPMODEMSETTINGS pms = &this->pmi->ms;
    int iSel;
    DWORD baudSel;

    // (The port name is saved in PSN_KILLACTIVE processing)

    // Determine new volume settings
    this->pmi->ms.dwSpeakerMode   = this->tics[this->ticVolume].dwMode;
    this->pmi->ms.dwSpeakerVolume = this->tics[this->ticVolume].dwVolume;

    // Determine new speed settings
    iSel = ComboBox_GetCurSel(hwndCB);
    baudSel = ComboBox_GetItemData(hwndCB, iSel);

    // Has the user changed the speed?
    if (iSel != this->iSelOriginal)
        {
        this->pmi->dcb.BaudRate = baudSel;      // yes
        }

    // Set the speed adjust
    if (Button_GetCheck(GetDlgItem(this->hdlg, IDC_STRICTSPEED)))
        ClearFlag(pms->dwPreferredModemOptions, MDM_SPEED_ADJUST);
    else
        SetFlag(pms->dwPreferredModemOptions, MDM_SPEED_ADJUST);

    this->pmi->idRet = IDOK;
    }


/*----------------------------------------------------------
Purpose: PSN_KILLACTIVE handler
Returns: --
Cond:    --
*/
void PRIVATE Gen_OnSetActive(
    PGEN this)
    {
    // Set the speed listbox selection; find DCB rate in the listbox
    // (The speed can change in the Connection page thru the Port Settings
    // property dialog.)
    Gen_SetSpeed(this);
    }


/*----------------------------------------------------------
Purpose: PSN_KILLACTIVE handler
Returns: --
Cond:    --
*/
void PRIVATE Gen_OnKillActive(
    PGEN this)
    {
    HWND hwndCB = GetDlgItem(this->hdlg, IDC_CB_SPEED);
    int iSel;

    // Save the settings back to the modem info struct so the Connection
    // page can invoke the Port Settings property dialog with the 
    // correct settings.

    // Is the port for this modem fixed?
    if (IsFlagSet(this->pmi->uFlags, MIF_PORT_IS_FIXED))
        {
        // Yes; do nothing (the portname cannot change)
        }
    else
        {
        // No
        int iSel = ComboBox_GetCurSel(this->hwndPort);
        TCHAR sz[MAXFRIENDLYNAME];

        ComboBox_GetLBText(this->hwndPort, iSel, sz);
        if ( !IsSzEqual(sz, this->pmi->szPortName) )
            {
            if (PortMap_GetPortName(this->hportmap, sz, this->pmi->szPortName, 
                                     SIZECHARS(this->pmi->szPortName)))
                {
                SetFlag(this->pmi->uFlags, MIF_PORTNAME_CHANGED);
                }
            }
        }

    // Speed setting
    iSel = ComboBox_GetCurSel(hwndCB);
    this->pmi->dcb.BaudRate = ComboBox_GetItemData(hwndCB, iSel);
    }


/*----------------------------------------------------------
Purpose: WM_NOTIFY handler
Returns: varies
Cond:    --
*/
LRESULT PRIVATE Gen_OnNotify(
    PGEN this,
    int idFrom,
    NMHDR FAR * lpnmhdr)
    {
    LRESULT lRet = 0;
    
    switch (lpnmhdr->code)
        {
    case PSN_SETACTIVE:
        Gen_OnSetActive(this);
        break;

    case PSN_KILLACTIVE:
        // N.b. This message is not sent if user clicks Cancel!
        // N.b. This message is sent prior to PSN_APPLY
        Gen_OnKillActive(this);
        break;

    case PSN_APPLY:
        Gen_OnApply(this);
        break;

    default:
        break;
        }

    return lRet;
    }


/*----------------------------------------------------------
Purpose: WM_DESTROY handler
Returns: --
Cond:    --
*/
void PRIVATE Gen_OnDestroy(
    PGEN this)
    {
    PortMap_Free(this->hportmap);
    }


/////////////////////////////////////////////////////  EXPORTED FUNCTIONS

static BOOL s_bGenRecurse = FALSE;

LRESULT INLINE Gen_DefProc(
    HWND hDlg, 
    UINT msg,
    WPARAM wParam,
    LPARAM lParam) 
    {
    ENTER_X()
        {
        s_bGenRecurse = TRUE;
        }
    LEAVE_X()

    return DefDlgProc(hDlg, msg, wParam, lParam); 
    }


/*----------------------------------------------------------
Purpose: Real dialog proc
Returns: varies
Cond:    --
*/
LRESULT Gen_DlgProc(
    PGEN this,
    UINT message,
    WPARAM wParam,
    LPARAM lParam)
    {
#pragma data_seg(DATASEG_READONLY)
    const static DWORD rgHelpIDs[] = {
        IDC_GE_ICON,        IDH_UNI_GEN_MODEM,
        IDC_ED_FRIENDLYNAME,IDH_UNI_GEN_MODEM,
        IDC_LBL_PORT,       IDH_UNI_GEN_PORT,
        IDC_ST_PORT,        IDH_UNI_GEN_PORT,
        IDC_CB_PORT,        IDH_UNI_GEN_PORT,
        IDC_ED_PORT,        IDH_UNI_GEN_PORT_INT,
        IDC_SPEAKER,        IDH_UNI_GEN_VOLUME,
        IDC_LBL_OFF,        IDH_UNI_GEN_VOLUME,
        IDC_VOLUME,         IDH_UNI_GEN_VOLUME,
        IDC_LOUD,           IDH_UNI_GEN_VOLUME,
//        IDC_SPEED,          IDH_COMM_GROUPBOX,
        IDC_SPEED,          IDH_UNI_GEN_MAX_SPEED,
        IDC_CB_SPEED,       IDH_UNI_GEN_MAX_SPEED,
        IDC_STRICTSPEED,    IDH_UNI_GEN_THIS_SPEED,
        0, 0 };
#pragma data_seg()

    switch (message)
        {
        HANDLE_MSG(this, WM_INITDIALOG, Gen_OnInitDialog);
        HANDLE_MSG(this, WM_HSCROLL, Gen_OnHScroll);
        HANDLE_MSG(this, WM_NOTIFY, Gen_OnNotify);
        HANDLE_MSG(this, WM_DESTROY, Gen_OnDestroy);

    case WM_HELP:
        WinHelp(((LPHELPINFO)lParam)->hItemHandle, c_szWinHelpFile, HELP_WM_HELP, (DWORD)(LPVOID)rgHelpIDs);
        return 0;

    case WM_CONTEXTMENU:
        WinHelp((HWND)wParam, c_szWinHelpFile, HELP_CONTEXTMENU, (DWORD)(LPVOID)rgHelpIDs);
        return 0;

    default:
        return Gen_DefProc(this->hdlg, message, wParam, lParam);
        }
    }


/*----------------------------------------------------------
Purpose: Dialog Wrapper
Returns: varies
Cond:    --
*/
BOOL CALLBACK Gen_WrapperProc(
    HWND hDlg,          // std params
    UINT message,
    WPARAM wParam,
    LPARAM lParam)
    {
    PGEN this;

    // Cool windowsx.h dialog technique.  For full explanation, see
    //  WINDOWSX.TXT.  This supports multiple-instancing of dialogs.
    //
    ENTER_X()
        {
        if (s_bGenRecurse)
            {
            s_bGenRecurse = FALSE;
            LEAVE_X()
            return FALSE;
            }
        }
    LEAVE_X()

    this = Gen_GetPtr(hDlg);
    if (this == NULL)
        {
        if (message == WM_INITDIALOG)
            {
            this = (PGEN)LocalAlloc(LPTR, sizeof(GEN));
            if (!this)
                {
                MsgBox(g_hinst,
                       hDlg, 
                       MAKEINTRESOURCE(IDS_OOM_GENERAL), 
                       MAKEINTRESOURCE(IDS_CAP_GENERAL),
                       NULL,
                       MB_ERROR);
                EndDialog(hDlg, IDCANCEL);
                return (BOOL)Gen_DefProc(hDlg, message, wParam, lParam);
                }
            this->hdlg = hDlg;
            Gen_SetPtr(hDlg, this);
            }
        else
            {
            return (BOOL)Gen_DefProc(hDlg, message, wParam, lParam);
            }
        }

    if (message == WM_DESTROY)
        {
        Gen_DlgProc(this, message, wParam, lParam);
        LocalFree((HLOCAL)OFFSETOF(this));
        Gen_SetPtr(hDlg, NULL);
        return 0;
        }

    return SetDlgMsgResult(hDlg, message, Gen_DlgProc(this, message, wParam, lParam));
    }