-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathGGchess.cpp
More file actions
1101 lines (906 loc) · 30.9 KB
/
Copy pathGGchess.cpp
File metadata and controls
1101 lines (906 loc) · 30.9 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
// GGchess.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "GGchess.h"
#include "chess.h"
#include "data.h"
#include "pregen.h"
#include <shellapi.h>
#include <sys/stat.h>
#include <io.h>
#include <fcntl.h>
#include <share.h>
#define MAX_LOADSTRING 100
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
#ifdef USE_WINLICENSE
VM_START_WITHLEVEL(12)
int Status;
Status = WLRegGetStatus(NULL);
if(Status == 1){ //只有1是注册成功的
//MessageBox(NULL, "(1)!!", "注册成功了!!", MB_OK | MB_ICONERROR);
}
else{ //这儿还没注册成功
//先读入注册文件,看能不能注册成功,
char *filepart;
if(SearchPath(NULL,"GGchess.exe",NULL,MSG_SIZ,installDir,&filepart)){
*filepart = NULLCHAR;
}
else{
GetCurrentDirectory(MSG_SIZ,installDir);
}
if(strlen(installDir) < 5){
exit(0);
}
//打开注册文件
char pRegName[1024];
sprintf_s(pRegName,1024,"%s%s", installDir,"mreg.bin");
int pFile;
char rbuf[4096];
errno_t err = _sopen_s(&pFile,pRegName,_O_RDONLY, _SH_DENYNO,
_S_IREAD | _S_IWRITE);
if(err == 0){
int byteRead = _read(pFile,rbuf,2048);
_close(pFile);
if(byteRead > 2000){
exit(0);
}
//*********************************************************************
//解密一下
const char key[18] = {
//00 01 02,03 04 05 06 07 08 09 10 11 12 13 14 15 16 17
25,15,75,74,66,55,15,37,71,64,34,25,87,81,43,19,85,47,
};
int k = 0;
for(int i = 0; i < 2000; i++){
char old = rbuf[i];
rbuf[i] ^= key[k++];
if(rbuf[i] == 0 || rbuf[i] < 32 || rbuf[i] > 125){
rbuf[i] = old;
}
if(k>16){
k = 0;
}
}
}
else{
}
//***********************************************************************
rbuf[2000] = 0;
rbuf[2001] = 0;
char keybuf[4096];
for(int k = 0; k < 2048; k++){
keybuf[k] = rbuf[k];
if(rbuf[k] == 0){
break;
}
}
if(!WLRegNormalKeyCheck(keybuf)){
DialogBox(NULL,(LPSTR)MAKEINTRESOURCE(IDD_FIRST_DIAG),NULL,(DLGPROC)firstDlgProc);
}
else{
DeleteFile(pRegName);
WLRegNormalKeyInstallToFile(keybuf);
MessageBox(NULL, "感谢您的注册, 请重新启动本程序!!", "注册成功了!!", MB_OK | MB_ICONERROR);
WLRestartApplication();
}
}
VM_END
#endif
#ifdef USE_WINLICENSE
REGISTERED_START
#endif
UNREFERENCED_PARAMETER(hPrevInstance);
//UNREFERENCED_PARAMETER(lpCmdLine);
// TODO: Place code here.
MSG msg;
//HACCEL hAccelTable;
HACCEL hAccelMain, hAccelNoAlt;
appData.debugFP = stderr;
OBS[0] = new dispboard_t[1];
memset(OBS[0],0,sizeof(dispboard_t));
OBS[0]->first.table
= OBS[0]->second.table
= OBS[0]->ics.table = 0;
LoadLibrary("RICHED32.DLL");
#ifdef USE_WINLICENSE
VM_START
#endif
initPreGen(); //初始化走步
#ifdef USE_WINLICENSE
VM_END
#endif
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_GGCHESS, szWindowClass, MAX_LOADSTRING);
appData.iconWhite = LoadIcon(hInstance,"icon_white");
appData.iconBlack = LoadIcon(hInstance,"icon_black");
MyRegisterClass(hInstance);
// Perform application initialization: //应用程序的初始化
if (!InitInstance (hInstance, nCmdShow,lpCmdLine)) {
return FALSE;
}
//sqlite3 *db;
//sqlite3_open("",&db);
//加速键处理
hAccelMain = LoadAccelerators(hInstance, (LPCTSTR)IDC_GGCHESS);
hAccelNoAlt = LoadAccelerators(hInstance,"NO_ALT");
// 主消息循环:
while (GetMessage(&msg, NULL, 0, 0)) {
if (!(!appData.Afrozen && TranslateAccelerator(OBS[0]->hwndThis, hAccelMain, &msg)) //加速键
&& !(!DLG.hwndConsole && TranslateAccelerator(OBS[0]->hwndThis,hAccelNoAlt,&msg))) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
#ifdef USE_WINLICENSE
REGISTERED_END
#endif
return (int) msg.wParam;
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage are only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM
MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = appData.iconWhite;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
wcex.lpszMenuName = (LPCTSTR)IDC_GGCHESS;
wcex.lpszClassName = szWindowClass;
wcex.hIconSm = appData.iconWhite;
if(!RegisterClassEx(&wcex)) return false; //注册主窗口 DIS.iconWhite
////****************************************************************************
//wcex.style = CS_HREDRAW | CS_VREDRAW;
//wcex.lpfnWndProc = (WNDPROC)ConsoleWndProc;
//wcex.cbClsExtra = 0;
//wcex.hbrBackground = (HBRUSH)DLGWINDOWEXTRA;
//wcex.hInstance = hInstance;
////wcex.hIcon = LoadIcon(hInstance,"icon_white");
//wcex.hIcon = DIS.iconWhite;
//wcex.hCursor = LoadCursor(NULL,IDC_ARROW);
//wcex.hbrBackground = (HBRUSH)(COLOR_MENU+1);
//wcex.lpszMenuName = NULL;
//wcex.lpszClassName = szConsoleName;
//if(!RegisterClassEx(&wcex)){
// return false; //注册连线窗口
//}
//****************************************************************************
return true;
}
//
// FUNCTION: InitInstance(HINSTANCE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL
InitInstance(HINSTANCE hInstance, int nCmdShow,LPSTR lpCmdLine){
HWND hWnd;
int ibs;
WINDOWPLACEMENT wp;
char *filepart;
hInst = hInstance; // 将实例句柄存储在全局变量中
//当前目录确认 //!CycloneGui GGchess
if(SearchPath(NULL,"GGchess.exe",NULL,MSG_SIZ,installDir,&filepart)){
*filepart = NULLCHAR;
}
else{
GetCurrentDirectory(MSG_SIZ,installDir);
}
InitAppData(lpCmdLine); /* Get run-time parameters */
//#ifdef DEBUG_MODE
// appData.debugMode = TRUE;
//#else
// appData.debugMode = FALSE;
//#endif
//appData.debugMode = FALSE;
#ifdef DEBUG_MODE
//if(appData.debugMode){ //调试模式
char buf[MAX_PATH];
sprintf_s(buf,MAX_PATH,"%s%s",installDir,"GGchess.debug");
errno_t err = fopen_s(&appData.debugFP,buf,"w");
if(err != 0){
//int ddd = 0;
MessageBox(NULL,"不能打开调试文件","出错啦",MB_OK);
return FALSE;
}
else{
//setvbuf(DIS.debugFP,NULL,NULL,0);
//fwrite(
}
//}
#endif
InitBackEnd1();
hWnd = CreateWindow(szWindowClass, //建立主窗口
szTitle,
//WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX,
WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX,
CW_USEDEFAULT,
0,
CW_USEDEFAULT, //680,
0, //570,
NULL,
NULL,
hInstance,
NULL);
if (!hWnd){
return FALSE;
}
dispboard_t *pDis = OBS[0];
pDis->hwndThis = hWnd; //保存主窗口句柄
hStatusBar = CreateStatus(hWnd);
hwndToolBar = CreateAToolBar(hWnd);
//DIS.ucci = UCCI_UCCI;
pDis->iconCurrent = appData.iconWhite;
InitDrawingColors(pDis);
pDis->screenHeight = GetSystemMetrics(SM_CYSCREEN); //高
pDis->screenWidth = GetSystemMetrics(SM_CXSCREEN); //宽
for(ibs = (int)NUM_SIZES - 1; ibs >= 0; ibs--){
//用每一个board尺寸与屏幕尺寸比较,缺省时使用匹配屏幕的最大使用尺寸*/
InitDrawingSizes(pDis,(BoardSize)ibs, 0);
//如果是-1,就表示上次还没有正确的尺寸
if (pDis->bsize== (BoardSize)-1
&& pDis->winHeight <= pDis->screenHeight ) {
pDis->bsize = (BoardSize)ibs;
break;
}
}
if(appData.winWidth != -1){ //得到上回保存的placement
RECT crect;
GetClientRect(hWnd, &crect);
WINDOWPLACEMENT wp;
wp.length = sizeof(WINDOWPLACEMENT);
wp.flags = WPF_RESTORETOMAXIMIZED;
wp.showCmd = SW_SHOW;
wp.rcNormalPosition.left = crect.left;
wp.rcNormalPosition.top = crect.top;
wp.rcNormalPosition.right = crect.left + appData.winWidth;
wp.rcNormalPosition.bottom = crect.left + OBS[0]->winHeight;
SetWindowPlacement(hWnd,&wp);
}
InitDrawingSizes(pDis,pDis->bsize,0); //初始化显示区的大小
InitMenuChecks(); //只有退出保存和通讯端口两项
appData.buttonCount = GetSystemMetrics(SM_CMOUSEBUTTONS); //鼠标的按钮数量
/* Make a console window if needed */
//if (appData.icsActive) {
// ConsoleCreate();
//}
/* Make the window visible; update its client area; and return "success" */
EnsureOnScreen(pDis, &pDis->boardX, &pDis->boardY);
wp.length = sizeof(WINDOWPLACEMENT);
wp.flags = 0;
wp.showCmd = nCmdShow;
wp.ptMaxPosition.x = wp.ptMaxPosition.y = 0;
wp.rcNormalPosition.left = pDis->boardX;
wp.rcNormalPosition.right = pDis->boardX + pDis->winWidth;
wp.rcNormalPosition.top = pDis->boardY;
wp.rcNormalPosition.bottom = pDis->boardY + pDis->winHeight;
SetWindowPlacement(hWnd, &wp);
SetWindowPos(hWnd, appData.AalwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
//if (DIS.hwndConsole) {
// //#if AOT_CONSOLE
// // SetWindowPos(hwndConsole, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
// // 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
// //#endif
// ShowWindow(DIS.hwndConsole, nCmdShow);
//}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
DLG_Rich_Log_Event(); //显示日志窗口
initIcs(); //初始化连线帐号
SetIcsTitleName("尚未联机,按<连接>可连接网络下棋");
#ifdef USE_BerKeley_DB
BD_initEnv(MST); //初始化环境, BK 用于开局库的制作
#endif
#ifdef USE_SQL_LITE_DATABASE
//initSqlLiteDB ();
#endif
InitBackEnd2();
ThawUI();
DLG_BOOK_Event(); //开始不显示棋库列表
ResetGameEvent(OBS[0]);
#ifdef USE_WINLICENSE //定义了加密
VM_START
if(wlIsRegistered == WLRegGetStatus(NULL)){
char pName[256];
char pCompanyName[256];
char pCustomData[512];
if(WLRegGetLicenseInfo(pName,pCompanyName,pCustomData)){
char buf[256];
sprintf_s(buf,sizeof(buf),"已注册给:%s, 感谢您使用本软件!",pName);
SetWindowText(hWnd,buf);
LogOut("\n本软件已注册给:\n用户: ");
LogOut(pName);
LogOut("\n公司名:");
LogOut(pCompanyName);
LogOut("\n其它信息:");
LogOut(pCustomData);
}
}
else{
LogOut("对不起,您可能使用的是盗版,将在5秒后退出!");
Sleep(1000);
exit(0);
}
VM_END
#endif
//LoadChessProgramState(&DIS.first,hwndMain); //调用第一个引擎
//LoadChessProgramState(&DIS.second,hwndMain); //调用第二个引擎
#ifdef USE_MY_PROTECT //使用我的保护方法
VM_START
buf[1024];
sprintf_s(buf,1024,
"%s%s",installDir,"GGchess.exe");
HANDLE mfile = CreateFile(buf,
GENERIC_READ, // open for reading
FILE_SHARE_READ, // share for reading
NULL, // default security
OPEN_EXISTING, // existing file only
FILE_ATTRIBUTE_NORMAL, // normal file
NULL); // no attr. template
if (mfile == INVALID_HANDLE_VALUE)
{
//printf("Could not open file (error %d)\n", GetLastError());
exit(0); //直接退出了
}
int fsize = GetFileSize(mfile,NULL);
if(fsize > MAX_file_size || fsize < MIN_file_size){
exit(0);
}
//int test = 0;
VM_END
#endif
return TRUE;
}
//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK //主窗口处理程序
WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){
int wmId, wmEvent;
//PAINTSTRUCT ps;
//HDC hdc;
switch (message) {
case WM_CREATE:
//random_init();
break;
case WM_PAINT: //重绘窗口
PaintProc(OBS[0]);
break;
case WM_ERASEBKGND:
if (IsIconic(hWnd)) {
/* Cheat; change the message */
return (DefWindowProc(hWnd, WM_ICONERASEBKGND, wParam, lParam));
}
else {
return (DefWindowProc(hWnd, message, wParam, lParam));
}
break;
case WM_CHAR: //键盘输入信息
if (appData.icsActive) {
//if (wParam == '\t') {
// if (GetKeyState(VK_SHIFT) < 0) {
// /* shifted */
// HWND h = GetDlgItem(hwndConsole, OPT_ConsoleInput);
// if (IsIconic(hwndConsole)) ShowWindow(hwndConsole, SW_RESTORE);
// SetFocus(h);
// } else {
// /* unshifted */
// HWND h = GetDlgItem(hwndConsole, OPT_ConsoleText);
// if (IsIconic(hwndConsole)) ShowWindow(hwndConsole, SW_RESTORE);
// SetFocus(h);
// }
//} else {
// HWND h = GetDlgItem(hwndConsole, OPT_ConsoleInput);
// if (IsIconic(hwndConsole)) ShowWindow(hwndConsole, SW_RESTORE);
// SetFocus(h);
// SendMessage(h, message, wParam, lParam);
//}
}
else if (isalpha((char)wParam) || isdigit((char)wParam)) {
//PopUpMoveDialog((char)wParam);
}
break;
case WM_COMMAND: //菜单或工具条
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
if(lParam == NULL){ // ;菜单总是NULL// 分析菜单选择:
switch (wmId){
//托盘菜单
case ID_NOTEMENU_RESTORE:
ShowWindow(hWnd,SW_RESTORE);
break;
case ID_NOTEMENU_EXIT:
SendMessage(hWnd,WM_CLOSE,0,0);
break;
//*****************************************
case IDM_NewGame: // Reset Game,也就是新开一局哇
ResetGameEvent(OBS[0]);
AnalysisPopDown();
//
break;
case IDM_LoadGame:
LoadGameDialog(hWnd, "Load Game from File");
break;
case IDM_Backward:
BackwardEvent(OBS[0]);
SetFocus(hWnd);
break;
case IDM_Forward:
ForwardEvent(OBS[0]);
SetFocus(hWnd);
break;
case IDM_ToStart:
ToStartEvent(OBS[0]);
SetFocus(hWnd);
break;
case IDM_TwoMachines:
TwoMachinesEvent();
/*
* refresh the tags dialog only if it's visible
*/
//if (DIS.gameMode == TwoMachinesPlay && IsWindowVisible(editTagsDialog)) {
// char *tags;
// tags = PGNTags(&gameInfo);
// TagsPopUp(tags, CmailMsg());
// free(tags);
//}
break;
case IDM_MachineWhite: //机器走红方
//MachineWhiteEvent();
MachinePlayEvent(&OBS[0]->first);
/*
* refresh the tags dialog only if it's visible
*/
//if (gameMode == MachinePlaysWhite && IsWindowVisible(editTagsDialog)) {
// char *tags;
// tags = PGNTags(&gameInfo);
// TagsPopUp(tags, CmailMsg());
// free(tags);
//}
break;
case IDM_MachineBlack:
MachinePlayEvent(&OBS[0]->second);
//MachineBlackEvent();
/*
* refresh the tags dialog only if it's visible
*/
//if (gameMode == MachinePlaysBlack && IsWindowVisible(editTagsDialog)) {
// char *tags;
// tags = PGNTags(&gameInfo);
// TagsPopUp(tags, CmailMsg());
// free(tags);
//}
break;
case IDM_FlipView:
FlipViewEvent(OBS[0]);
break;
case IDM_ToEnd:
ToEndEvent(OBS[0]);
SetFocus(hWnd);
break;
case IDM_GeneralOptions: //通用选项菜单
GeneralOptionsPopup(hWnd);
break;
case IDM_EditGame:
EditGameEvent(OBS[0]);
break;
case IDM_TimeControl:
YqSetOptionsPopup(0);
break;
case IDM_EditPosition:
EditPositionEvent();
break;
case IDM_SaveSettings:
//SaveSettings(DIS.settingsFileName);
SaveSettingDataToSqlite();
break;
case IDM_SaveSettingsOnExit:
appData.AsaveSettingsOnExit = !appData.AsaveSettingsOnExit;
(void) CheckMenuItem(GetMenu(OBS[0]->hwndThis), IDM_SaveSettingsOnExit,
MF_BYCOMMAND|(appData.AsaveSettingsOnExit ? MF_CHECKED : MF_UNCHECKED));
break;
//-----------------------------------------
case IDM_ABOUT:
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
//DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
//***********************************窗口菜单
//case IDM_ShowStepListDlg:
// ShowStepListEvent();
// break;
//case IDM_ShowTimeDisplay:
// TimeDisplayListEvent();
// break;
case IDM_BOOK_DLG:
DLG_BOOK_Event();
break;
case IDM_RichLog:
DLG_Rich_Log_Event();
break;
case IDM_DlgDefaultPosition:
DlgDefaultPosition();
break;
//*******************************************
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
else if( (HWND)lParam == hwndToolBar){ //工具条消息
switch(wmId){
case IDT_NEW: //新建一局游戏
//TestIsSame();
ResetGameEvent(OBS[0]);
//LoadChessProgramState(&DIS.first);
break;
case IDT_IMPORT:
if(SendMessage(hwndToolBar,TB_ISBUTTONCHECKED,
IDT_IMPORT,0)){//电脑走棋按钮按下了
#ifdef USE_MYSQL_DATABASE
Import_QJ_To_Mysql_Event();
#endif
}
break;
case IDT_CANJU: //摆局按钮
//if(SendMessage(hwndToolBar,TB_ISBUTTONCHECKED,IDT_CANJU,0)){
//if(DispTotalNum != 0){
// if(MessageBox(hwndMain,
// "确认将清除当前的内容,去消将返回!",
// "注意:当前已有棋步!",
// MB_OKCANCEL) != IDOK){ //如果按的不是确认
// return 0;
// }
//}
//initBaiJu(&DispBoard);
// initBaiJu(&DispBoard);
//}else{
// //得判断棋局是不是正常哇
// if(!isCanFinishBaiJu(&DispBoard)){
//
// }
//}
//ManBaiCanJu();
/*extern char sql_host[MSG_SIZ/2];
extern char sql_user[MSG_SIZ/2];
extern char sql_pass[MSG_SIZ/2];
extern int sql_port;
extern char sql_db[MSG_SIZ/2];*/
//MysqlCreateConnect(&mysql,sql_host,
// sql_user,sql_pass,sql_db,sql_port);
//Sql2000_To_Mysql_Event();
//Web_To_Mysql_Event();
break;
case IDT_CORRECT_MAN:
//GameQJ gg;
#ifdef USE_MYSQL_DATABASE
MysqlGetOneUncheckGGqj(&DIS.GGQJ,&DIS.mysql);
#endif
break;
case IDT_CHANGE_BR: //改变上下棋盘
//Change_BlueRed();
break;
case IDT_CHANGE_RIGHT_LEFT: //改变左右显示棋盘
//Change_Right_Left();
break;
case IDT_Backward:
BackwardEvent(OBS[0]);
SetFocus(hWnd);
break;
case IDT_Forward:
ForwardEvent(OBS[0]);
SetFocus(hWnd);
break;
case IDT_ToStart:
ToStartEvent(OBS[0]);
SetFocus(hWnd);
break;
case IDT_FLIP:
FlipViewEvent(OBS[0]);
break;
case IDT_ToEnd:
ToEndEvent(OBS[0]);
SetFocus(hWnd);
break;
case IDT_LEARN_QK: //学习棋局
//MysqlGetOneCheckedAndLearn(GameQJ *pgg, MYSQL *my);
//MysqlGetOneCheckedAndLearn(&DIS.GGQJ, &DIS.mysql);
if(SendMessage(hwndToolBar,TB_ISBUTTONCHECKED,IDT_LEARN_QK,0)){
#ifdef USE_MYSQL_DATABASE
LearnChecked_QJ_To_Mysql_Event();
#endif
}
//TestFaceEvent();
break;
case IDT_COM_RED: { //按下了第 1 个引擎
//MachineWhiteEvent(); //TBSTATE_CHECKED
////if(SendMessage(hwndToolBar,TB_CHECKBUTTON,but,0)){ //如果是引擎按钮按下了
//ChessProgramState *cps = &OBS[0]->first;
////int k = SendMessage(hwndToolBar,TB_GETSTATE,IDT_COM_RED,0);
//if(SendMessage(hwndToolBar,TB_GETSTATE,IDT_COM_RED,0) & TBSTATE_CHECKED){
// MachinePlayEvent(cps);
//}
//else{
// if(cps->maybeThinking == TRUE){
// SendToProgram(DIS,"stop\n", cps);
// Sleep(100);
// }
// cps->maybeThinking = FALSE;
// cps->playWhat = NEUTRAL;
//}
}
break;
case IDT_COM_BLUE: { //按下了第 2 个引擎
//MachineBlackEvent();
//MachinePlayEvent(&DIS.second);
//ChessProgramState *cps = &OBS[0]->second;
//if(SendMessage(hwndToolBar,TB_GETSTATE,IDT_COM_BLUE,0) & TBSTATE_CHECKED){
// MachinePlayEvent(cps);
//}
//else{
// if(cps->maybeThinking == TRUE){
// SendToProgram("stop\n", cps);
// Sleep(100);
// }
// cps->maybeThinking = FALSE;
// cps->playWhat = NEUTRAL;
//}
}
break;
case IDT_HUIQI: //悔棋
{ dispboard_t *pDis = OBS[0];
BackwardEvent(pDis);
if(pDis->pos->gply > 0){
pDis->pos->gply--;
};
//
FillBookbyPos(pDis,MST->book);
SetFocus(hWnd);
}
break;
case IDT_INTERNET: //连线到INTERNET
InternetPlayEvent();
break;
case IDT_YQ_SET:
YqSetOptionsPopup(0);
break;
default:
break;
}
}
break;
case WM_USER_Input:
InputEvent(hWnd, message, wParam, lParam);
break;
case WM_SIZE:
//在工具栏和状态栏编程中,
//要注意的就是工具栏和状态栏并不会随父窗口的大小
//变化自己调整位置和大小,所以要在父窗口的 WM_SIZE
//消息中来移动和调整它们,这可以简单的把 WM_SIZE 消息传给它们就行了。
//不必自己再去计算。
SendMessage(hStatusBar, message,wParam,lParam);
SendMessage(hwndToolBar,message,wParam,lParam);
if(LOWORD(wParam) == SIZE_MINIMIZED){//最小化窗口
Note.cbSize = sizeof(NOTIFYICONDATA);
Note.hWnd = hWnd;
Note.uID = IDI_TRAY;
Note.uFlags = NIF_ICON + NIF_MESSAGE + NIF_TIP;
Note.uCallbackMessage = WM_SHELLNOTIFY;
Note.hIcon = OBS[0]->iconCurrent;
StringCbCopy(Note.szTip,128,"佳佳象棋");
ShowWindow(hWnd,SW_HIDE);
Shell_NotifyIcon(NIM_ADD,&Note);
}
//else if(LOWORD(wParam) == SIZE_MAXIMIZED){//最大化窗口SIZE_MAXIMIZED
// return 0;
//}
break;
//case SC_MAXIMIZE:
// break;
case WM_ENTERSIZEMOVE:
if (hWnd == OBS[0]->hwndThis) {
OBS[0]->doingSizing = TRUE;
OBS[0]->lastSizing = 0;
}
break;
case WM_NOTIFY: {
//if(wParam == hwndTabID){ //这是TAB控件发来的消息哇
// NMHDR *lnm = (NMHDR *)lParam;
// if(lnm->code == TCN_SELCHANGE){//改变了选项卡哇
// ShowWindow(TAB.dlgTab[TAB.tabChosen],SW_HIDE);
// TAB.tabChosen = (int)SendMessage(TAB.hwndTab,TCM_GETCURSEL,0,0);
// ShowWindow(TAB.dlgTab[TAB.tabChosen],SW_SHOW);
// FitTabDialogToTabControl(); //重新调整大小
// }
//}
//if(wParam == IDR_TOOLBAR){
// //int test = 0;
// static int i = 0;
// i++;
// if(i%2){
// DispStatS("这是工具条信息哇");
// }
// else{
// DispStatS("这是工具条信息哇1");
// }
//}
NMHDR *lnm = (NMHDR*)lParam;
if(lnm->code == TTN_NEEDTEXT){
//static int i = 0;
//i++;
//if(i%2){
// DispStatS("这是工具条信息哇");
//}
//else{
// DispStatS("这是工具条信息哇1");
//}
TOOLTIPTEXT* ptip = (TOOLTIPTEXT*)lParam;
//ptip->lpszText = ptip->hdr.idFrom;
LoadString(hInst,(UINT)ptip->hdr.idFrom,ptip->szText,sizeof(ptip->szText));
DispStatS(ptip->szText);
}
}
break;
case WM_SIZING:
if (hWnd == OBS[0]->hwndThis) {
OBS[0]->lastSizing = (int)wParam;
}
break;
case WM_EXITSIZEMOVE:
if (hWnd == OBS[0]->hwndThis) {
RECT client;
OBS[0]->doingSizing = FALSE;
InvalidateRect(hWnd, &OBS[0]->boardRect, FALSE);
GetClientRect(hWnd, &client);
ResizeBoard(OBS[0],client.right, client.bottom, OBS[0]->lastSizing);
OBS[0]->lastSizing = 0;
//
SendEveryObsBoard(WM_USER_MainBoard_Sized,0,0);
}
break;
case WM_SHELLNOTIFY:
if(LOWORD(wParam) == IDI_TRAY){
if(lParam == WM_RBUTTONDOWN){
POINT pt;
GetCursorPos(&pt);
SetForegroundWindow(hWnd);
HMENU hm = LoadMenu(hInst,MAKEINTRESOURCE(IDR_MENU_NOTE));
hm = GetSubMenu(hm,0);
TrackPopupMenu(hm,TPM_RIGHTALIGN|TPM_LEFTBUTTON |
TPM_RIGHTBUTTON,pt.x,pt.y,NULL,hWnd,NULL);
}
else if(lParam == WM_LBUTTONDOWN){
SendMessage(hWnd,WM_COMMAND,ID_NOTEMENU_RESTORE,0);
SetForegroundWindow(hWnd);
}
}
break;
case WM_LBUTTONDOWN:
case WM_MBUTTONDOWN:
case WM_RBUTTONDOWN:
case WM_LBUTTONUP:
case WM_MBUTTONUP:
case WM_RBUTTONUP:
case WM_MOUSEMOVE: