-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathSETTINGS.C
1422 lines (1118 loc) · 42 KB
/
SETTINGS.C
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
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*-----------------------------------------------------------------------------
This is a part of the Microsoft Source Code Samples.
Copyright (C) 1995 Microsoft Corporation.
All rights reserved.
This source code is only intended as a supplement to
Microsoft Development Tools and/or WinHelp documentation.
See these sources for detailed information regarding the
Microsoft samples programs.
MODULE: Settings.c
PURPOSE: Controls all dialog controls in the Settings Dialog as well
as the comm events dialog, flow control dialog, and timeouts
dialog. The module also controls the tty settings based on
these dialogs and also control comm port settings using
SetCommState and SetCommTimeouts.
FUNCTIONS:
OpenSettingsToolbar - Creates the Settings Dialog
ChangeConnection - Modifies menus & controls based on connection state
UpdateTTYInfo - Modifies TTY data from Settings Dialog and
if connected, updates open comm port settings
FillComboBox - Fills a combo box with strings
SetComboBox - Selects an entry from a combo box
SettingDlgInit - Initializes settings dialog
GetdwTTYItem - returns a DWORD value from a dialog control
GetbTTYItem - returns a BYTE value from a dialog control
ToolbarProc - Dialog procedure for Settings Dialog
InitHexControl - Places a byte value into edit controls of a dialog
GetHexControl - returns hex data from a control and converts to a TCHAR
InitCommEventsDlg - Initializes Comm Events Dialog
SaveCommEventsDlg - Saves comm events flag if changed
CommEventsProc - Dialog procedure for Comm Events Dialog
SaveFlowControlDlg - Saves flow control settings if changed
InitFlowControlDlg - Inititlizes Flow Control Dialog
FlowDefault - sets "hardware" or "software" flow control
FlowControlProc - Dialog procedure for Flow Control Dialog
InitTimeoutsDlg - Initializes Timeouts Dialog
SaveTimeoutsDlg - Saves comm timeouts from Timeouts Dialog
TimeoutsProc - Dialog procedure for Timeouts Dialog
-----------------------------------------------------------------------------*/
#include <windows.h>
#include <stdio.h>
#include "mttty.h"
#define MAXLEN_TEMPSTR 20
/*
Prototypes for functions called only within this file
*/
void FillComboBox( HWND, TCHAR ** szString, DWORD *, WORD, DWORD );
BOOL SettingsDlgInit( HWND );
DWORD GetdwTTYItem( HWND, int, TCHAR **, DWORD *, int );
BYTE GetbTTYItem( HWND, int, TCHAR **, DWORD *, int);
BOOL CALLBACK CommEventsProc( HWND, UINT, WPARAM, LPARAM );
BOOL CALLBACK ToolbarProc( HWND, UINT, WPARAM, LPARAM );
void InitHexControl(HWND, WORD, WORD, TCHAR);
char GetHexControl(HWND, WORD, WORD);
void SaveCommEventsDlg( HWND );
void InitCommEventsDlg( HWND, DWORD );
BOOL CALLBACK FlowControlProc( HWND, UINT, WPARAM, LPARAM );
void InitFlowControlDlg( HWND );
void SaveFlowControlDlg( HWND );
void FlowDefault(HWND hdlg, WORD wId);
BOOL CALLBACK TimeoutsProc( HWND, UINT, WPARAM, LPARAM );
void InitTimeoutsDlg( HWND, COMMTIMEOUTS );
void SaveTimeoutsDlg( HWND );
BOOL CALLBACK GetADWORDProc( HWND, UINT, WPARAM, LPARAM );
/*
GLOBALS for this file
The string arrays are the items in the dialog list controls.
*/
DCB dcbTemp;
TCHAR * szBaud[] = {
_T("110"), _T("300"), _T("600"), _T("1200"), _T("2400"),
_T("4800"), _T("9600"), _T("14400"), _T("19200"),
_T("38400"), _T("56000"), _T("57600"), _T("115200"),
_T("128000"), _T("256000")
};
DWORD BaudTable[] = {
CBR_110, CBR_300, CBR_600, CBR_1200, CBR_2400,
CBR_4800, CBR_9600, CBR_14400, CBR_19200, CBR_38400,
CBR_56000, CBR_57600, CBR_115200, CBR_128000, CBR_256000
} ;
TCHAR * szParity[] = { _T("None"), _T("Even"), _T("Odd"), _T("Mark"), _T("Space") };
DWORD ParityTable[] = { NOPARITY, EVENPARITY, ODDPARITY, MARKPARITY, SPACEPARITY } ;
TCHAR * szStopBits[] = { _T("1"), _T("1.5"), _T("2") };
DWORD StopBitsTable[] = { ONESTOPBIT, ONE5STOPBITS, TWOSTOPBITS } ;
TCHAR * szDTRControlStrings[] = { _T("Enable"), _T("Disable"), _T("Handshake") };
DWORD DTRControlTable[] = { DTR_CONTROL_ENABLE, DTR_CONTROL_DISABLE, DTR_CONTROL_HANDSHAKE };
TCHAR * szRTSControlStrings[] = { _T("Enable"), _T("Disable"), _T("Handshake"), _T("Toggle") };
DWORD RTSControlTable[] = { RTS_CONTROL_ENABLE, RTS_CONTROL_DISABLE,
RTS_CONTROL_HANDSHAKE, RTS_CONTROL_TOGGLE };
DWORD EventFlagsTable[] = {
EV_BREAK, EV_CTS, EV_DSR, EV_ERR, EV_RING,
EV_RLSD, EV_RXCHAR, EV_RXFLAG, EV_TXEMPTY
};
/*-----------------------------------------------------------------------------
FUNCTION: OpenSettingsToolbar(HWND)
PURPOSE: Open Settings Dialog
PARAMETERS:
hWnd - dialog owner window handle
HISTORY: Date: Author: Comment:
10/27/95 AllenD Wrote it
-----------------------------------------------------------------------------*/
void OpenSettingsToolbar(HWND hWnd)
{
ghWndToolbarDlg = CreateDialog(ghInst, MAKEINTRESOURCE(IDD_TOOLBARSETTINGS), hWnd, ToolbarProc);
if (ghWndToolbarDlg == NULL)
ErrorReporter(_T("CreateDialog (Toolbar Dialog)"));
return;
}
/*-----------------------------------------------------------------------------
FUNCTION: ChangeConnection(HWND, BOOL)
PURPOSE: Modifies connection appearance
PARAMETERS:
hwnd - menu owner windows
fConnected - TRUE sets connection appearance to connected
FALSE sets appearance to not connected
HISTORY: Date: Author: Comment:
10/27/95 AllenD Wrote it
-----------------------------------------------------------------------------*/
void ChangeConnection( HWND hwnd, BOOL fConnected )
{
HMENU hMenu;
int i;
if (fConnected) {
/*
The port is connected. Need to :
Disable connect menu and enable disconnect menu.
Enable file transfer menu
Disable comm port selection box
Disable no writing, no reading, no events, no status check boxes
Enable status check boxes
Set focus to the child tty window
*/
hMenu = GetMenu( hwnd ) ;
EnableMenuItem( hMenu, ID_FILE_CONNECT,
MF_GRAYED | MF_DISABLED | MF_BYCOMMAND ) ;
EnableMenuItem( hMenu, ID_FILE_DISCONNECT,
MF_ENABLED | MF_BYCOMMAND ) ;
EnableMenuItem( hMenu, ID_TRANSFER_SENDFILETEXT,
MF_ENABLED | MF_BYCOMMAND ) ;
EnableMenuItem( hMenu, ID_TRANSFER_RECEIVEFILETEXT,
MF_ENABLED | MF_BYCOMMAND ) ;
EnableMenuItem( hMenu, ID_TRANSFER_SENDREPEATEDLY,
MF_ENABLED | MF_BYCOMMAND ) ;
EnableMenuItem( hMenu, ID_TRANSFER_ABORTSENDING,
MF_DISABLED | MF_GRAYED | MF_BYCOMMAND );
EnableMenuItem( hMenu, ID_TRANSFER_ABORTREPEATEDSENDING,
MF_DISABLED | MF_GRAYED | MF_BYCOMMAND );
EnableWindow( GetDlgItem(ghWndToolbarDlg, IDC_PORTCOMBO), FALSE);
EnableWindow( GetDlgItem(ghWndToolbarDlg, IDC_NOWRITINGCHK), FALSE);
EnableWindow( GetDlgItem(ghWndToolbarDlg, IDC_NOREADINGCHK), FALSE);
EnableWindow( GetDlgItem(ghWndToolbarDlg, IDC_NOEVENTSCHK), FALSE);
EnableWindow( GetDlgItem(ghWndToolbarDlg, IDC_NOSTATUSCHK), FALSE);
for (i = IDC_STATCTS; i <= IDC_STATRLSD; i++)
EnableWindow( GetDlgItem(ghWndStatusDlg, i), TRUE );
for (i = IDC_CTSHOLDCHK; i <= IDC_RXCHAREDIT; i++)
EnableWindow( GetDlgItem(ghWndStatusDlg, i), TRUE);
SetFocus(ghWndTTY);
}
else {
//
// Not connected, do opposite of above.
//
hMenu = GetMenu( hwnd ) ;
EnableMenuItem( hMenu, ID_FILE_CONNECT,
MF_ENABLED | MF_BYCOMMAND ) ;
EnableMenuItem( hMenu, ID_FILE_DISCONNECT,
MF_GRAYED | MF_DISABLED | MF_BYCOMMAND ) ;
EnableMenuItem( hMenu, ID_TRANSFER_SENDFILETEXT,
MF_DISABLED | MF_GRAYED | MF_BYCOMMAND ) ;
EnableMenuItem( hMenu, ID_TRANSFER_RECEIVEFILETEXT,
MF_DISABLED | MF_GRAYED | MF_BYCOMMAND ) ;
EnableMenuItem( hMenu, ID_TRANSFER_SENDREPEATEDLY,
MF_DISABLED | MF_GRAYED | MF_BYCOMMAND ) ;
EnableMenuItem( hMenu, ID_TRANSFER_ABORTSENDING,
MF_DISABLED | MF_GRAYED | MF_BYCOMMAND ) ;
EnableMenuItem( hMenu, ID_TRANSFER_ABORTREPEATEDSENDING,
MF_DISABLED | MF_GRAYED | MF_BYCOMMAND );
EnableWindow( GetDlgItem(ghWndToolbarDlg, IDC_PORTCOMBO), TRUE);
EnableWindow( GetDlgItem(ghWndToolbarDlg, IDC_NOWRITINGCHK), TRUE);
EnableWindow( GetDlgItem(ghWndToolbarDlg, IDC_NOREADINGCHK), TRUE);
EnableWindow( GetDlgItem(ghWndToolbarDlg, IDC_NOEVENTSCHK), TRUE);
EnableWindow( GetDlgItem(ghWndToolbarDlg, IDC_NOSTATUSCHK), TRUE);
for (i = IDC_STATCTS; i <= IDC_STATRLSD; i++) {
CheckDlgButton(ghWndStatusDlg, i, 0);
EnableWindow( GetDlgItem(ghWndStatusDlg, i), FALSE );
}
for (i = IDC_CTSHOLDCHK; i <= IDC_RXCHAREDIT; i++) {
if (i != IDC_TXCHAREDIT && i != IDC_RXCHAREDIT)
CheckDlgButton(ghWndStatusDlg, i, 0);
else
SetDlgItemInt(ghWndStatusDlg, i, 0, FALSE);
EnableWindow( GetDlgItem(ghWndStatusDlg, i), FALSE);
}
SetFocus(ghwndMain);
}
return;
}
/*-----------------------------------------------------------------------------
FUNCTION: UpdateTTYInfo(void)
PURPOSE: Modifies TTY data based on the settings and calls UpdateConnection
COMMENTS: Modifies the data based on the dialog. If connected,
calls UpdateConnection.
HISTORY: Date: Author: Comment:
10/27/95 AllenD Wrote it
1/ 9/96 AllenD Split DCB settings to new function
-----------------------------------------------------------------------------*/
void UpdateTTYInfo()
{
//
// update globals from dialog settings
//
GetDlgItemText(ghWndToolbarDlg, IDC_PORTCOMBO, gszPort, sizeof(gszPort));
BAUDRATE(TTYInfo) = GetdwTTYItem( ghWndToolbarDlg,
IDC_BAUDCOMBO,
szBaud,
BaudTable,
sizeof(BaudTable)/sizeof(BaudTable[0]));
PARITY(TTYInfo) = GetbTTYItem( ghWndToolbarDlg,
IDC_PARITYCOMBO,
szParity,
ParityTable,
sizeof(ParityTable)/sizeof(ParityTable[0]));
STOPBITS(TTYInfo) = GetbTTYItem( ghWndToolbarDlg,
IDC_STOPBITSCOMBO,
szStopBits,
StopBitsTable,
sizeof(StopBitsTable)/sizeof(StopBitsTable[0]));
LOCALECHO(TTYInfo) = IsDlgButtonChecked(ghWndToolbarDlg, IDC_LOCALECHOCHK);
BYTESIZE(TTYInfo) = GetDlgItemInt(ghWndToolbarDlg, IDC_DATABITSCOMBO, NULL, FALSE);
NEWLINE(TTYInfo) = IsDlgButtonChecked(ghWndToolbarDlg, IDC_LFBTN);
CR2CRLF(TTYInfo) = IsDlgButtonChecked(ghWndToolbarDlg, IDC_CRBTN);
AUTOWRAP(TTYInfo) = IsDlgButtonChecked(ghWndToolbarDlg, IDC_AUTOWRAPCHK);
DISPLAYERRORS(TTYInfo) = IsDlgButtonChecked(ghWndToolbarDlg, IDC_DISPLAYERRORSCHK);
NOREADING(TTYInfo) = IsDlgButtonChecked(ghWndToolbarDlg, IDC_NOREADINGCHK);
NOWRITING(TTYInfo) = IsDlgButtonChecked(ghWndToolbarDlg, IDC_NOWRITINGCHK);
NOEVENTS(TTYInfo) = IsDlgButtonChecked(ghWndToolbarDlg, IDC_NOEVENTSCHK);
NOSTATUS(TTYInfo) = IsDlgButtonChecked(ghWndToolbarDlg, IDC_NOSTATUSCHK);
if (CONNECTED(TTYInfo)) // if connected, then update port state
UpdateConnection();
return;
}
/*-----------------------------------------------------------------------------
FUNCTION: UpdateConnection( void )
PURPOSE: Sets port state based on settings from the user
COMMENTS: Sets up DCB structure and calls SetCommState.
Sets up new timeouts by calling SetCommTimeouts.
HISTORY: Date: Author: Comment:
1/ 9/96 AllenD Wrote it
-----------------------------------------------------------------------------*/
BOOL UpdateConnection()
{
DCB dcb = {0};
dcb.DCBlength = sizeof(dcb);
//
// get current DCB settings
//
if (!GetCommState(COMDEV(TTYInfo), &dcb))
ErrorReporter(_T("GetCommState"));
//
// update DCB rate, byte size, parity, and stop bits size
//
dcb.BaudRate = BAUDRATE(TTYInfo);
dcb.ByteSize = BYTESIZE(TTYInfo);
dcb.Parity = PARITY(TTYInfo);
dcb.StopBits = STOPBITS(TTYInfo);
//
// update event flags
//
if (EVENTFLAGS(TTYInfo) & EV_RXFLAG)
dcb.EvtChar = FLAGCHAR(TTYInfo);
else
dcb.EvtChar = '\0';
//
// update flow control settings
//
dcb.fDtrControl = DTRCONTROL(TTYInfo);
dcb.fRtsControl = RTSCONTROL(TTYInfo);
dcb.fOutxCtsFlow = CTSOUTFLOW(TTYInfo);
dcb.fOutxDsrFlow = DSROUTFLOW(TTYInfo);
dcb.fDsrSensitivity = DSRINFLOW(TTYInfo);
dcb.fOutX = XONXOFFOUTFLOW(TTYInfo);
dcb.fInX = XONXOFFINFLOW(TTYInfo);
dcb.fTXContinueOnXoff = TXAFTERXOFFSENT(TTYInfo);
dcb.XonChar = XONCHAR(TTYInfo);
dcb.XoffChar = XOFFCHAR(TTYInfo);
dcb.XonLim = XONLIMIT(TTYInfo);
dcb.XoffLim = XOFFLIMIT(TTYInfo);
//
// DCB settings not in the user's control
//
dcb.fParity = TRUE;
//
// set new state
//
if (!SetCommState(COMDEV(TTYInfo), &dcb))
ErrorReporter(_T("SetCommState"));
//
// set new timeouts
//
if (!SetCommTimeouts(COMDEV(TTYInfo), &(TIMEOUTSNEW(TTYInfo))))
ErrorReporter(_T("SetCommTimeouts"));
return TRUE;
}
/*-----------------------------------------------------------------------------
FUNCTION: FillComboBox(HWND, TCHAR **, DWORD *, WORD, DWORD)
PURPOSE: Populates dialog controls with proper strings
PARAMETERS:
hCtrlWnd - window handle of control being filled
szString - string table contains strings to fill control with
npTable - table of values corresponding to strings
wTableLen - length of the string table
dwCurrentSetting - initialz combo box selection
COMMENTS: This function originally found in the Win32 COMM sample
Written by BryanW. Modified for Win32 MTTTY Sample.
HISTORY: Date: Author: Comment:
10/27/95 AllenD Modified for MTTTY
-----------------------------------------------------------------------------*/
void FillComboBox( HWND hCtrlWnd, TCHAR ** szString,
DWORD * npTable, WORD wTableLen, DWORD dwCurrentSetting )
{
WORD wCount, wPosition ;
for (wCount = 0; wCount < wTableLen; wCount++) {
wPosition = LOWORD( SendMessage( hCtrlWnd, CB_ADDSTRING, 0,
(LPARAM) (LPSTR) szString[wCount] ) ) ;
//
// use item data to store the actual table value
//
SendMessage( hCtrlWnd, CB_SETITEMDATA, (WPARAM) wPosition,
(LPARAM) *(npTable + wCount) ) ;
//
// if this is our current setting, select it
//
if (*(npTable + wCount) == dwCurrentSetting)
SendMessage( hCtrlWnd, CB_SETCURSEL, (WPARAM) wPosition, 0L ) ;
}
return ;
}
/*-----------------------------------------------------------------------------
FUNCTION: SetComboBox(HWND, WORD, DWORD)
PURPOSE: Selects an entry from a dialog combobox
PARAMETERS:
hCtrlWnd - windows handle of control
wTableLen - length of value table for this control
dwNewSetting - new item to base selection on
HISTORY: Date: Author: Comment:
11/20/95 AllenD Wrote it
-----------------------------------------------------------------------------*/
void SetComboBox( HWND hCtrlWnd, WORD wTableLen, DWORD dwNewSetting )
{
WORD wCount, wItemData ;
for (wCount = 0; wCount < wTableLen; wCount++) {
wItemData = LOWORD( SendMessage( hCtrlWnd, CB_GETITEMDATA, (WPARAM) wCount, 0L ) );
if (wItemData == dwNewSetting) {
SendMessage( hCtrlWnd, CB_SETCURSEL, (WPARAM) wCount, 0L ) ;
break;
}
}
return ;
}
/*-----------------------------------------------------------------------------
FUNCTION: SettingsDlgInit(HWND)
PURPOSE: Initializes Settings Dialog
PARAMETERS:
hDlg - Dialog window handle
RETURN: always TRUE
COMMENTS: This function originally found in the Win32 COMM sample
Written by BryanW. Modified for Win32 MTTTY Sample.
HISTORY: Date: Author: Comment:
10/27/95 AllenD Modified for MTTTY
-----------------------------------------------------------------------------*/
BOOL SettingsDlgInit( HWND hDlg )
{
TCHAR szBuffer[ MAXLEN_TEMPSTR ], szTemp[ MAXLEN_TEMPSTR ] ;
WORD wCount, wMaxCOM, wPosition ;
wMaxCOM = MAXPORTS ;
_tcscpy_s(szTemp, MAXLEN_TEMPSTR, _T("COM"));
//
// fill port combo box and make initial selection
//
for (wCount = 0; wCount < wMaxCOM; wCount++) {
wsprintf( szBuffer, _T("%s%d"), (LPSTR) szTemp, wCount + 1 ) ;
SendDlgItemMessage( hDlg, IDC_PORTCOMBO, CB_ADDSTRING, 0,
(LPARAM) (LPSTR) szBuffer ) ;
}
SendDlgItemMessage( hDlg, IDC_PORTCOMBO, CB_SETCURSEL,
(WPARAM) (PORT( TTYInfo ) - 1), 0L ) ;
GetDlgItemText(hDlg, IDC_PORTCOMBO, gszPort, sizeof(gszPort));
//
// fill baud combo box and make initial selection
//
FillComboBox( GetDlgItem( hDlg, IDC_BAUDCOMBO ),
szBaud, BaudTable,
sizeof( BaudTable ) / sizeof( BaudTable[ 0 ] ),
BAUDRATE( TTYInfo ) ) ;
//
// fill data bits combo box and make initial selection
//
for (wCount = 5; wCount < 9; wCount++) {
wsprintf( szBuffer, _T("%d"), wCount ) ;
wPosition = LOWORD( SendDlgItemMessage( hDlg, IDC_DATABITSCOMBO,
CB_ADDSTRING, 0,
(LPARAM) (LPSTR) szBuffer ) ) ;
//
// if wCount is current selection, tell the combo box
//
if (wCount == BYTESIZE( TTYInfo ))
SendDlgItemMessage( hDlg, IDC_DATABITSCOMBO, CB_SETCURSEL,
(WPARAM) wPosition, 0L ) ;
}
//
// fill parity combo box and make initial selection
//
FillComboBox( GetDlgItem( hDlg, IDC_PARITYCOMBO ),
szParity, ParityTable,
sizeof( ParityTable ) / sizeof( ParityTable[ 0 ] ),
PARITY( TTYInfo ) ) ;
//
// fill stop bits combo box and make initial selection
//
FillComboBox( GetDlgItem( hDlg, IDC_STOPBITSCOMBO ),
szStopBits, StopBitsTable,
sizeof( StopBitsTable ) / sizeof ( StopBitsTable[ 0 ] ),
STOPBITS( TTYInfo ) ) ;
//
// set check marks based on TTY data
//
CheckDlgButton( hDlg, IDC_LOCALECHOCHK, LOCALECHO( TTYInfo ) ) ;
CheckDlgButton( hDlg, IDC_DISPLAYERRORSCHK, DISPLAYERRORS( TTYInfo ) );
CheckDlgButton( hDlg, IDC_LFBTN, NEWLINE( TTYInfo ) );
CheckDlgButton( hDlg, IDC_AUTOWRAPCHK, AUTOWRAP( TTYInfo ) );
CheckDlgButton( hDlg, IDC_NOWRITINGCHK, NOWRITING( TTYInfo ) );
CheckDlgButton( hDlg, IDC_NOREADINGCHK, NOREADING( TTYInfo ) );
CheckDlgButton( hDlg, IDC_NOSTATUSCHK, NOSTATUS( TTYInfo ) );
CheckDlgButton( hDlg, IDC_NOEVENTSCHK, NOEVENTS( TTYInfo ) );
return ( TRUE ) ;
} // end of SettingsDlgInit()
/*-----------------------------------------------------------------------------
FUNCTION: GetdwTTYItem(HWND, int, TCHAR **, DWORD *, int)
PURPOSE: Returns a DWORD item from a dialog control
PARAMETERS:
hDlg - Dialog window handle
idControl - id of control to get data from
szString - table of strings that the control displays
pTable - table of data associated with strings
iNumItems - size of table
RETURN:
DWORD item corresponding to control selection
0 if item not found correctly
HISTORY: Date: Author: Comment:
10/27/95 AllenD Wrote it
-----------------------------------------------------------------------------*/
DWORD GetdwTTYItem(HWND hDlg, int idControl, TCHAR ** szString, DWORD * pTable, int iNumItems)
{
int i;
TCHAR szItem[MAXLEN_TEMPSTR];
//
// Get current selection (a string)
//
GetDlgItemText(hDlg, idControl, szItem, sizeof(szItem));
/*
Compare current selection with table to find index of item.
If index is found, then return the DWORD item from table.
*/
for (i = 0; i < iNumItems; i++) {
if (_tcscmp(szString[i], szItem) == 0)
return pTable[i];
}
return 0;
}
/*-----------------------------------------------------------------------------
FUNCTION: GetbTTYItem(HWND, int, TCHAR **, DWORD *, int)
PURPOSE: Returns a BYTE item from a dialog control
PARAMETERS:
hDlg - Dialog window handle
idControl - id of control to get data from
szString - table of strings that the control displays
pTable - table of data associated with strings
iNumItems - size of table
RETURN:
BYTE item from corresponding to control selection
0 if item data not found
HISTORY: Date: Author: Comment:
10/27/95 AllenD Wrote it
-----------------------------------------------------------------------------*/
BYTE GetbTTYItem(HWND hDlg, int idControl, TCHAR ** szString, DWORD * pTable, int iNumItems)
{
int i;
TCHAR szItem[MAXLEN_TEMPSTR];
//
// Get current selection (a string)
//
GetDlgItemText(hDlg, idControl, szItem, sizeof(szItem));
/*
Compare current selection with table to find index of item.
If index is found, then return the BYTE item from table.
*/
for (i = 0; i < iNumItems; i++) {
if (_tcscmp(szString[i], szItem) == 0)
return (BYTE) pTable[i];
}
return 0;
}
/*-----------------------------------------------------------------------------
FUNCTION: ToolbarProc(HWND, UINT, WPARAM, LPARAM)
PURPOSE: Dialog Procedure for Settings Dialog
PARAMETERS:
hWndDlg - Dialog window handle
uMsg - Window message
wParam - message parameter (depends on message)
lParam - message parameter (depends on message)
RETURN:
TRUE if message is handled
FALSE if message is not handled
Exception is WM_INITDIALOG: returns FALSE since focus is not set
HISTORY: Date: Author: Comment:
10/27/95 AllenD Wrote it
-----------------------------------------------------------------------------*/
BOOL CALLBACK ToolbarProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
BOOL fRet = FALSE;
switch(uMsg)
{
case WM_INITDIALOG: // setup dialog with defaults
SettingsDlgInit(hWndDlg);
break;
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case IDC_FONTBTN: // font button pressed
{
CHOOSEFONT cf = {0};
LOGFONT lf;
lf = LFTTYFONT(TTYInfo);
cf.lStructSize = sizeof(CHOOSEFONT);
cf.hwndOwner = hWndDlg;
cf.lpLogFont = &lf;
cf.rgbColors = FGCOLOR(TTYInfo);
cf.Flags = CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS | CF_FIXEDPITCHONLY | \
CF_EFFECTS;
if (!ChooseFont(&cf))
break;
InitNewFont(lf, cf.rgbColors);
//
// fix scroll bar sizes since we may have more or less pixels per
// character now
//
SizeTTY(ghWndTTY, (WORD)XSIZE(TTYInfo), (WORD)YSIZE(TTYInfo));
//
// repaint screen contents
//
InvalidateRect(ghWndTTY, NULL, TRUE);
//
// kill old cursor
//
KillTTYFocus(ghWndTTY);
//
// create new cursor
//
SetTTYFocus(ghWndTTY);
}
fRet = FALSE;
break;
case IDC_COMMEVENTSBTN: // comm events button pressed
DialogBox(ghInst, MAKEINTRESOURCE(IDD_COMMEVENTSDLG), ghwndMain, CommEventsProc);
fRet = FALSE;
break;
case IDC_FLOWCONTROLBTN:
DialogBox(ghInst, MAKEINTRESOURCE(IDD_FLOWCONTROLDLG), ghwndMain, FlowControlProc);
fRet = FALSE;
break;
case IDC_TIMEOUTSBTN:
DialogBox(ghInst, MAKEINTRESOURCE(IDD_TIMEOUTSDLG), ghwndMain, TimeoutsProc);
fRet = FALSE;
break;
default: // some other control has been modified
if (CONNECTED(TTYInfo))
UpdateTTYInfo();
break;
}
}
break;
default:
break;
}
return fRet;
}
/*-----------------------------------------------------------------------------
FUNCTION: InitHexControl(HWND, WORD, WORD, TCHAR)
PURPOSE: Places byte value into two edit boxes of the dialog
PARAMETERS:
hdlg - Dialog Handle
wIdNumberBox - Edit control ID ; displays hex
wIdCharBox - Edit control ID ; displays char
chData - data to display
COMMENTS: Some dialogs may have an edit control designed to accept
hexidecimal input from the user. This function initializes
such edit controls. First, the byte (char) is placed into a
zero terminated string. This is set as the item text of one
of the controls. Next, the byte is converted to a hexidecimal
string. This is set as the item text of the other control.
HISTORY: Date: Author: Comment:
10/27/95 AllenD Wrote it
-----------------------------------------------------------------------------*/
void InitHexControl(HWND hdlg, WORD wIdNumberBox, WORD wIdCharBox, TCHAR chData)
{
TCHAR szFlagText[3] = {0};
TCHAR szFlagChar[2] = {0};
//
// put character into char edit display control
//
szFlagChar[0] = chData;
SetDlgItemText(hdlg, wIdCharBox, szFlagChar);
//
// put flag character into hex numeric edit control
//
wsprintf(szFlagText, _T("%02x"), 0x000000FF & chData);
SetDlgItemText(hdlg, wIdNumberBox, szFlagText);
return;
}
/*-----------------------------------------------------------------------------
FUNCTION: GetHexControl(HWND, WORD, WORD)
PURPOSE: Get hex data from control and convert to character
PARAMETERS:
hdlg - Dialog Handle
wIdNumberBox - Edit control ID ; contains hex string
wIdCharBox - Edit control ID ; displays the char
RETURN:
0 if can't get hex string from edit control
byte value of hex string otherwise
COMMENTS: Function does the following:
1) Gets first two characters from edit control
2) Converts hex string to numeric value
3) Displays ascii char of numeric value
4) Returns numeric value
HISTORY: Date: Author: Comment:
10/27/95 AllenD Wrote it
-----------------------------------------------------------------------------*/
char GetHexControl(HWND hdlg, WORD wIdNumberBox, WORD wIdCharBox)
{
UINT uFlagValue;
TCHAR chFlagEntered[3] = {0};
char chFlag[2] = {0};
TCHAR tchFlag[2] = { 0 };
//
// get numeric value from control
//
if (0 == GetDlgItemText(hdlg, wIdNumberBox, chFlagEntered, 3))
return 0;
_tcscanf_s(chFlagEntered, 3, _T("%x"), &uFlagValue);
chFlag[0] = (char) uFlagValue;
tchFlag[0] = (TCHAR)uFlagValue;
SetDlgItemText(hdlg, wIdCharBox, tchFlag); // display character
return chFlag[0];
}
/*-----------------------------------------------------------------------------
FUNCTION: InitCommEventsDlg(HWND, DWORD)
PURPOSE: Initializes Comm Event Dialog Control
PARAMETERS:
hdlg - Dialog window handle
dwEventFlags - event flag to set controls to
COMMENTS: Since controls are checked based on the dwEventFlags parameter,
it is easy to init control based on current settings,
or default settings.
HISTORY: Date: Author: Comment:
10/27/95 AllenD Wrote it
-----------------------------------------------------------------------------*/
void InitCommEventsDlg(HWND hdlg, DWORD dwEventFlags)
{
int i,j;
for (i = IDC_EVBREAKBTN, j = 0; i <= IDC_EVTXEMPTYBTN; i++, j++)
CheckDlgButton( hdlg, i, dwEventFlags & EventFlagsTable[j]) ;
InitHexControl(hdlg, IDC_FLAGEDIT, IDC_FLAGCHAR, FLAGCHAR(TTYInfo));
EnableWindow(GetDlgItem(hdlg, IDC_FLAGEDIT), dwEventFlags & EV_RXFLAG);
EnableWindow(GetDlgItem(hdlg, IDC_FLAGCHAR), dwEventFlags & EV_RXFLAG);
return;
}
/*-----------------------------------------------------------------------------
FUNCTION: SaveCommEventsDlg(HWND)
PURPOSE: Saves new Comm Events Flag
PARAMETERS:
hdlg - Dialog window handle
COMMENTS: Builds a new flag based on current dialog control.
If the new flag differs from old, then new is updated.
HISTORY: Date: Author: Comment:
10/27/95 AllenD Wrote it
-----------------------------------------------------------------------------*/
void SaveCommEventsDlg(HWND hdlg)
{
int i,j;
DWORD dwNew = {0};
char chNewFlag = '\0';
BOOL fChangingRXFLAG;
//
// create a flag out of dialog selections
//
for (i = IDC_EVBREAKBTN, j = 0; i <= IDC_EVTXEMPTYBTN; i++, j++) {
if (IsDlgButtonChecked(hdlg, i))
dwNew |= EventFlagsTable[j];
}
//
// get current flag character from dialog
//
chNewFlag = GetHexControl(hdlg, IDC_FLAGEDIT, IDC_FLAGCHAR);
fChangingRXFLAG = (EVENTFLAGS(TTYInfo) & EV_RXFLAG) != (dwNew & EV_RXFLAG);
if (chNewFlag != FLAGCHAR(TTYInfo) || fChangingRXFLAG) {
FLAGCHAR(TTYInfo) = chNewFlag;
UpdateTTYInfo();
}
//
// if new flags have been selected, or
//
if (dwNew != EVENTFLAGS(TTYInfo))
EVENTFLAGS(TTYInfo) = dwNew;
return;
}
/*-----------------------------------------------------------------------------
FUNCTION: CommEventsProc(HWND, UINT, WPARAM, LPARAM)
PURPOSE: Dialog Procedure for Comm Events Dialog
PARAMETERS:
hdlg - Dialog window handle
uMessage - window message
wparam - message parameter (depends on message)
lparam - message parameter (depends on message)
RETURN:
TRUE if message is handled
FALSE if message is not handled
Exception is WM_INITDIALOG: returns FALSE since focus is not set
HISTORY: Date: Author: Comment:
10/27/95 AllenD Wrote it
-----------------------------------------------------------------------------*/
BOOL CALLBACK CommEventsProc(HWND hdlg, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
switch(uMessage)
{
case WM_INITDIALOG: // init controls
InitCommEventsDlg(hdlg, EVENTFLAGS(TTYInfo));
break;
case WM_COMMAND:
switch(LOWORD(wparam))
{
case IDOK:
SaveCommEventsDlg(hdlg);
//
// FALL THROUGH
//
case IDCANCEL:
EndDialog(hdlg, LOWORD(wparam));
return TRUE;
case IDC_DEFAULTSBTN:
InitCommEventsDlg(hdlg, EVENTFLAGS_DEFAULT);
return TRUE;
case IDC_EVRXFLAGBTN:
EnableWindow(GetDlgItem(hdlg, IDC_FLAGEDIT), IsDlgButtonChecked(hdlg, IDC_EVRXFLAGBTN));
EnableWindow(GetDlgItem(hdlg, IDC_FLAGCHAR), IsDlgButtonChecked(hdlg, IDC_EVRXFLAGBTN));
return TRUE;
case IDC_FLAGEDIT:
GetHexControl(hdlg, IDC_FLAGEDIT, IDC_FLAGCHAR);
return TRUE;
}
break;
}
return FALSE;
}
/*-----------------------------------------------------------------------------
FUNCTION: SaveFlowControlDlg(HWND)
PURPOSE: Sets TTY flow control settings based on dlg controls
PARAMETERS:
hdlg - Dialog window handle
HISTORY: Date: Author: Comment:
10/27/95 AllenD Wrote it
-----------------------------------------------------------------------------*/
void SaveFlowControlDlg(HWND hdlg)
{
BOOL fNewCTSOut, fNewDSROut, fNewDSRIn, fNewXOut, fNewXIn, fNewTXafterXoffSent;
DWORD dwNewDTRControl, dwNewRTSControl;
WORD wNewXONLimit, wNewXOFFLimit;