forked from topjoo/dnw
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEngine.cpp
More file actions
9651 lines (7075 loc) · 248 KB
/
Engine.cpp
File metadata and controls
9651 lines (7075 loc) · 248 KB
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
// =============================================
// Program Name: engine
// =============================================
#define STRICT
#define WIN32_LEAN_AND_MEAN
#define REMOVED_AFTER_PRESS_CTRL_C 0 // FEATURing 2019.07.12
#include "resource.h"
#include <windows.h>
#include <stdio.h>
#include <mmsystem.h>
#include <winreg.h>
#include <windowsx.h>
#include <CommCtrl.h> /// 2010.05.28 added.
#include <process.h> /* 2016.02.19 : For _beginthread() */
#include <wchar.h>
//#include <crtdbg.h> // memory leakage check
#if 0
#pragma comment(lib, "comctl32.lib") /// 2013.05.22
#endif
#pragma hdrstop
#include <stdio.h> //for _vsntprintf()
#include <stdarg.h> // for va_list, va_start
#include <string.h> // for memset
#include <stdlib.h>
#include <tchar.h>
#include <stddef.h>
#include <conio.h>
#include <time.h>
#include <winuser.h>
#include <math.h> // 2017.08.30
#if RICHED_COLOR // 2016.09.19 +++++++++
#include <richedit.h>
#endif
#include "engine.h"
#include "dnw.h"
#include "fileopen.h"
#include "font.h"
#include "d_box.h"
#include "usbtxrx.h"
#include "regmgr.h" // added.
#include "md5.h"
#include ".\sha3\sha3.h" // 2017.08.22
#include ".\has160\has160.h" // 2018.06.15
#include ".\BLAKE\blake.h" // 2018.06.15
#if USE_RX_TX_QUEUE
#include "queue.h"
//------------------------------
// Queue
//------------------------------
extern ctQueue Rx2Tx;
#endif
extern BOOL isFileExist(TCHAR *file);
extern BOOL ExecProgram (LPCTSTR lpAppName, LPTSTR lpCmdLine);
void CheckSum_MD5(void *args);
void CheckSum_SHA1(void *args);
void CheckSum_CRC32(void *args);
void CheckSum_CRC64(void *args);
void CheckSum_SHA2_256(void *args);
void CheckSum_SHA2_384(void *args);
void CheckSum_SHA2_512(void *args);
void CheckSum_SHA2_224(void *args);
void CheckSum_MD6(void *args);
void CheckSum_SHA3_KECCAK_224(void *args); // 2017.08.22
void CheckSum_SHA3_KECCAK_256(void *args); // 2017.08.22
void CheckSum_SHA3_KECCAK_384(void *args); // 2017.08.22
void CheckSum_SHA3_KECCAK_512(void *args); // 2017.08.22
void CheckSum_SHAKE128(void *args); // 2017.08.29
void CheckSum_SHAKE256(void *args);
void CheckSum_Blake224(void *args); // 2018.06.15
void CheckSum_Blake256(void *args);
void CheckSum_Blake384(void *args);
void CheckSum_Blake512(void *args);
void CheckSum_KR_HAS160(void *args); // 2018.06.15
void CheckSum_Tiger1995(void *args);
void CheckSum_RIPEMD160(void *args); // 2018.06.22
void ThreadLogSaveFunc(void *args);
void DoBeforeExit(HWND hwnd); // 2017.05.11
void MenuCheckSum(HWND hwnd, int checksum_type);
void MenuSaveLog(HWND hwnd); // 2016.02.23
extern void BeepSound(int beeptype);
extern void LOGFile_close(void);
extern BOOL LOGFile_open(void);
extern int ProcessorType(void);
extern unsigned __int64 LinuxDate2Number( mjd_timestamp LTime );
#if (RICHED_COLOR) || (TEXT_FIND_MARK) // 2016.09.23
extern int txtColorRed, txtColorMegenta, txtColorBlue, txtColorGreen, txtColorYellow;
extern int txtFindRed, txtFindMegenta, txtFindBlue, txtFindGreen, txtFindYellow;
extern int iLenDataRed, iLenDataMagenta, iLenDataBlue, iLenDataGreen, iLenDataYellow;
extern TCHAR szDataRed[MAX_PATH];
#if 0
extern TCHAR szDataMagenta[MAX_PATH];
extern TCHAR szDataBlue[MAX_PATH];
extern TCHAR szDataGreen[MAX_PATH];
extern TCHAR szDataYellow[MAX_PATH];
#endif
void InitFindMark(COLORREF tColor);
void IsMarking(void);
#define MARK_RED TEXT("***")
#define MARK_NULL TEXT(" ")
#endif
#if RICHED_COLOR// 2016.09.22
void RichEditInit(void);
void RichTxtColor(DWORD xx, DWORD yy, DWORD line, COLORREF tColor);
static HMODULE hDll = NULL; /// added.
CHARFORMAT cf;
#endif
#if (TEXT_FIND_MARK) // 2016.09.23
extern int isTxtMark;
extern long long HashRed, HashMagenta;
#endif
#if LOG_SAVE_BY_THREAD // 2016.02.25
#define FILE_WRITE_QUEUE_SIZE 2000
TCHAR buf2write[FILE_WRITE_QUEUE_SIZE][STRING_LEN+4096] = {0,};
int qindex = 0; // initial
#endif
unsigned __int64 ulCRCFileSize = 0UL; // 2017.08.28
unsigned __int64 ulCRCFileRead = 0UL; // 2017.08.28 __int64 -> unsigned __int64
TCHAR gszCRCFileName[FILENAMELEN] = {0,};
TCHAR szCRCTitleName[FILENAMELEN] = {0,};
TCHAR gszPrtFileName[FILENAMELEN] = {0,};
int iidx=0, jidx=0, isFind=0;
int g_ChecksumCalcing = CHECKSUM_UNKNOWN;
const char* szCRCtype[CHECKSUM_MAX+1] = {
NULL,
"MD5",
"SHA1",
"CRC32",
"CRC64",
"SHA2-256",
"SHA2-384",
"SHA2-512",
"SHA2-224",
"MD6",
"SHA3-224 (Keccak)", // 2017.08.22
"SHA3-256 (Keccak)", // 2017.08.22
"SHA3-384 (Keccak)", // 2017.08.22
"SHA3-512 (Keccak)", // 2017.08.22
"Shake128 (256bit)", // SHAKE128_DIGEST_DEFAULT_SIZE CHECKSUM_SHAKE_128
"Shake256 (512bit)", // SHAKE256_DIGEST_DEFAULT_SIZE CHECKSUM_SHAKE_256
"BLAKE224", // 2018.06.15
"BLAKE256",
"BLAKE384",
"BLAKE512",
"KR HAS-160", // Korea HAS160 CHECKSUM_KR_HAS160
"Tiger-1995", // CHECKSUM_TIGER1995
"RMD-160", // CHECKSUM_RIPEMD160
"unknown",
};
SYSTEMTIME mCRCSysTime; // checksum system time
#pragma warning (disable : 4100)
#pragma warning (disable : 4068)
TCHAR szAppName[] = APPNAME;
HINSTANCE _hInstance;
HWND _hwnd, _MainHwnd, _EditHwnd;
static HWND _hwndEdit;
//static HWND _hwndBott;
#if 1 // 2017.4.25
extern volatile HWND _hDlgTxData2UART;
extern HWND _hTxData2UART;
extern volatile HWND _hDlgHex2Binary;
extern HWND _hHex2Binary;
extern volatile HWND _hDlgDownloadProgress;
extern HWND _hProgressControl;
extern volatile HWND _hDlgDownloadProgressUART;
extern HWND _hProgressControlUART;
extern volatile HWND _hDlgSerialSettings;
#endif
#if USE_FLOAT2HEX_VALUE // 2018.07.18
extern volatile HWND _hDlgFlt2Hexa;
#endif
extern int LogFileType; // 2020.04.07
#if DNW_2ND_WINDOWS_ENABLE // 2016.10.24
static HWND hWndStatusBar;
static HWND hWndCommandBar;
//const int iStatusWidths[NUM_STATUS_BAR] = {80, 170, 250, 290, 350, -1};
const int iStatusWidths[NUM_STATUS_BAR] = {70, 160, 240, 280, 340, -1};
const DWORD WinStatus_YInit = 24;
const DWORD WinStatus_YSize = 20;
int isStatusBarEnable = BAR_NONE;
int OKstatusBarInitial = 0;
extern int userComPort, userBaudRate;
extern volatile int isConnected; // 0:Disconnect, 1:Connected, 2:Try to connect
void MenuStatusClear(HWND hwnd);
#define ARR_KEY_UP 0x01
#define ARR_KEY_DN 0x02
#define ARR_KEY_LT 0x04
#define ARR_KEY_RT 0x08
#define ARR_KEY_PGUP 0x10
#define ARR_KEY_PGDN 0x20
#define MAX_AT_COMMAND_NUM 100 // 100 // dnw_cmd_history.txt
TCHAR szTempKeyIn[MAX_PATH] = {0,}; // key-in
#if KEYIN_HISTORY_SAVE // 2017.4.25
TCHAR szKeyAll[MAX_AT_COMMAND_NUM][MAX_PATH] = {0,}; // key-in
TCHAR szTmpTxt[MAX_PATH] = {0,}; // display in Status bar
int idxCurrKey = 0;
int idxKeyTot = 0; // 2017.08.28, MAX_AT_COMMAND_NUM;
unsigned char arrowKeyTouched = 0;
int idxRepNum = 0;
int TxDataOnStatusBar(void); // 2017.05.10
void CmdDisplayOnStatusBar(void); // 2017.05.15
int CheckTxDataFileOnStatusBar(void); // 2017.08.28
#endif
int key_index = 0; // unsigned int -> int
unsigned int isPressKey = 0;
#else
const DWORD WinStatus_YInit = 0;
const DWORD WinStatus_YSize = 0;
#endif
char dnwCurrPath[MAX_PATH] = {0,};
char dnwDefaultPath[MAX_PATH] = {0,};
#if DISPLAY_PC_SYSTEM_TIME /*--- 2016.02.12 ------ */
SYSTEMTIME LocalSysTime; // NOTE PC 의 시간 정보 취득 Display에 출력한다 ---
#endif
const char WeekTXT[][3+1] = {
"Sun", // wDayOfWeek 0
"Mon", // wDayOfWeek 1
"Tue", // wDayOfWeek 2
"Wed", // wDayOfWeek 3
"Thu", // wDayOfWeek 4
"Fri", // wDayOfWeek 5
"Sat", // wDayOfWeek 6
"***", // NEVER
NULL
};
extern int FontType;
#if defined(COLOR_DISP2)
HBRUSH m_Brush = NULL; /// background color
COLORREF BGColor=RGB(255,255,255);
extern int ColorType; /// 2010.05.14 added
#endif ////////
#define UMON_IRAM_BL1_FILE_INDEX 0
#define UMON_EBOOT_FILE_INDEX 1
#if HEXA_MODE_SUPPORT /* 2012.07.03 Hexa mode display */
extern DWORD ColumnNumber;
extern TCHAR szColumnNumber[16];
int uCount = 0; // 2016.04.02 for LineFeed Count
DWORD HexaEndChar = 0x0D0A; // Example 0x81, or 0x83, ...
extern TCHAR szHexaEnd[16];
#endif
extern int TextorHexaMode; /* Text display or Hexa display */
extern int userFlowControl; // 2017.08.03, Flow COntrol
extern int userFlowCtrlVal; // 2017.08.04, Flow Control Value
extern int userHexaDispVal; // 2018.03.22, Hexa display
extern UINT str2int(TCHAR *str);
extern int sendTxDataType; // 2016.03.23
extern int txDataMsgOnOff; // 2016.03.23
extern TCHAR szSerialTxCharData[TX_DATA_LENGTH];
extern TCHAR szSerialTxHexaData[TX_DATA_LENGTH];
extern TCHAR szSerialTxFileData[TX_DATA_LENGTH]; // 2016.03.28
extern TCHAR szSerialTxFileTitl[TX_DATA_LENGTH]; // 2016.03.28
extern unsigned int WriteTXComm(void *args);
extern BOOL ThreadWriteTXComm(void *args);
extern int isTxData2UART; // Tx Data on/Off for UpdateWindowTitle()
#if USE_WIN_OUTOF_AREA_TO_ZERO // 2016.03.31 LCD size
extern DWORD myLCDwidth, myLCDheight;
extern DWORD myVirWidth, myVirHeight; // 2017.08.01 VirtualLCD size
#endif
// const DWORD WIx_START = 0;
// const DWORD WIy_START = 0;
extern DWORD WIN_XSIZE;
extern DWORD WIN_YSIZE;
#if DNW_WIN_POSITION_MOVALBE // 2016.02.29
extern BOOL isSaveSize;
extern BOOL isSavePosition;
extern DWORD POSave_XSIZE;
extern DWORD POSave_YSIZE;
#endif
extern DWORD editXBgn, editWidth;
extern DWORD editYBgn, editHeight;
extern DWORD MainXBgn, MainWidth;
extern DWORD MainYBgn, MainHeight;
extern DWORD WIN_XBgn, WIN_YBgn;
extern int autoSendKey;
extern int msgSaveOnOff;
#if DISPLAY_PC_SYSTEM_TIME /*--- 2016.02.12 ------ */
extern int localTime;
extern int isTimeInfoOnce; // Time 정보를 맨 앞에 한번 표시한다.
#endif
extern int cmdCRLF; // 2019.12.21
static BOOL is_resize = FALSE;
static RECT MainRect, rect;
DWORD W_dif = X_DIFF_CAL; /* 8 */
DWORD H_dif = Y_DIFF_CAL; /* 50 */
BOOL is_auto_download_Key = FALSE;
WORD DownloadedBin = 0x00;
int BinFileIndex = 0; /* start = 0*/
static BOOL is_ram_usbtransmit_bl1 = FALSE;
extern FILE *fFileWrite;
extern unsigned char buff_fin[DATE_LEN];
#define DNW_WIN_NAME TEXT("DNW")
extern void LOGFile_close(void);
#define EDITID 1
#define STATUSID 2
#define TOOLBAR_ID 3
#define HEXAID 4
#define CMDKEY_ID 5
// --------------------------------------------------------------------------------------------------
// ------------- SCREEN BUFFER SIZE -----------------------------------------------------------------
// --------------------------------------------------------------------------------------------------
#if 0 // dnw original
#define MAX_EDIT_BUF_SIZE (0x7FFE) // 31K
#define EDIT_BUF_SIZE (0x6000) // 24K
#define EDIT_BUF_DEC_SIZE (0x2000) /* 8KB - 맨 위 8KB 단위 (약 81 line) 로 삭제한다 -- */
#else
#if USER_SCREEN_BUF_SIZE // 2016.02.14
// 0: Large(100MB), 1:Normal, 2:Small(20MB), 3:Smallest(2MB)
#define MAX_EDIT_BUF_SIZE (0x7FFFFFE) /* 128 MB */ /* Max : 0x6FFFFFE */
#define HUGE_EDIT_BUF_SIZE (0x6400000) /* 100MB */
#define HUGE_EDIT_BUF_DEC_SIZE (0x1E00000) /* 30MB - 맨 위 30MB 단위로 삭제하여 scroll 처리한다 -- */
#define LARGE_EDIT_BUF_SIZE (0x3C00000) /* 60MB */
#define LARGE_EDIT_BUF_DEC_SIZE (0x1400000) /* 20MB - 맨 위 20MB 단위로 삭제하여 scroll 처리한다 -- */
#define MIDDLE_EDIT_BUF_SIZE (0x1400000) /* 20 MB */
#define MIDDLE_EDIT_BUF_DEC_SIZE (0x0500000) /* 5MB - 맨 위 5MB 단위로 삭제하여 scroll 처리한다 -- */
#define SMALL_EDIT_BUF_SIZE (0x0500000) /* 5 MB */
#define SMALL_EDIT_BUF_DEC_SIZE (0x0100000) /* 1MB - 맨 위 1MB 단위로 삭제하여 scroll 처리한다 -- */
#define SMALLEST_EDIT_BUF_SIZE (0x0200000) /* 2 MB */
#define SMALLEST_EDIT_BUF_DEC_SIZE (0x0080000) /* 512KB - 맨 위 512KB 단위로 삭제하여 scroll 처리한다 -- */
#else
#define MAX_EDIT_BUF_SIZE (0x7FFFFFE) /* 128MB */ /* Max : 0x7FFFFFFE */
//#define EDIT_BUF_SIZE (0x7F00000) /* 127MB */
//#define EDIT_BUF_DEC_SIZE (0x3F80000) /* 64MB - 맨 위 64MB 단위로 삭제하여 scroll 처리한다 -- */
//#define EDIT_BUF_DEC_SIZE (0x3200000) /* 50MB - 맨 위 50MB 단위로 삭제하여 scroll 처리한다 -- */
#define EDIT_BUF_SIZE (0x6400000) /* 100MB */
#define EDIT_BUF_DEC_SIZE (0x1E00000) /* 30MB - 맨 위 30MB 단위로 삭제하여 scroll 처리한다 -- */
#endif // USER_SCREEN_BUF_SIZE
#endif
#define MIN_EDIT_BUF_SIZE (0x10)
#if USER_SCREEN_BUF_SIZE // 2016.02.14
DWORD dwBufferCheckSize = HUGE_EDIT_BUF_SIZE; // Huge (100MB)
DWORD dwBufferEraseSize = HUGE_EDIT_BUF_DEC_SIZE; // Huge (30MB)
extern int userScrBufSizIndex;
#endif
// --------------------------------------------------------------------------------------------------
//1) Why program doesn't work when EDIT_BUF_SIZE=50000?
// If the data size of the edit box is over about 30000,
// EM_REPLACESEL message needs very long time.
// So,EDIT_BUF_SIZE is limited to 30000.
// If the size is bigger than 30000, the size will be decreased by 5000.
//2) WM_CLEAR to the edit box doesn't work. only, EM_REPLACESEL message works.
// ==============================================
// INITIALIZATION
// ==============================================
//////////////////////////////////////
// The WinMain function is the program entry point.
//////////////////////////////////////
#pragma argsused
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance,
LPSTR lpszCmdParam, int nCmdShow)
{
MSG Msg;
HACCEL hAccel;
SetUnhandledExceptionFilter(UnhandledExceptionHandler); // 2016.10.15
_hInstance = hInst;
//OutputDebugString("");
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#if 0
int result = 0;
GetRegistry(); // 2017.4.13
//Create the download progress dialogbox.
result = DialogBox(_hInstance, MAKEINTRESOURCE(IDD_DIALOG2), NULL , OptionsProc); //modal
if( (1==result) ) // && (1!=isConnected) )
{
/// MenuConnect(hwnd); //reconfig the serial port.
//EB_Printf(TEXT("[dnw] MenuOptions is connected! \r\n") ); // refer -> EndDialog(hDlg,1)
}
else if( 0 == result )
{
// Cancel or ESC
//EB_Printf(TEXT("[dnw] MenuOptions is error or already connected!! (%d, %d) \r\n"), result, GetLastError() );
}
SetRegistry();
return FALSE; ///
#endif
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#if 0
int result = 0;
//Create the download progress dialogbox.
result = DialogBox(_hInstance, MAKEINTRESOURCE(IDD_DIALOG3), NULL, cbHex2BinProc);
if( 1 == result )
{
// OK --
}
else if( 0 == result )
{
// Cancel or ESC
// EB_Printf(TEXT("[dnw] MenuHex2Bin is error or already connected!! (%d, %d) \r\n"), result, GetLastError() );
}
//return FALSE;
#endif
if (!Register(hInst))
return FALSE;
if (!Create(hInst, nCmdShow))
return FALSE;
#if 0 // #include <crtdbg.h> // memory leakage check
// _CrtSetBreakAlloc(64);
// _CrtMemDumpAllObjectsSince(0);
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif
// ----------------------------------------------
// HOT key
// ----------------------------------------------
hAccel = LoadAccelerators(hInst,MAKEINTRESOURCE(IDR_ACCELERATOR1));
while (GetMessage(&Msg, NULL, 0, 0))
{
//To throw the message to dialog box procedure
if( _hDlgDownloadProgress==0 || !IsDialogMessage(_hDlgDownloadProgress,&Msg)
|| _hDlgDownloadProgressUART==0 || !IsDialogMessage(_hDlgDownloadProgressUART,&Msg) )
{
/* --------------------------------------------------
TranslateMessage(&Msg);
//To intercept key-board input instead of edit control.
if(Msg.message==WM_CHAR)
SendMessage(_hwnd,WM_CHAR,Msg.wParam,Msg.lParam);
else //2000.1.26
DispatchMessage(&Msg);
//EB_Printf("."); //for debug
-------------------------------------------------- */
if (!TranslateAccelerator(_hwnd,hAccel,&Msg))
{
TranslateMessage(&Msg);
if(WM_CHAR == Msg.message)
SendMessage(_hwnd, WM_CHAR, Msg.wParam, Msg.lParam);
else //2000.1.26
DispatchMessage(&Msg);
// EB_Printf("[0x%x] [%x %x] \r\n", Msg.message, Msg.wParam, Msg.lParam ); //for debug
}
}
}
return Msg.wParam;
}
//////////////////////////////////////
// Register Window
//////////////////////////////////////
BOOL Register(HINSTANCE hInst)
{
GetRegistry(); // 2017.4.13
WNDCLASSEX WndClass = { 0 }; // main
#if DNW_2ND_WINDOWS_ENABLE // 2016.10.24
WNDCLASSEX WndChild = { 0 }; // child
#endif
WndClass.cbSize = sizeof(WNDCLASSEX);
WndClass.style = CS_HREDRAW | CS_VREDRAW;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = hInst;
WndClass.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON1)); /// IDI_APPLICATION
WndClass.hCursor = LoadCursor(hInst,IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)(COLOR_BLACK);
//WndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1); /// 2018.12.28
#ifdef __TEST__
IDC_APPSTARTING // App Start Used to show that something undetermined is going on or the application is not stable
IDC_ARROW // Arrow This standard arrow is the most commonly used cursor
IDC_CROSS // The crosshair cursor is used in various circumstances such as drawing
IDC_HAND // The Hand is standard only in Windows 2000. If you are using a previous operating system and need this cursor, you may have to create your own.
IDC_HELP // The combined arrow and question mark cursor is used when providing help on a specific item on a window object
IDC_IBEAM // The I-beam cursor is used on text-based object to show the position of the caret
IDC_ICON // This cursor is not used anymore
IDC_NO // This cursor can be used to indicate an unstable situation
IDC_SIZE // This cursor is not used anymore
IDC_SIZEALL // The four arrow cursor pointing north, south, east, and west is highly used to indicate that an object is selected or that it is ready to be moved
IDC_SIZENESW // The northeast and southwest arrow cursor can be used when resizing an object on both the length and the height
IDC_SIZENS // The north - south arrow pointing cursor can be used when shrinking or heightening an object
IDC_SIZENWSE // The northwest - southeast arrow pointing cursor can be used when resizing an object on both the length and the height
IDC_SIZEWE // The west - east arrow pointing cursor can be used when narrowing or enlarging an object
IDC_UPARROW // The vertical arrow cursor can be used to indicate the presence of the mouse or the caret
IDC_WAIT // The Hourglass cursor is usually used to indicate that a window or the application is not ready.
#endif
//WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
//WndClass.hbrBackground = (HBRUSH)(COLOR_BLACK);
//2017.4.12, WndClass.hbrBackground = (HBRUSH)CreateSolidBrush( COLOR_GRAY7 );
//WndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndClass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
WndClass.lpszClassName = szAppName;
WndClass.hIconSm = LoadIcon(hInst,MAKEINTRESOURCE(IDI_ICON2));
#if DNW_2ND_WINDOWS_ENABLE // 2016.10.24
#if DNW_2ND_COMMAND // 2017.4.22
if( BAR_STATUS==isStatusBarEnable || BAR_COMMAND==isStatusBarEnable )
#else
if( BAR_STATUS==isStatusBarEnable )
#endif
{
WndChild = WndClass;
WndChild.lpszClassName = "h2";
WndChild.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
WndChild.lpfnWndProc = WndProc;
//RegisterClassEx(&WndClass);
//RegisterClassEx(&WndChild);
if( !RegisterClassEx(&WndClass) )
{
MessageBox(NULL, TEXT("Failed to create the WinClass!1!"), TEXT("Error1"), MB_OK | MB_ICONERROR);
return 0;
}
if( !RegisterClassEx(&WndChild) )
{
MessageBox(NULL, TEXT("Failed to create the WndChild!!2!!"), TEXT("Error2"), MB_OK | MB_ICONERROR);
return 0;
}
return 1;
}
else
{
return (RegisterClassEx(&WndClass) != 0);
}
#else
return (RegisterClassEx(&WndClass) != 0);
#endif
}
//////////////////////////////////////
// Create the window and show it.
//////////////////////////////////////
BOOL Create(HINSTANCE hInst, int nCmdShow)
{
//~~ 2017.04.13 GetRegistry();
#if DNW_WIN_POSITION_MOVALBE // 2016.02.29
HWND hwnd = CreateWindow(szAppName, szAppName,
WS_OVERLAPPEDWINDOW /*&(~(WS_SIZEBOX|WS_MAXIMIZEBOX|WS_MINIMIZEBOX))*/,
WIN_XBgn, /* 0 */ /* CW_USEDEFAULT */
WIN_YBgn, /* 0 */ /* CW_USEDEFAULT */
WIN_XSIZE,
WIN_YSIZE, /*WINDOW_XSIZE, WINDOW_YSIZE, */
NULL, NULL, hInst, NULL);
#else
HWND hwnd = CreateWindow(szAppName, szAppName,
WS_OVERLAPPEDWINDOW /*&(~(WS_SIZEBOX|WS_MAXIMIZEBOX|WS_MINIMIZEBOX))*/,
0, // WIN_XBgn, /* 0 */ /* CW_USEDEFAULT */
0, // WIN_YBgn, /* 0 */ /* CW_USEDEFAULT */
WIN_XSIZE,
WIN_YSIZE, /*WINDOW_XSIZE, WINDOW_YSIZE, */
NULL, NULL, hInst, NULL);
#endif // DNW_WIN_POSITION_MOVALBE! -----------------------------------------
if ( NULL==hwnd )
{
return FALSE;
}
//_hwnd=hwnd;
GetWindowRect(hwnd,&MainRect);
_MainHwnd = hwnd;
///////////////////////////////////////////////////////////////////////////////
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd); /* 윈도우 프로시저로 WM_PAINT 메시지를 보내 작업영역을 강제로 그리도록(즉시 다시그림) */
#if USE_RX_TX_QUEUE
// intialized Circular Queue for Rx2Tx
InitCQueue(&Rx2Tx, MAX_QUEUE_SIZE );
#endif
return TRUE;
}
//==============================================
// IMPLEMENTATION
//==============================================
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
WORD BinType = 0;
#if DNW_2ND_WINDOWS_ENABLE // 2016.10.24
RECT rcClient; // 2017.04.21
#endif
#if 0
//static HINSTANCE hInst;
//HCURSOR hcur1;
static HWND hSB;
PTSTR pstr = TEXT("Owner draw Text");
BOOL fResult=FALSE;
#endif
///HWND hwndRichedit = (HWND)GetWindowLong(hwnd, 0 ); /// added.
switch(Message)
{
case WM_CREATE:
if( FALSE == isFileExist( TEXT(DNW_FOLDER_NAME1) ) )
{
if( FALSE == CreateDirectory( TEXT(DNW_FOLDER_NAME2), NULL) )
{
DWORD dwError = GetLastError();
if( ERROR_ALREADY_EXISTS == dwError ) /// The specified directory already exists ---
{
// EB_Printf(TEXT("[dnw] Folder [%s] already exists. \r\n"), TEXT(DNW_FOLDER_NAME1) );
}
else
{
EB_Printf(TEXT("[dnw] Can not create the dnw folfer!!! Err(%u) \r\n"), dwError );
}
}
else
{
//EB_Printf(TEXT("[dnw] dnwconfig!!! --- OK \r\n"));
}
}
else
{
///EB_Printf(TEXT("[dnw] found!!!! === \r\n"));
}
#if DISPLAY_PC_SYSTEM_TIME /*--- 2016.02.12 ------ */
memset(&LocalSysTime,0x00,sizeof(SYSTEMTIME));
#endif
memset( dnwCurrPath, 0x00, sizeof(dnwCurrPath) );
memset( dnwDefaultPath, 0x00, sizeof(dnwDefaultPath) );
if( !GetCurrentDirectory(MAX_PATH, dnwCurrPath) )
{
EB_Printf(TEXT("[dnw] currDir is [%s]. Err(%u) \r\n"), dnwCurrPath, GetLastError() );
}
strcpy(dnwDefaultPath,dnwCurrPath);
strcat(dnwDefaultPath,"\\");
//PlaySound(TEXT("d:\\windows\\media\\chimes.wav"),NULL,SND_FILENAME|SND_ASYNC);
_hwnd=hwnd;
// ~~~ 2016.04.13 ~~~ GetRegistry(); // added.
#if USE_WIN_OUTOF_AREA_TO_ZERO // 2016.03.31 LCD size
myLCDwidth = GetSystemMetrics(SM_CXSCREEN);
myLCDheight = GetSystemMetrics(SM_CYSCREEN);
myVirWidth = GetSystemMetrics(SM_CXVIRTUALSCREEN);
myVirHeight = GetSystemMetrics(SM_CYVIRTUALSCREEN);
if( myLCDwidth <= 0 ) myLCDwidth = WIN_LIMIT_XX;
if( myLCDheight <= 0 ) myLCDheight = WIN_LIMIT_YY;
//if( (WIN_XBgn > myLCDwidth-WIN_LIMIT_X_MARGIN) || WIN_XBgn < 0 )
if( (WIN_XBgn > myVirWidth-WIN_LIMIT_X_MARGIN) || WIN_XBgn < 0 ) // 2017.08.01, : myLCDwidth -> myVirWidth
{
WIN_XBgn = 0;
}
if( (WIN_YBgn > myLCDheight-WIN_LIMIT_Y_MARGIN) || WIN_YBgn < 0 )
{
WIN_YBgn = 0;
}
// EB_Printf(TEXT("[dnw] ++++++++++ ==> X:Y[%d, %d] \n"), LCDwidth, LCDheight );
#endif
SetTimer(hwnd,TIMER_ID_WIN_UPDATE, 1000, NULL); /* dnw title - 1sec 마다 update */
#if RICHED_COLOR // 2016.09.19 +++++++++
if( !(hDll = LoadLibrary("RichEd20.dll")) )
{
if( !(hDll = LoadLibrary("riched32.dll")) )
{
MessageBox(NULL, TEXT("RICHED_COLOR DLL can not loaded!"), TEXT("Error"), MB_OK);
}
}
// Create the edit control child window
_hwndEdit = CreateWindowEx (0, RICHEDIT_CLASS,
TEXT("edit"), /*The name of the progress class*/
//NULL, /*Caption Text*/
WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_AUTOVSCROLL | /* WS_CAPTION | WS_HSCROLL |*/
WS_BORDER | ES_LEFT | ES_MULTILINE | ES_READONLY /* | TBSTYLE_TOOLTIPS */
/* | ES_SUNKEN | ES_NOHIDESEL|*/ /*ES_AUTOVSCROLL*/ /*|ES_AUTOHSCROLL*/ , /*Styles*/
0, /*X co-ordinates*/
0, /*Y co-ordinates*/ /* CW_USEDEFAULT, CW_USEDEFAULT,*/
WIN_XSIZE, /*Width*/
WIN_YSIZE, /*Height*/ /*SCREEN_X, SCREEN_Y, */
hwnd, /*Parent HWND*/
(HMENU)EDITID, /*The Progress Bar's ID*/
((LPCREATESTRUCT)lParam)->hInstance, /*The HINSTANCE of your program*/
NULL); /*Parameters for main window*/
RichEditInit(); // RICHEDIT Initialized
#else // ~~~~~~~~~~~~~~~~~~~~~~~
// Create the edit control child window
_hwndEdit = CreateWindow (
TEXT("edit"), /*The name of the progress class*/
NULL, /*Caption Text*/
WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_AUTOVSCROLL /* | WS_CAPTION | WS_HSCROLL |*/
| WS_BORDER | ES_LEFT | ES_MULTILINE | ES_READONLY /* | TBSTYLE_TOOLTIPS */
| WS_TABSTOP /* | ES_SUNKEN | ES_NOHIDESEL|*/ /*ES_AUTOVSCROLL*/ /*|ES_AUTOHSCROLL*/ , /*Styles*/
0, /*X co-ordinates*/
0, /*Y co-ordinates*/ /* CW_USEDEFAULT, CW_USEDEFAULT,*/
WIN_XSIZE, /*Width*/
WIN_YSIZE - STATUS_BAR_HEIGHT, // WinStatus_YInit, /*Height*/ /*SCREEN_X, SCREEN_Y, */
hwnd, /*Parent HWND*/
(HMENU)EDITID, /*The Progress Bar's ID*/
((LPCREATESTRUCT)lParam)->hInstance, /*The HINSTANCE of your program*/
NULL); /*Parameters for main window*/
// _hwndBott = CreateDialog (((LPCREATESTRUCT)lParam)->hInstance, (LPCTSTR)IDD_DIAGLOG_BOTTOM, hwnd, (DLGPROC)(WNDPROC) ChildBottomProc);
#endif // ----------------------------------------
SetWindowLong( _hwndEdit,
GWL_EXSTYLE|GWL_USERDATA|DWL_USER|GWL_STYLE /*|GWL_WNDPROC|GWL_ID|DWL_DLGPROC|DWL_MSGRESULT*/,
TRUE); /// added.
//hcur1 = LoadCursor( NULL, IDC_CROSS );
//hcur1 = LoadCursorFromFile(TEXT("icon1.ico"));