forked from Discriminator/PDW
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PDW.cpp
11464 lines (9254 loc) · 347 KB
/
PDW.cpp
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
// PDW.cpp
//
// Main program loop.
//
// This file uses the following functions:
//
// ClearPanes()
// WinMain(), PDWWndProc(), Pane1WndProc(), Pane2WndProc()
// InvertSelection(), CopyToClipboard(), PanePaint(), PaneHScroll()
// PaneVScroll(), GoModalDialogBoxParam(), ErrDlgProc(), ExitDlgProc()
// OkCancelDlgProc(), LogFileDlgProc(), SetupDlgProc(), SelectFont()
// ColorsDlgProc(), ColorWndProc(), OptionsDlgProc(), ScrollDlgProc()
// Copy_Filter_Fields(), BuildFilterString(), FilterDlgProc()
// UpdateSigInd(), MonStatDlgProc(), MonKeepDlgProc()
// CenterOpenDlgBox(), CenterWindow(), ErrorMessageBox()
// SetTitle(), GetPrivateProfileSettings(), GetPrivateProfileDWord()
// WritePrivateProfileSettings(), WritePrivateProfileInt()
// WritePrivateProfileDWord(), GetEditSaveName()
//
//
// PH : Peter Hunt
// RAH: Rutger A. Heunks
// AVE: Andreas Verhoeven
// DD : Danny D.
// AG : Andrey Grodzovsky
// DNL: discriminator.nl
//
//
// 06/04/2003 PH: Added Short Instructions
// 07/04/2003 PH: Short Instructions / Frames optional via menu
// 08/04/2003 PH: Added option to choose separate color for Short Instructions
// 09/04/2003 PH: Displaying of Tone-Only / Numeric now separately selectable
// 10/04/2003 PH: FLEX vector-type is now also displayed
// 11/04/2003 PH: Enlarged filterwindow (CTRL-F)
// 15/04/2003 PH: Switch '/labellog' writes the filterlabels also in monitorlogfile
// 19/05/2003 RAH: Included playback
// 23/05/2003 AVE: Added "PDW Filters(#)" in filter window titlebar.
// 09/06/2003 PH: Added 2-level 3200sps sync-up
// 11/06/2003 PH: Added switch '/callmax' for optimized Callmax-pages
// 26/06/2003 AVE: Added html.cpp & html.h for HTML-logfiles
// 28/06/2003 PH: Added IRC-logfiles via switch '/irc'
// 01/09/2003 PH: Linefeed character will be replaced by '»'
// 02/09/2003 PH: Added extra column "type" for FLEX/POCSAG
// 03/09/2003 PH: Changed GetTimeFormat/Date, now always leading zeros are displayed
// 07/09/2033 PH: Removed Flush-Time. All logfiles will be flushed immediately
// 01/10/2003 PH: Labellog is now optional via Filter-dialog
// 03/10/2003 PH: Bug fixed in FLEX.CPP regarding displayed phases
// 05/10/2003 PH: Added code.wav (for FLEX-short only)
// 06/10/2003 PH: Separate directories for Wavfiles and Logfiles
// 07/10/2003 PH: Filters will now be written to "filters.ini" via WriteFilters()
// 08/10/2003 PH: Code.wav also usable for pocsag
// 11/10/2003 AVE: Added FTP-support (FTP.DLL)
// 12/10/2003 AVE: Filters will now be read from "filters.ini" via ReadFilters() (up to 32.000!)
// 30/10/2003 PH: When exiting PDW, a backup of FILTERS.INI will be made, named FILTERS.BAK
// 03/11/2003 PH: FTP-password is now encrypted (in PDW.INI)
// 11/11/2003 PH: changed WM_KEYDOWN and added VK_SHIFT for scrolling in Pane2
// 12/11/2003 PH: Added "Reload Filters", for use with PDW-Filter
// 13/11/2003 PH: Added ClearScreenDlgProc
//
// 160/196
//
// 14/11/2003 PH: Version 1.2 released !!!
//
// 17/11/2003 PH: Added: hitcounter, date&time of last hit
// 18/11/2003 PH: HTML: Added HTMLTitle & Refresh
// 26/11/2003 PH: HTML: Added URL-filter
// 28/11/2003 PH: FTP : Added FTP-File
// Added Haaglanden.html
// 72/250
//
// 01/12/2003 PH: Version 1.21 released !!!
//
// 01/12/2003 PH: Separate filter messages are now logged to normal filterfile
// AND separate filter file
// 02/12/2003 PH: Added Separate filter HTML-files
// 03/12/2003 PH: Added Statistics.html
//
// 12/04/2004 PH/AVE: New FTP, FTP.DLL not needed anymore
// 21/04/2004 PH: Monitor-only labels made public
// 28/04/2004 PH: Added "Invisible for search engines" (in HTML)
// 28/04/2004 PH: Added FTP-passive mode
// 08/05/2004 PH: Added Label colors
// 15/05/2004 PH: Short Instructions gan now be converted to textmessage
// 18/05/2004 PH: Added cycle/frame information in statusbar
// 06/06/2004 PH: Changed update of HTML-files
// 11/06/2004 PH: Little bugix on SI-conversion (rejecting 20295xx)
// 17/06/2004 PH: Test: cycle/frame instead of MODE
// 23/06/2004 PH: Changed linefeeds for P2000-Amsterdam
// 24/06/2004 PH: Added separate color for biterrors in HTML (CLASS="B")
// 24/06/2004 PH: Changed colors for Convert-SI
//
// 497/3659
//
// 02/07/2004 PH: Version 1.22 released !!!
//
// 04/07/2004 PH: Wordwrap / Linefeed are now selectable options
// 05/07/2004 PH: Bugfix: separate files can now contain pathname
// 06/07/2004 PH: HTML-Statistics is now made an option
// 19/07/2004 PH: Changed command file arguments (%1 %2 %3 %4 %5 %6 %7 %8)
// 29/07/2004 PH: Changed ERMES-format, added 'type'-column
// 30/07/2004 PH: All modes can now log messages as columns
// 01/08/2004 PH: Some little changes in ACARS
// 12/08/2004 PH: Fixed bugs: rejecting FLEX-groupcodes, deleting FLEX tempfiles
// Added "converting to textmessage" for all FLEX-vectors
// 395/1736
//
// 15/08/2004 PH: Version 1.23 released !!!
//
// 16/08/2004 PH: Fixed ERMES bug. Fixed parity-check bug in ACARS
// Modified the columns
//
// 52/176
//
// 18/08/2004 PH: Version 1.24 released !!!
//
// 19/08/2004 PH: Fixed some ACARS bugs
// 22/08/2004 PH: Several ACARS changes + added routes.df + ACARS-HTML
// 25/08/2004 PH: Added: ACARS-filter (Aircraft reg)
// 28/08/2004 PH: Fixed little bug when using HTML & soundcard
// 30/08/2004 PH: Added: Profile.MonthNumber for logfilenames
// 02/09/2004 PH: Added: Class="NOCSS" in case PDW.CSS is missing
// 08/09/2004 PH: Fixed little bug : filtering capcode+text
// 20/09/2004 PH: Added some extra label colors
// 06/10/2004 PH: Added Profile.LogfilePath
// 16/10/2004 PH: Added: user can enter capcode variable in description (%1234567)
// 17/10/2004 PH: Changed ScrollDlgProc (user can enter percentage)
// 01/11/2004 PH: Added: Monitor-Only.wav
// 05/11/2004 PH: Replaced collogfile editboxes by checkboxes
// 08/11/2004 PH: Statistics.HTML can also be uploaded
// 08/11/2004 PH: Added: Warning when resolution is < 800x600
// 09/11/2004 PH: Splitted FilterDlgProc into FilterDlgProc & FilterOptionsDlgProc
//
// 10/11/2004 : Version 2.0 released !!!
// 555/3221
//
// 14/11/2004 PH: Added: Profile.filter_default_type
// 16/11/2004 PH: Added: Profile.Linefeed in Filterwindow
// 17/11/2004 PH: Added: Profile.LabelNewline
// 18/11/2004 PH: Added: Profile.BlockDuplicate
// 19/11/2004 PH: Fixed FLEX SH/TONE bug
// 26/11/2004 PH: Added capcode.wav for wildcards (?->x)
// 29/11/2004 PH: Combined Add and Edit Filter Dialogs
// 30/11/2004 PH: New : UpdateFilterControls()
// 30/11/2004 PH: New : UpdateHTMLControls()
// 30/11/2004 PH: Rejecting texfilters is now possible
// 06/12/2004 HWi: Added FlexTIME
// 18/12/2004 PH: Monitor_Only.wav can be turned on/off per filter
// 19/12/2004 PH: Bugfix displaying phases
// 21/12/2004 HWi: Bugfix slicer.sys
// 22/12/2004 PH: Linefeeds also possible in logfiles
// 23/12/2004 PH: Short Instructions are now displayed in reversed order
// 28/12/2004 HWi: Improved scrolling when dragging in FilterDlg
// 28/12/2004 HWi: When the PC falls in standby mode, PDW doesn't stop anymore
//
// 30/12/2004 : Version 2.1 released!!
// 344/1700
//
// 01/2005 PH: Fixed several bugs regarding pocsag and mobitex
//
// 20/01/2005 : Version 2.11 released!!
// 584/2913
//
// 21/01/2005 PH: Added 'filter.match_exact_text'
//
// 07/03/2005 : Version 2.12 released!!
// 1348/8217
//
// 10/07/2005 PH: Added 'Profile.Hide_Column'
// 21/07/2005 HWi: Fixed disappearing emailaddresses
// Check to see if PDW is already running (in the current directory)
// 01/08/2005 PH: Fixed StNum bug in FLEX
// 05/08/2005 Hwi: The Filterwindow will now automatically resize depending on resolution
// 10/08/2005 PH: The button sizes in filterwindow are now also resolution dependant
// 15/08/2005 PH: Added: Find filter
// 25/08/2005 PH: Added: Search while typing
//
// 27/08/2005 : Version 2.13 released!!
// 1453/9482
//
// 22/09/2005 PH: Added: Additional information in titlebar (FTP/reject/blocked)
// 22/09/2005 PH: Bugfix: When started up, sometimes the first message didn't appear
// correctly (if Hide Column)
// 04/10/2005 PH: Change: CODE.WAV will allways be played, also if no filtermatch
// 03/11/2005 PH: Added: Empty lines / HTML separator after ALPHA/GROUP messages
// 27/11/2005 PH: Added: User can select soundcard
// 02/11/2005 PH: Bugfix: Early wrapping when screen_x=1280 && Hide Column
// 05/12/2005 PH: Added: Reset ALL hitcounters / backup filters.xxx
// 07/12/2005 PH: Added: zDlgProc()
// 09/12/2005 PH: Change: In SelectFont() charactersize limited to 8-12 and a MessageBox
// will appear if the selected fontsize is too big to fit in the columns
// 11/12/2005 PH: Change: Font in IDC_FILTERS is now Lucida Console (fixed font)
// Also changed BuildFilterString, now everyting lines up
// 12/12/2005 PH: Change: InitListControl() now makes a better measurement of the width
// of the ListView to use the window more efficently
// 15/12/2005 PH: Added: FilterEdit => Multiple Edit
// 17/12/2005 PH: Added: Minimize to SystemTray => MoveToSystemTray()
// 13/01/2006 PH: FLEX Groupcalls are now converted via array (no more tempfiles)
// 29/01/2006 PH: Bugfix: ERMES bug (no more junk / ghost messages are being displayed)
//
// 22/02/2006 : Version 2.14 released!!
// 2251/14503
//
// 24/02/2006 PH: Bugfix: The filter window titlebar sometimes displayed wrong filter
// 25/02/2006 PH: Bugfix: Minor fixes on main titlebar
// 26/02/2006 PH: Bugfix: Break on EOT character
// 03/03/2006 PH: Change: HTML-labels same colors as in PDW itself
// 05/03/2006 PH: Optimized Empty lines / HTML separator
// 09/04/2005 PH: Added : Empty lines / HTML separator -> now also for filter window
// 13/04/2006 HWi: Fixed : SMTP TCP/IP bug
// 17/04/2005 PH: Added : Empty lines / HTML separator -> option: also check time
// 19/04/2006 PH: Added : Log only FTP-errors to FTP.LOG
// 26/04/2006 PH: Optimized Empty lines (clear screen / new logfile)
// 27/04/2006 PH: Change: Block Duplicate Messages also blocks duplicate groupcalls
// 29/04/2006 PH: Added : Filtered messages can only be displayed in filterwindow
// 30/04/2006 PH: Change: display_show_crlf() now opens files via OpenGetFilename()
// 17/05/2006 PH: Change: CODE.WAV -> Prio wavfiles
// 18/05/2006 PH: FLEX Groupcalls are now converted via int GroupCapcodes[16][MAXIMUM_GROUPSIZE]
// 01/06/2006 PH: Started using more arrays and definitions (MISC.CPP : CURRENT/PREVIOUS)
// 02/06/2006 PH: Added : Empty lines -> now also for separate filterfiles
// 26/06/2006 PH: Added : iDateUSA
// 29/06/2006 PH: Added : Filtered messages can only be displayed in filterwindow
// 26/07/2006 PH: Fixed : StNum bug in FLEX
// 04/08/2006 PH: Added : Multiple separate filter files (only HTML)
// 05/08/2006 PH: Change: UpdateFilterControls() integrated in FilterEditDlgProc
// using WM_WININICHANGE
// 07/08/2006 Hwi: Change: SMTP.CPP now uses 8-bit charset
// 07/08/2006 PH: Change: Replaced character remapping, so messages appear also remapped
// in logfile and SMTP.
// 13/08/2006 Hwi: Added : Charset selection in SMTP Dialog
// 16/10/2006 PH: Added : Multiple separate filter files (also logfiles)
// 22/10/2006 PH: Added : Custom HTML folder
//
//
// 11/01/2007 : Version 2.15 released!!
// 559/1238
//
// 23/08/2007 : Version 2.2 released!!
// 1716/8104
//
// 19/12/2007 : Version 2.3 released!!
// 638/3497
//
// 16/03/2008 : Version 2.4 released!!
// 774/6400
//
// 19/07/2008 : Version 2.5 released!!
// 188/1529
//
// 16/08/2008 : Version 2.51 released!!
// 431/3252
//
// 12/10/2008 : Version 2.52 released!!
// 556/4571
//
// 11/01/2009 : Version 2.53 released!!
// 601/5057
//
// 24/03/2010 : Version 2.60 released!!
//
// 10/08/2010 : Version 3.0 released!!
// 13/7/2013 DD: Updated About. web url.
// 13/7/2013 DD: Version 3.12 released!
//
// FILTERS.INI lines :
//
// Filter1=0,"1234567","Description / label","text",1,2,3,4,5,"sepfile",118,20-04-04,16:22:22
//
// 0: 1=FLEX , 2=POCSAG , 3=TEXT
// 1: 1=Reject / 2=Monitor-only
// 2: Wavenumber
// 3: 1=CMD-enabled
// 4: 1=Label-enabled += label-color
// 5: 1=SEP-enabled , 2=SEP-HTML , 4=SEP-FTP , 8=SMTP , 16=Match exact text
//
// 12-JUN-2016 AG : SSL support for SMTP mail client
// 20-AUG-2016 DNL: Beta release 3.2b01
//
#ifndef STRICT
#define STRICT 1
#endif
#ifndef STRICT
#define STRICT 1
#endif
#include <windows.h>
#include <commctrl.h>
#include <mmsystem.h>
#include <stdio.h>
#include <commdlg.h>
#include <string.h>
#include <time.h>
#include <shlobj.h>
#include "headers\resource.h"
#include "headers\PDW.h"
#include "headers\slicer.h"
#include "headers\toolbar.h"
#include "headers\gfx.h"
#include "headers\initapp.h"
#include "headers\sigind.h"
#include "headers\decode.h"
#include "headers\sound_in.h"
#include "headers\printer.h"
#include "headers\misc.h"
#include "headers\menu.h"
#include "headers\acars.h"
#include "headers\language.h"
#include "headers\mobitex.h"
#include "headers\ermes.h"
#include "utils\rs232.h"
#include "utils\debug.h"
#include "utils\ostype.h"
#include "utils\smtp.h"
#include "headers\helper_funcs.h" // Extra functies van Andreas
#define MIN_X_WIN_SIZE 444 // Smallest main win X size can be (was 444)
#define MIN_Y_WIN_SIZE 261 // Smallest main win Y size can be (was 261)
#define TOOLBAR_SIZE 49 // Space for Toolbar/Top of Pane1 (was 52)
#define WIN_DIVIDER_SIZE 19 // Pane1/Pane2 seperator size (was 56)
#define PANE1_SIZE 1000 // Pane1 default scrollback size
#define PANE2_SIZE 200 // Pane2 default scrollback size
#define PDW_TIMER 101 // Timer ID
#define SCROLL_TIMER 102
#define SECOND_TIMER 103 // Timer ID
#define MINUTE_TIMER 104 // Timer ID
#define CLICK_TIMER 105 // Timer ID
#define WM_MOUSEWHEEL 0x020A
#define HMENU_MAIN 1
#define HMENU_FILTERS 2
#define HMENU_SYSTRAY 3
#define DRIVER_NOT_LOADED 0
#define DRIVER_VXD_LOADED 1
#define DRIVER_COM_LOADED 2
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define max(a,b) (((a) > (b)) ? (a) : (b))
PROFILE Profile; // User profile information
HANDLE hDriver = 0; // Handle of Virtual Device
int *pComPorts; // Array with available comports
bool bWin9x;
int nDriverLoaded = DRIVER_NOT_LOADED;// VxD/comport loaded?
bool bEditFilter = false; // Set before/after calling edit dialog
bool bPauseFlag = false; // Decides if message output is paused.
bool bUpdateFilters = false; // PH: Needs FILTERS.INI to be updated?
double dRX_Quality;
int nCount_Messages=0; // PH: Counts # Messages
int nCount_Groupcalls=0; // PH: Counts # Groupcalls
int nCount_Biterrors=0; // PH: Counts # Message-biterrors
int nCount_Rejected=0; // PH: Counts # Rejected Messages
int nCount_Blocked=0; // PH: Counts # Blocked Messages
int nCount_Missed[2] = { 0,0 }; // PH: Counts # Missed Groupcalls
int nCount_BlockBuffer[2] = { 0,0 };// PH: Counts # Block Buffer
//int iDebug_Test=0;
int nSMTPsessions=0;
int nSMTPemails=0;
int nSMTPerrors=0;
int iSMTPlastError=0;
int iMouseClick=0; // PH: Used for detecting double click
//int Notification=0; // PH: Used for notification windows
bool bTrayed=false; // PH: Is true if trayed
bool bLBUTTONDBLCLK=false; // PH: Is true after 2 WM_LBUTTONDOWN messages
bool bFilterFindCASE=false; // PH: Filter Find Case Sensitive?
int iTEMP = 0; // Global temporary int
char szTEMP[MAX_STR_LEN]; // Global temporary buffer
int iDuplicateFilter=0;
char szFilenameDate[16]; // PH: Global buffer for date as filename
char szDebugStarted[32]; // PH: Time and date when PDW has been started
char szWindowText[6][1000]; // [0] = PDW version
// [1] = SPARE
// [2] = Current mode
// [3] = FLEX/ERMES cycle/frame(/batch)
// [4] = FLEX - Groupcall
// [5] = Rejected/Blocked messages
// Text editing globals
unsigned int iSelectionStartCol, iSelectionStartRow, iSelectionEndCol, iSelectionEndRow;
int select_on = 0, selected = 0, selecting = 0;
PaneStruct *select_pane; // selects pain to copy text from
// The following COLORREFS are used while changing POCSAG/FLEX colors
COLORREF custom_colors[16];
COLORREF tmp_background;
COLORREF tmp_address;
COLORREF tmp_timestamp;
COLORREF tmp_modetypebit;
COLORREF tmp_numeric;
COLORREF tmp_message;
COLORREF tmp_misc;
COLORREF tmp_filterlabel;
COLORREF tmp_filtermatch;
COLORREF tmp_biterrors;
// Tempory fonts-see gfx.c for other fonts
HFONT tmp_hfont=NULL;
LOGFONT tmp_logfont;
time_t tStarted; // Contains the time when PDW was started
// If copy upper/lower pane or just copy is successful then this flag is set to TRUE.
bool bOK_to_save=false;
char *pdw_version = "PDW v3.2b01"; // Current version info
// RAH: record and playback stuff
OPENFILENAME openplayback;
OPENFILENAME openrecording;
char szPlayback[MAX_PATH];
char szRecording[MAX_PATH];
//HWi
typedef enum sroll
{
scrollNull,
scrollUp,
scrollDown
} EScrollDirection;
HIMAGELIST hDragImageList;
LPNMHDR pnmhdr;
bool bDragging, bDragLine;
bool bSortingFilters, bDeletingFilters;
LVHITTESTINFO lvhti;
HWND hListView, hDebugDlg, hSystemTrayDlg, hFilterDlg, hCurrentHWND;
int m_uScrollTimer, m_ScrollDirection, m_nScrollOffset, m_nDropIndex=-1;
int nCopyStart=-1, nCopyEnd=-1;
void OnBeginDrag(NMHDR* pnmhdr);
void InitListControl(HWND hDlg);
bool WINAPI InsertListViewItem(char *szLine, int nItem);
void OnMouseMove(UINT nFlags, int x, int y);
void OnMouseWheel(WPARAM wParam, int x, int y, RECT g_rect);
void OnLButtonUp(UINT nFlags, int x, int y);
void DropItemOnList(int x, int y);
void OnTimer(UINT nIDEvent);
void KillScrollTimer(void);
void SetScrollTimer(EScrollDirection ScrollDirection);
LONG OnCustomDraw(LPNMLVCUSTOMDRAW lpDraw);
void SortFilter(HWND hDlg, bool bAddress);
bool CheckSelection(bool bMore);
int CompareCapcodes(char *szCapcode1, char *szCapcode2);
void CopyFilter(void);
void PasteFilter(void);
void ResetHitcounters(bool bAll);
void ShowContextMenu(int menu, HWND hWindow);
void GoogleMaps(int iPosition);
void SelectByDoubleClick(HWND hWnd, PaneStruct *pane, int iPosition, int StartRow);
int FindFilter(int index, char *szSearchString, bool bShowHits, bool bBackwards);
void pumpMessages(void);
DWORD GetColorRGB(BYTE color);
void AutoRecording(); // PH: temp/test
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
{
// RAH: setup common file dialog data
ZeroMemory(&openplayback, sizeof(openplayback));
ZeroMemory(&openrecording,sizeof(openrecording));
openplayback.lStructSize = sizeof(openplayback);
openrecording.lStructSize = sizeof(openrecording);
szPlayback[0] = '\0';
MSG msg;
ghWnd = NULL;
ghInstance = hInstance;
Profile.LabelLog = 1; // Flag for labels in monitored-logfile
Profile.LabelNewline = 1; // Flag for labels on new line
Profile.ColLogfile[0] = '\0'; // Flag for columns in logfile
Profile.ColFilterfile[0] = '\0'; // Flag for columns in filterfiles
Profile.Linefeed = 1; // Flag for converting » to linefeed
Profile.Separator = 1; // Flag for separating messages (empty line)
Profile.MonthNumber = 1; // Flag for using monthnumber in logfilenames
Profile.DateFormat = 0; // Flag for date format
Profile.BlockDuplicate = 0; // Flag for blocking duplicate messages
Profile.FilterWindowColors = 1; // Flag for showing label colors in filterwindow
Profile.FilterWindowExtra = 1; // Flag for showing CMD/DESC/SEP/etc in filterwindow
Profile.SystemTray = 0; // Flag for enabeling the system tray
Profile.SystemTrayRestore = 0; // Flag for enabeling auto restore from tray
Profile.SMTP = 0; // Flag for SMTP-email
Profile.FlexTIME = 0; // Flag for FlexTIME as systemtime
Profile.FlexGroupMode = 0;
Profile.xPos = 0;
Profile.yPos = 0;
Profile.xSize = 593;
Profile.ySize = 442;
Profile.showtone = 1;
Profile.shownumeric = 1;
Profile.showmisc = 1;
Profile.filterbeep = 0;
Profile.filterwindowonly = 0; // Show filtered messages only in filterwindow
Profile.confirmExit = 1;
Profile.decodepocsag = 1;
Profile.decodeflex = 1;
Profile.showinstr = 1; // PH: Show Short Instructions
Profile.convert_si = 1; // PH: Convert Short Instructions to textmessage
Profile.pocsag_512 = 1;
Profile.pocsag_1200 = 1;
Profile.pocsag_2400 = 1;
Profile.pocsag_fnu = 0;
Profile.pocsag_showboth = 0;
Profile.flex_1600 = 1;
Profile.flex_3200 = 1;
Profile.flex_6400 = 1;
Profile.acars_parity_check = 0;
Profile.comPortEnabled = 0;
Profile.comPort = 2;
Profile.comPortRS232 = 0;
Profile.comPortAddr = 0x2F8;
Profile.comPortIRQ = 3;
Profile.invert = 0; // Current invert status. 0=No,1=Yes
Profile.fourlevel = 0;
Profile.percent = 65; // Set pane1 to 65% of client area
// setup default font information
Profile.fontInfo.lfHeight = -11;
Profile.fontInfo.lfWidth = 0;
Profile.fontInfo.lfEscapement = 0;
Profile.fontInfo.lfOrientation = 0;
Profile.fontInfo.lfWeight = FW_NORMAL;
Profile.fontInfo.lfItalic = 0;
Profile.fontInfo.lfUnderline = 0;
Profile.fontInfo.lfStrikeOut = 0;
Profile.fontInfo.lfCharSet = OEM_CHARSET;
Profile.fontInfo.lfOutPrecision = OUT_STROKE_PRECIS;
Profile.fontInfo.lfClipPrecision = CLIP_DEFAULT_PRECIS;
Profile.fontInfo.lfQuality = DEFAULT_QUALITY;
Profile.fontInfo.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;
lstrcpy(Profile.fontInfo.lfFaceName, "Courier New");
Profile.reverse_msg = FALSE; // Flag to reverse message output.
Profile.lang_mi_index = 0; // Set default language menu item.
Profile.lang_tbl_index= 0; // Decides language character map.
Profile.logfile_enabled = 1;
Profile.logfile[0] = '\0';
Profile.logfile_use_date = 1;
Profile.edit_save_file[0] = '\0';
Profile.maximize_flg = 1;
Profile.filterfile_enabled = 1;
Profile.filterfile[0] = '\0';
Profile.filterfile_use_date = 1;
Profile.filter_cmd_file_enabled = 0;
Profile.filter_cmd[0] = '\0';
Profile.filter_cmd_args[0] = '\0';
Profile.filter_default_type = 0;
Profile.filters.clear();
// COLORS.
Profile.color_background = RGB(rgbColor[BLACK][0], rgbColor[BLACK][1], rgbColor[BLACK][2]);
Profile.color_address = RGB(rgbColor[WHITE][0], rgbColor[WHITE][1], rgbColor[WHITE][2]);
Profile.color_modetypebit = RGB(rgbColor[RED][0], rgbColor[RED][1], rgbColor[RED][2]);
Profile.color_timestamp = RGB(rgbColor[LTBLUE][0], rgbColor[LTBLUE][1], rgbColor[LTBLUE][2]);
Profile.color_numeric = RGB(rgbColor[RED][0], rgbColor[RED][1], rgbColor[RED][2]);
Profile.color_message = RGB(rgbColor[LTCYAN][0], rgbColor[LTCYAN][1], rgbColor[LTCYAN][2]);
Profile.color_misc = RGB(rgbColor[BROWN][0], rgbColor[BROWN][1], rgbColor[BROWN][2]);
Profile.color_biterrors = RGB(rgbColor[LTGRAY][0], rgbColor[LTGRAY][1], rgbColor[LTGRAY][2]);
Profile.color_filtermatch = RGB(rgbColor[LTGREEN][0],rgbColor[LTGREEN][1],rgbColor[LTGREEN][2]);
Profile.color_instructions = RGB(rgbColor[LTCYAN][0], rgbColor[LTCYAN][1], rgbColor[LTCYAN][2]);
Profile.color_ac_message_nr = RGB(rgbColor[WHITE][0], rgbColor[WHITE][1], rgbColor[WHITE][2]);
Profile.color_ac_dbi = RGB(rgbColor[RED][0], rgbColor[RED][1], rgbColor[RED][2]);
Profile.color_mb_sender = RGB(rgbColor[RED][0], rgbColor[RED][1], rgbColor[RED][2]);
// Filter label colors
Profile.color_filterlabel[0] = RGB(rgbColor[LTBLUE][0], rgbColor[LTBLUE][1], rgbColor[LTBLUE][2]);
Profile.color_filterlabel[1] = RGB(rgbColor[YELLOW][0], rgbColor[YELLOW][1], rgbColor[YELLOW][2]);
Profile.color_filterlabel[2] = RGB(rgbColor[RED][0], rgbColor[RED][1], rgbColor[RED][2]);
Profile.color_filterlabel[3] = RGB(0xFF, 0xAA, 0x00); /* orange */
Profile.color_filterlabel[4] = RGB(rgbColor[LTBLUE][0], rgbColor[LTBLUE][1], rgbColor[LTBLUE][2]);
Profile.color_filterlabel[5] = RGB(rgbColor[CYAN][0], rgbColor[CYAN][1], rgbColor[CYAN][2]);
Profile.color_filterlabel[6] = RGB(rgbColor[WHITE][0], rgbColor[WHITE][1], rgbColor[WHITE][2]);
Profile.color_filterlabel[7] = RGB(rgbColor[LTGREEN][0],rgbColor[LTGREEN][1],rgbColor[LTGREEN][2]);
Profile.color_filterlabel[8] = RGB(rgbColor[LTGRAY][0], rgbColor[LTGRAY][1], rgbColor[LTGRAY][2]);
Profile.color_filterlabel[9] = RGB(rgbColor[BROWN][0], rgbColor[BROWN][1], rgbColor[BROWN][2]);
Profile.color_filterlabel[10] = RGB(rgbColor[LTCYAN][0], rgbColor[LTCYAN][1], rgbColor[LTCYAN][2]);
Profile.color_filterlabel[11] = RGB(0x00, 0x33, 0x99); /* navy blue */
Profile.color_filterlabel[12] = RGB(0xFF, 0x00, 0xFF); /* magenta */
Profile.color_filterlabel[13] = RGB(0x33, 0xCC, 0x99); /* sea green */
Profile.color_filterlabel[14] = RGB(0xFF, 0x99, 0xCC); /* pink */
Profile.color_filterlabel[15] = RGB(0x99, 0xFF, 0xFF); /* ice blue */
Profile.color_filterlabel[16] = RGB(0x99, 0xFF, 0xCC); /* turquoise */
Profile.pane1_size = PANE1_SIZE;
Profile.pane2_size = PANE2_SIZE;
Profile.ScrollSpeed = 1;
Profile.stat_file_enabled = 0;
Profile.stat_file[0] = '\0';
Profile.stat_file_use_date = 0;
// These control Audio input.
Profile.audioEnabled = 1;
Profile.audioDevice = 0;
Profile.audioSampleRate = 44100;
Profile.audioConfig = 5; // Audio input configuration.
Profile.audioThreshold[4] = 0;
Profile.audioResync[4] = 0;
Profile.audioCentering[4] = 0;
SetAudioConfig(Profile.audioConfig); // Set default audio config
Profile.minimize_flg = 0; // Keep track of minimized state (user could exit while minimized)
Profile.monitor_paging = true; // Default is to decode POCSAG/FLEX signals.
Profile.monitor_acars = false;
Profile.monitor_mobitex = false;
Profile.monitor_ermes = false;
nOSType = GetOSType(NULL); // HWi
bWin9x = (nOSType < OS_WIN2000) ? true : false;
if (!hPrevInstance && !InitApplication(hInstance))
{
ErrorMessageBox(TEXT("InitApplication() Failed"),
szApiFailedMsg, lpszSourceFileName, __LINE__);
return (FALSE);
}
CreateMutex(NULL, FALSE, szPath); // Check if PDW is already running
if (GetLastError() == ERROR_ALREADY_EXISTS) // Shut down, as an instance of PDW is
{ // already running in this folder
MessageBox(ghWnd, "PDW is already running", "Warning", MB_ICONINFORMATION);
return (FALSE);
}
if ((ghWnd = InitInstance(hInstance, nCmdShow)) == NULL)
{
ErrorMessageBox(TEXT("InitInstance() Failed"),
szApiFailedMsg, lpszSourceFileName, __LINE__);
return (FALSE);
}
if (hToolbar) TB_AutoSize(hToolbar); // keep toolbar correct size!
acars.read_data(); // Load Acars data base files.
read_language_tables(); // Load language tables.
set_lang_menu(); // Add languge menu items.
set_menu_items(); // Check/Uncheck required menu items.
SetWindowPaneSize(WINDOW_SIZE); // PH: Set Max_X_Client / iMaxWidth / NewLinePoint
sprintf(szWindowText[0], " %s", pdw_version); // PH: Set version info in szWindowText buffer
Get_Date_Time();
sprintf(szDebugStarted, "%s %s", szCurrentDate, szCurrentTime);
pComPorts = FindComPorts(); // Put all available comports in array pComports
tStarted = time(NULL); // Time when PDW was started
// Load VxD if using serial port else see if using sound card
if (Profile.comPortEnabled && !nDriverLoaded)
{
if (LoadDriver())
{
SetTimer(ghWnd, PDW_TIMER, 100, (TIMERPROC) NULL); // start timer.
}
}
else if (Profile.audioEnabled && !bCapturing)
{
if (Start_Capturing())
{
SetTimer(ghWnd, PDW_TIMER, 100, (TIMERPROC) NULL); // start timer.
}
}
SetTimer(ghWnd, MINUTE_TIMER, 1000*60, (TIMERPROC) NULL); // start minute timer
SetTimer(ghWnd, SECOND_TIMER, 1000, (TIMERPROC) NULL); // start second timer
if (Max_X_Client < 800) // PH: Check if the screen width is less than 800
{
MessageBox(ghWnd, "WARNING! PDW is optimized for 800x600 resolution (and higher)\nYour computer seems to be using a lower resolution...", "PDW Resolution", MB_ICONWARNING);
}
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(ghWnd, ghAccel, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return ((int) msg.wParam);
} // end of WinMain()
// Used if WM_CREATE fails or when program exits.
void Free_Common_Objects(void)
{
if (Pane1.buff_char != NULL) free(Pane1.buff_char);
if (Pane1.buff_color != NULL) free(Pane1.buff_color);
if (Pane2.buff_char != NULL) free(Pane2.buff_char);
if (Pane2.buff_color != NULL) free(Pane2.buff_color);
Free_Drawing_Objects(); // see gfx.cpp
FreeSysObjects(); // see gfx.cpp
FreeLogFONTS(); // see gfx.cpp
FreeSigInd(); // see sigind.cpp
FreeToolBarImages(ghInstance); // Free toolbar button bitmaps
}
LRESULT FAR PASCAL PDWWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HDC ghDC;
TEXTMETRIC g_tm;
static RECT g_rect={0};
RECT g_sys_rect;
size_t g_mem_size;
LPMINMAXINFO lpMMI;
time_t lTime;
struct tm *recTm;
int g_xNew, g_yNew, g_scrollSize;
unsigned int g_min_col, g_max_col, g_min_row, g_max_row, g_index;
extern bool bMode_IDLE; // Set if no signal
extern bool bEmpty_Frame; // Set if FLEX-Frame=EMTPY / ERMES-Batch=0
char szFile[MAX_PATH];
char filters_reload[64]; // PH: Buffer for reloading filters
char filters_temp[64]; // PH: Buffer for reloading filters
bool pane1=false;
extern unsigned long int aMessages[1000][3]; // PH: Array used for blocking messages
int BlockTimer = (Profile.BlockDuplicate >> 4) * 60;
switch (uMsg)
{
case WM_TIMER: // Decode POCSAG/FLEX with comport or sound card.
if (!bPauseFlag)
{
if (bPlayback) pdw_playback(); // RAH: Playing recording?
else if (nDriverLoaded) pdw_decode(); // Log messages/statistics & Update signal indicator.
else if (bCapturing) Process_ReadyBuffers(hWnd);// Using sound card?
switch (wParam)
{
case SECOND_TIMER:
DrawPaneLabels(ghWnd, PANERXQUAL);
lTime = time(NULL); // Get current systemtime
iSecondsElapsed = difftime(lTime, tStarted);
if (BlockTimer)
{
while (aMessages[0][0] && (iSecondsElapsed > (aMessages[0][1] + BlockTimer))) // First entry Overdue?
{
memmove(aMessages[0], aMessages[1], sizeof(aMessages)); // Move entries
nCount_BlockBuffer[0]--;
}
}
if (hDebugDlg) SendMessage(hDebugDlg, WM_WININICHANGE, 0, 0L);
break;
case MINUTE_TIMER: // Handle minute timer
if (bMode_IDLE || bEmpty_Frame || Profile.monitor_acars || Profile.monitor_mobitex)
{
if (bUpdateFilters)
{
WriteFilters(&Profile, 0); // PH: Save FILTERS.INI
bUpdateFilters = false; // PH: Reset for new messages
}
}
lTime = time(NULL);
recTm = localtime(&lTime);
if ((recTm->tm_mon == 4) && (recTm->tm_mday == 4)) strcpy(szWindowText[1], "Today is Peter Hunt's birthday :-)");
else if ((recTm->tm_mon == 11) && ((recTm->tm_mday == 25) || (recTm->tm_mday == 26))) strcpy(szWindowText[1], "Merry Christmas!");
else if ((recTm->tm_mon == 0) && (recTm->tm_mday == 1)) strcpy(szWindowText[1], "Happy New Year!");
else strcpy(szWindowText[1], "");
if (FindWindow(NULL, "PDW Resolution")) // Check if there is a "PDW Resolution" dialog
{
PostMessage(FindWindow(NULL, "PDW Resolution"), WM_CLOSE, 0, 0L); // Close it
}
if (bAutoRecording)
{
AutoRecording(); // PH: temp/test
}
break;
case CLICK_TIMER: // Handle click timer
KillTimer(ghWnd, CLICK_TIMER); // Stop Click Timer
iMouseClick=0;
break;
}
}
break;
case WM_POWERBROADCAST :
OUTPUTDEBUGMSG((("WM_POWERBROADCAST PowerMode = 0x%08lX Data 0x%08lX\n"), (DWORD) wParam, (DWORD) lParam));
if (bWin9x)
{
switch(wParam)
{
case PBT_APMRESUMECRITICAL :
case PBT_APMRESUMESUSPEND :
case PBT_APMRESUMESTANDBY :
case PBT_APMRESUMEAUTOMATIC :
OUTPUTDEBUGMSG((("Out of Suspend: Reload VxD!\n")));
UnloadDriver();
pd_reset_all();
if (LoadDriver())
{
SetTimer(ghWnd, PDW_TIMER, 100, (TIMERPROC) NULL);
}
break ;
default:
break ;
}
}
break ;
case WM_PAINT: // Keep main gfx data valid
PAINTSTRUCT pdw_ps;
BeginPaint(hWnd,&pdw_ps);
DrawSigInd(hWnd); // Draw the signal indicator
DrawTitleBarGfx(hWnd); // Draw pane1/pane2 title bars
EndPaint(hWnd,&pdw_ps);
break;
case WM_NOTIFY: // If we receive this message, need to get toolbar tooltip text
switch (((LPNMHDR)lParam)->code)
{
case TTN_NEEDTEXT:
SetToolTXT(ghInstance, lParam);
break;
default:
DrawSigInd(hWnd); // Draw the signal indicator
break;
}
DrawTitleBarGfx(hWnd); // Draw pane1/pane2 title bars
break;
case WM_CREATE:
Pane1.buff_char = NULL;
Pane1.buff_color = NULL;
Pane2.buff_char = NULL;
Pane2.buff_color = NULL;
if (!(LoadSigInd(ghInstance))) return(-1);
if (!(GetSysObjects(hWnd)))// Get general purpose drawing objects.
{
Free_Common_Objects(); // Free any objects we got!
return(-1); // These use standard system colors.
}
if (!(GetLogFONTS())) // Get general purpose font objects.
{
Free_Common_Objects(); // Free any objects we got!
return(-1);
}
if (!(hToolbar = (HWND)ShowMakeToolBar(hWnd,ghInstance))) // Display tool bar
{
Free_Common_Objects(); // Free any objects we got!
return(-1);
}
hfont = CreateFontIndirect(&Profile.fontInfo);
ghDC = GetDC(hWnd);
SelectObject(ghDC, hfont);
GetTextMetrics(ghDC, &g_tm);
cxChar = g_tm.tmAveCharWidth;
cxCaps = (g_tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar / 2;
cyChar = g_tm.tmHeight + g_tm.tmExternalLeading;
ReleaseDC(hWnd, ghDC);
g_mem_size = (Profile.pane1_size+1) * (LINE_SIZE+1);
Pane1.buff_char = (char *)malloc(g_mem_size);
Pane1.buff_color = (BYTE *)malloc(g_mem_size);
if ((Pane1.buff_char == NULL) || (Pane1.buff_color == NULL))
{
if (Pane1.buff_char != NULL) free (Pane1.buff_char);
if (Pane1.buff_color != NULL) free (Pane1.buff_color);
Pane1.buff_char = NULL;
Pane1.buff_color = NULL;
Profile.pane1_size = PANE1_SIZE;
g_mem_size = (Profile.pane1_size+1) * (LINE_SIZE+1);
Pane1.buff_char = (char *)malloc(g_mem_size);
if (Pane1.buff_char == NULL)
{
Free_Common_Objects(); // Free any objects we got!
return(-1);
}
Pane1.buff_color = (BYTE *)malloc(g_mem_size);
if (Pane1.buff_color == NULL)
{
Free_Common_Objects(); // Free any objects we got!
return(-1);
}
}
Pane1.buff_lines = Profile.pane1_size;
g_mem_size = (Profile.pane2_size+1) * (LINE_SIZE+1);
Pane2.buff_char = (char *)malloc(g_mem_size);
Pane2.buff_color = (BYTE *)malloc(g_mem_size);
if ((Pane2.buff_char == NULL) || (Pane2.buff_color == NULL))
{
if (Pane2.buff_char != NULL) free (Pane2.buff_char);
if (Pane2.buff_color != NULL) free (Pane2.buff_color);
Pane2.buff_char = NULL;
Pane2.buff_color = NULL;
Profile.pane2_size = PANE2_SIZE;
g_mem_size = (Profile.pane2_size+1) * (LINE_SIZE+1);
Pane2.buff_char = (char *)malloc(g_mem_size);
if (Pane2.buff_char == NULL)
{
Free_Common_Objects(); // Free any objects we got!
return(-1);
}
Pane2.buff_color = (BYTE *)malloc(g_mem_size);
if (Pane2.buff_color == NULL)
{
Free_Common_Objects(); // Free any objects we got!
return(-1);
}
}
Pane2.buff_lines = Profile.pane2_size;
InitializePane(&Pane1);
InitializePane(&Pane2);
Pane1.hWnd = CreateWindow(gszPane1Class, NULL, WS_CHILD | WS_VISIBLE, 0,0,0,0, hWnd,
NULL, (HINSTANCE) GetWindowLong(hWnd, GWL_HINSTANCE), 0);
if (Pane1.hWnd == NULL)
{
Free_Common_Objects(); // Free any objects we got!