-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandLotteryDlg.cpp
2775 lines (2351 loc) · 85.4 KB
/
RandLotteryDlg.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
// RandLotteryDlg.cpp : implementation file
//
#include "ShadeButtonST.h" // Added by ClassView
#include "stdafx.h"
#include "RandLottery.h"
#include "RandLotteryDlg.h"
#include "Excel.h"
#include "Setting.h"
#include "GetHardSoftInfo.h"
#include "MD5Checksum.h"
#include "HyperLink.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "afxmt.h" //为了文件中能够正确使用同步类,在文件开头添加
CEvent g_hEvent0;
CEvent g_hEvent1;
CEvent g_hEventW[MAX_ID_SHOW_COUNT];
HANDLE g_hProcess[MAX_ID_SHOW_COUNT];
CCriticalSection g_csSection;// //临界区
//CCriticalSection g_csSectionWriteTXT;// //临界区
static CRITICAL_SECTION g_csSectionWriteTXT;
void logfile_lock_initialize(void)
{
InitializeCriticalSection(&g_csSectionWriteTXT);
}
static inline void logfile_lock(void)
{
EnterCriticalSection(&g_csSectionWriteTXT);
}
static inline void logfile_unlock(void)
{
LeaveCriticalSection(&g_csSectionWriteTXT);
}
structInputData g_tInputData;
structInputData g_tInputData1;
#define SLEEP_TIME_START 30
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
//class CRandLotteryDlg;
/*指向类的非静态成员函数的指针*/
//typedef void (CRandLotteryDlg::*pClassFun[10]) (int);
/*指向一般函数的指针*/
UINT (*pThreadRun[MAX_ID_SHOW_COUNT]) (LPVOID pParam);
#define FUNCTION_POINT
class CAboutDlg : public CDialog
{
public:
CHyperLink m_lnk1;
CShadeButtonST m_btnOK;
CAboutDlg();
// Dialog Daa
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
CHyperLink m_Taobao;
CEdit m_editReg4;
CEdit m_editReg3;
CEdit m_editReg2;
CEdit m_editReg1;
CString m_strNum1;
CString m_strNum2;
CString m_strNum3;
CString m_strNum4;
CString m_strMachineSerial;
CString m_strRegeditSerial;
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
virtual BOOL OnInitDialog();
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
afx_msg void OnChangeEditReg1();
afx_msg void OnChangeEditReg2();
afx_msg void OnChangeEditReg3();
afx_msg void OnChangeEditReg4();
virtual void OnOK();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
m_strNum1 = _T("");
m_strNum2 = _T("");
m_strNum3 = _T("");
m_strNum4 = _T("");
m_strMachineSerial = _T("");
m_strRegeditSerial = _T("");
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
DDX_Control(pDX, IDC_STATIC_TAOBAO, m_Taobao);
DDX_Control(pDX, IDC_EDIT_REG4, m_editReg4);
DDX_Control(pDX, IDC_EDIT_REG3, m_editReg3);
DDX_Control(pDX, IDC_EDIT_REG2, m_editReg2);
DDX_Control(pDX, IDC_EDIT_REG1, m_editReg1);
DDX_Text(pDX, IDC_EDIT_REG1, m_strNum1);
DDV_MaxChars(pDX, m_strNum1, 5);
DDX_Text(pDX, IDC_EDIT_REG2, m_strNum2);
DDV_MaxChars(pDX, m_strNum2, 5);
DDX_Text(pDX, IDC_EDIT_REG3, m_strNum3);
DDV_MaxChars(pDX, m_strNum3, 5);
DDX_Text(pDX, IDC_EDIT_REG4, m_strNum4);
DDV_MaxChars(pDX, m_strNum4, 5);
DDX_Text(pDX, IDC_EDIT_MACHINE_SERIAL, m_strMachineSerial);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
ON_WM_CTLCOLOR()
ON_EN_CHANGE(IDC_EDIT_REG1, OnChangeEditReg1)
ON_EN_CHANGE(IDC_EDIT_REG2, OnChangeEditReg2)
ON_EN_CHANGE(IDC_EDIT_REG3, OnChangeEditReg3)
ON_EN_CHANGE(IDC_EDIT_REG4, OnChangeEditReg4)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRandLotteryDlg dialog
CRandLotteryDlg::CRandLotteryDlg(CWnd* pParent /*=NULL*/)
: CDialog(CRandLotteryDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CRandLotteryDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
iTransparent = 255;
m_pFloatWnd = NULL;
m_pListSet = NULL;
m_pItemSet = NULL;
m_bListDlgCreated = FALSE;
m_bItemDlgCreated = FALSE;
m_bShowResultCreated = FALSE;
m_bNextRank = FALSE;
m_nCount = 0;
//memset(m_nNum,0,MAX_ID_SHOW_COUNT); //初始化数组
//ZeroMemory(&m_pListSet->m_nNum[0], sizeof(&m_pListSet->m_nNum[0]));
//获取日期和时间
CTime CurrentTime=CTime::GetCurrentTime();
CString strTime,strTime1;
m_strCurrentDate.Format("%d-%d-%d" ,CurrentTime.GetYear(), CurrentTime.GetMonth()
,CurrentTime.GetDay());
m_strCurrentTime.Format("%d-%d-%d %d:%d" ,CurrentTime.GetYear(), CurrentTime.GetMonth()
,CurrentTime.GetDay(),CurrentTime.GetHour(),CurrentTime.GetMinute());
//获取当前执行文件路径,获取配置文件中的字段
CString strPath=CRandLotteryDlg::GetModuleFilePath();
//背景图片路径
GetPrivateProfileString("IMG_FILE_PATH", "IMG_File_Path", strPath+"\\BGPic\\金元宝.bmp",
m_imgFilePath.GetBuffer(FILE_PATH_BUFF_SIZE), FILE_PATH_BUFF_SIZE, strPath+"\\BGPic\\BGPic.ini");
m_imgFilePath.ReleaseBuffer();
logfile_lock_initialize();
}
void CRandLotteryDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRandLotteryDlg)
DDX_Control(pDX, IDC_STATIC_TILTE2, m_stcTitle2);
DDX_Control(pDX, IDC_STATIC_SHOW_EMAIL, m_stcShowEmail);
DDX_Control(pDX, IDC_STATIC_SHOW_AWORD, m_stcShowAword);
DDX_Control(pDX, IDC_STATIC_ITEM_SHOW, m_stcItemShow);
DDX_Control(pDX, IDC_STATIC_NOTIC, m_stcNotic);
DDX_Control(pDX, IDC_STATIC_ITEM_AMOUNT, m_stcItemAmount);
DDX_Control(pDX, IDC_STATIC_ITEM_AWORD, m_stcItemAword);
DDX_Control(pDX, IDC_STATIC_ITEM_RANK, m_stcItemRank);
DDX_Control(pDX, IDC_STATIC_TILTE, m_stcTitle);
DDX_Control(pDX, IDC_STATIC_ID, m_stcID);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CRandLotteryDlg, CDialog)
//{{AFX_MSG_MAP(CRandLotteryDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_START, OnButtonStart)
ON_BN_CLICKED(IDC_BUTTON_STOP, OnButtonStop)
ON_WM_CTLCOLOR()
ON_BN_CLICKED(IDC_BUTTON_SETTING, OnButtonSetting)
ON_WM_SIZE()
ON_COMMAND(ID_MENU_LOTTERY_NAME, OnMenuLotteryName)
ON_WM_RBUTTONDOWN()
ON_COMMAND(ID_MENU_ABOUT, OnMenuAbout)
ON_COMMAND(ID_MENU_TITLESETTING, OnMenuTitleSetting)
ON_COMMAND(IDC_MENU_BG1, OnMenuBg1)
ON_COMMAND(IDC_MENU_BG2, OnMenuBg2)
ON_COMMAND(IDC_MENU_BG3, OnMenuBg3)
ON_COMMAND(IDC_MENU_BG4, OnMenuBg4)
ON_COMMAND(ID_MENU_MUSIC_SETTING, OnMenuMusicSetting)
ON_COMMAND(ID_MENU_ITEMSETTING, OnMenuItemsetting)
ON_COMMAND(ID_MENU_LOTTERY_LIST, OnMenuLotteryList)
ON_COMMAND(ID_MENU_NOLOTTERY_LIST, OnMenuNolotteryList)
ON_COMMAND(ID_MENU_RESULT, OnMenuResult)
ON_COMMAND(ID_MENU_RESET, OnMenuReset)
ON_UPDATE_COMMAND_UI(ID_MENU_START, OnUpdateMenuStart)
ON_UPDATE_COMMAND_UI(ID_MENU_STOP, OnUpdateMenuStop)
ON_COMMAND(ID_MENU_BG_MORE, OnMenuBgMore)
ON_COMMAND(ID_MENU_CONTINUE, OnMenuContinue)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_DISPLAY,OnDisplay)
ON_MESSAGE(WM_DELETE_LISTITEM,OnDeleteListitem)
ON_MESSAGE(WM_ENABLE_BT,OnEnableBT)
ON_MESSAGE(WM_SHOW_ITEM_TEXT,OnShowItemText)
ON_MESSAGE(WM_WRITE_RESULT_LIST,OnWriteResultToResultList)
ON_MESSAGE(WM_WRITE_TEXT_FILE,OnWriteResultToTextFile)
ON_MESSAGE(MM_MCINOTIFY,OnMciNotify)
END_MESSAGE_MAP()
BEGIN_EASYSIZE_MAP(CRandLotteryDlg)
//---------------------- -Left,--------Top,-------Right,----Bottem
// EASYSIZE(IDC_STATIC_ID,ES_BORDER,ES_BORDER,ES_BORDER,ES_BORDER,ES_HCENTER| ES_HCENTER)//表示缩放后,值为IDC_STATIC_ID的控件,在对话框内垂直居中,水平居中
// EASYSIZE(IDC_BUTTON_START,IDC_STATIC_ID,ES_KEEPSIZE,ES_KEEPSIZE,IDC_STATIC_ID,0)
// EASYSIZE(IDC_BUTTON_STOP,IDC_BUTTON_START,ES_KEEPSIZE,ES_KEEPSIZE,IDC_BUTTON_START,0)
// EASYSIZE(IDC_BUTTON_SETTING,ES_KEEPSIZE,ES_KEEPSIZE,ES_BORDER,ES_BORDER,0)
//
// EASYSIZE(IDC_STATIC_ITEM_SHOW,ES_BORDER,ES_KEEPSIZE,ES_BORDER,IDC_STATIC_ID,0) //显示Rank区
//
// EASYSIZE(IDC_STATIC_TILTE,ES_BORDER,ES_BORDER,ES_BORDER,ES_KEEPSIZE,0) //主标题
// EASYSIZE(IDC_STATIC_TILTE2,ES_BORDER,IDC_STATIC_TILTE,ES_BORDER,ES_KEEPSIZE,0) //副标题
//
// EASYSIZE(IDC_STATIC_ITEM_RANK,ES_BORDER,ES_KEEPSIZE,ES_KEEPSIZE,IDC_STATIC_ID,0)
// EASYSIZE(IDC_STATIC_ITEM_AMOUNT,ES_BORDER,ES_KEEPSIZE,ES_KEEPSIZE,IDC_STATIC_ITEM_RANK,0)
// EASYSIZE(IDC_STATIC_ITEM_AWORD,ES_BORDER,ES_KEEPSIZE,ES_KEEPSIZE,IDC_STATIC_ITEM_RANK,0)
//
// EASYSIZE(IDC_STATIC_NOTIC,IDC_BUTTON_START,ES_KEEPSIZE,ES_KEEPSIZE,IDC_STATIC_ID,0)
//
// EASYSIZE(IDC_STATIC_SHOW_AWORD,ES_BORDER,ES_KEEPSIZE,ES_BORDER,ES_BORDER,0)
// EASYSIZE(IDC_STATIC_SHOW_EMAIL,ES_BORDER,ES_BORDER,ES_BORDER,ES_KEEPSIZE,0)
END_EASYSIZE_MAP
/////////////////////////////////////////////////////////////////////////////
// CRandLotteryDlg message handlers
BOOL CRandLotteryDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
CreateDirectoryEx("Result"); //根目录
INIT_EASYSIZE;
// TODO: Add extra initialization here
//ButtonST
for (int K=0;K<MAX_ID_SHOW_COUNT;K++)
{
g_hEventW[K].ResetEvent();
g_hProcess[K] = ::CreateEvent(NULL, TRUE, FALSE, NULL);
}
//隐藏控件
SetDialogHide(FALSE);
RemoveDialogStyleEx(TRUE);
//一开始窗口最大化
ShowWindow(SW_SHOWMAXIMIZED);
//布置所有控件的位置和大小
LayoutDialogLocationAndSize(); //
//Disable “停止” and “开始”按钮
GetDlgItem(IDC_BUTTON_STOP)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON_START)->EnableWindow(FALSE);
//设置“停止” 和 “开始”按钮字体
SetTextFont(GetDlgItem(IDC_BUTTON_START));
SetTextFont(GetDlgItem(IDC_BUTTON_STOP));
//美化按钮控件
m_btnStart.SubclassDlgItem(IDC_BUTTON_START,this);
m_btnStart.SetIcon(IDI_ICON_START);
m_btnStart.SetShade(CShadeButtonST::SHS_SOFTBUMP);
m_btnStop.SubclassDlgItem(IDC_BUTTON_STOP,this);
m_btnStop.SetIcon(IDI_ICON_STOP);
m_btnStop.SetShade(CShadeButtonST::SHS_SOFTBUMP);
//title and ID的字体文本设置
GetDlgItem(IDC_STATIC_TILTE)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_STATIC_TILTE2)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_STATIC_ID)->ShowWindow(SW_HIDE);
for (int i=1;i<MAX_ID_SHOW_COUNT;i++)
{
GetDlgItem(IDC_STATIC_ID+i)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_STATIC_ID+i)->SetWindowText(m_TitleSettingDlg.m_strID);
SetTextFont(GetDlgItem(IDC_STATIC_ID+i),m_TitleSettingDlg.m_nIDFontSize,m_TitleSettingDlg.m_strIDFontName);
}
SetTextFont(&m_stcID,m_TitleSettingDlg.m_nIDFontSize,m_TitleSettingDlg.m_strIDFontName);
SetTextFont(&m_stcTitle,m_TitleSettingDlg.m_nTitleFontSize,m_TitleSettingDlg.m_strTitleFontName);
SetTextFont(&m_stcTitle2,m_TitleSettingDlg.m_nTitle2FontSize,m_TitleSettingDlg.m_strTitle2FontName);
m_stcTitle.SetWindowText(m_TitleSettingDlg.m_strTitleHead);
m_stcTitle2.SetWindowText(m_TitleSettingDlg.m_strTitleHead2);
m_stcID.SetWindowText(m_TitleSettingDlg.m_strID);
//title and ID 文本框位置及大小设定
CRect rect;
GetDlgItem(IDC_STATIC_TILTE)->GetWindowRect(&rect); //保存Title窗口的位置
SetRectTitle(rect);
GetDlgItem(IDC_STATIC_TILTE2)->GetWindowRect(&rect); //保存Title2窗口的位置
SetRectTitle2(rect);
//导入背景图片
m_bmDents.DeleteObject();
m_brDents.DeleteObject();
//m_bmDents.LoadBitmap(IDB_BITMAP_BG3);
CRect WndRect;
this->GetWindowRect(&WndRect); //获取主窗口的尺寸
HBITMAP hBitmap = (HBITMAP)LoadImage(NULL,m_imgFilePath,IMAGE_BITMAP,WndRect.Width(),WndRect.Height(),LR_LOADFROMFILE);
m_bmDents.Attach(hBitmap);
m_brDents.CreatePatternBrush(&m_bmDents);
//浮动窗口的创建和初始化
m_pFloatWnd = new CFloatWnd;
m_pFloatWnd->Create(IDD_DIALOG_FLOAT,this);
m_pFloatWnd->ShowWindow(SW_SHOW);
m_pFloatWnd->OnUpdateTransparent(iTransparent);
Invalidate(); //刷新刷新桌面
//抽奖项目窗口创建
m_pItemSet = new CItemSetting;
if(m_pItemSet->Create(IDD_DIALOG_ITEM_SET,this))
{
m_pItemSet->ShowWindow(SW_HIDE);//隐藏窗口
m_bItemDlgCreated =TRUE;
g_tInputData1.pListCtr= &(m_pItemSet->m_listItem);
g_tInputData1.strPath = m_pItemSet->m_strFilePath; //
g_tInputData1.nMode = 1;
CWinThread *pThread_InputItem=AfxBeginThread(CRandLotteryDlg::Thread_InputItemExcelData,
//&m_pListSet->m_listInfo,
&g_tInputData1,
THREAD_PRIORITY_NORMAL,
0,
CREATE_SUSPENDED);
if (pThread_InputItem == NULL)
{
TRACE("创建InputItem线程出错!\n");
//return;
}
pThread_InputItem->ResumeThread();
Sleep(100);
}
//抽奖名单窗口创建
m_pListSet = new CListSetting;
if(m_pListSet->Create(IDD_DIALOG_LIST_SET,this))
{
//inputData->pListCtr = NULL;
m_pListSet->ShowWindow(SW_HIDE);//隐藏窗口
m_bListDlgCreated =TRUE;
g_tInputData.pListCtr= &(m_pListSet->m_listInfo);
g_tInputData.strPath = m_pListSet->m_strFilepath;
g_tInputData.nMode = 0;
CWinThread *pThread_InputExcelData=AfxBeginThread(CRandLotteryDlg::Thread_InputExcelData,
//&m_pListSet->m_listInfo,
&g_tInputData,
THREAD_PRIORITY_NORMAL,
0,
CREATE_SUSPENDED);
if (pThread_InputExcelData == NULL)
{
TRACE("创建InputExcelData线程出错!\n");
//return;
}
pThread_InputExcelData->ResumeThread();
Sleep(100);
}
//抽奖结果窗口创建
m_pShowResult = new CShowResult;
if(m_pShowResult->Create(IDD_DIALOG_RESULT,this))
{
//inputData->pListCtr = NULL;
m_pShowResult->ShowWindow(SW_HIDE);//隐藏窗口
m_bShowResultCreated =TRUE;
}
//下面两项都放到OnShowItemText函数里面
// //提示notic
// SetTextFont(&m_stcNotic,20,"宋体");
// CString strNotic;
// strNotic.Format("正在抽取^%s^,共%d名,目前还剩%d名...",m_pListSet->m_strItemRank,_ttoi(m_pListSet->m_strItemAmount),m_pListSet->m_nItemAmount);
// m_stcNotic.SetWindowText(strNotic);
//
//
// //提示show
// SetTextFont(&m_stcItemShow,m_TitleSettingDlg.m_nRankShowFontSize,m_TitleSettingDlg.m_strRankShowFontName);
// m_stcItemShow.SetWindowText("^"+m_pListSet->m_strItemRank+"^");
//打开背景音乐
//m_MusicPlayer.m_strBKGroundMusicPath = strPath+"\\Music\\BKGroundMusic.mp3";
if(m_MusicPlayer.m_bEnableBKGroundMusic) m_MusicPlayer.BKGroundMusicPlay();
//把中奖名单文件先清空
CString strPath;
strPath.Format("\\中奖名单%s.txt",m_strCurrentDate);
CString strFilePath = CRandLotteryDlg::GetModuleFilePath()+strPath;
CFileFind fFind;
CStdioFile file;// //
if(fFind.FindFile(strFilePath))
{
file.Open(strFilePath,CFile::modeCreate); //如果没有此文件就创建一个文件
file.Close();
}
#ifdef USE_MACHINE_SERIAL_REGEDIT
if (!theApp.IsRegedited()) //如果还没有注册
{
//初始化滚动条Email
CRect rectEmail;
GetDlgItem(IDC_STATIC_SHOW_EMAIL)->GetWindowRect(&rectEmail);
m_stcShowEmail.SetTextXPos(rectEmail.right);
m_stcShowEmail.SetTextColor(RGB(0,255,128));
m_stcShowEmail.SetRollDirection(0);//0向左,1向右,2向上,3向下
//m_stcShowAword.SetClock();
m_stcShowEmail.SetBkTransparent(1);
m_stcShowEmail.BeginRoll();
//m_stcShowAword.SetBkColor((RGB(0,255,0)));
m_stcShowEmail.SetTextFont(30,"arial");//arial
m_stcShowEmail.SetText(WELCOME_AND_EMAI_QQ);
}
else
#endif
{
m_stcShowEmail.SetBkTransparent(1);//滚动条背景刷新
}
//初始化滚动条Result
CRect rectResult;
GetDlgItem(IDC_STATIC_SHOW_AWORD)->GetWindowRect(&rectResult);
m_stcShowAword.SetTextXPos(rectResult.right);
m_stcShowAword.SetTextColor(RGB(0,255,128));
m_stcShowAword.SetRollDirection(0);//0向左,1向右,2向上,3向下
//m_stcShowAword.SetClock();
m_stcShowAword.SetBkTransparent(1);
m_stcShowAword.BeginRoll();
//m_stcShowAword.SetBkColor((RGB(0,255,0)));
m_stcShowAword.SetTextFont(40,"arial");//arial
//显示欢迎滚动条
(CStatic*)GetDlgItem(IDC_STATIC_SHOW_EMAIL)->ShowWindow(SW_SHOW);
//显示主标题,副标题,ID
GetDlgItem(IDC_STATIC_TILTE)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_STATIC_TILTE2)->ShowWindow(m_TitleSettingDlg.m_nTitle2Status);
RelayoutIDLocation(m_TitleSettingDlg.m_nIDCount); //重新布置ID区
GetDlgItem(IDC_STATIC_ID)->ShowWindow(SW_SHOW);
//创建一个保存中奖结果线程
CWinThread *pThread_WriteResult=AfxBeginThread(CRandLotteryDlg::Thread_WriteLuckyManMsgToFile,
//&m_pListSet->m_listInfo,
this,
THREAD_PRIORITY_NORMAL,
0,
CREATE_SUSPENDED);
if (pThread_WriteResult == NULL)
{
TRACE("创建WriteResult线程出错!\n");
//return;
}
pThread_WriteResult->ResumeThread();
//GetDlgItem(IDC_STATIC_TILTE2)->ShowWindow(SW_SHOW);
return TRUE; // return TRUE unless you set the focus to a control
}
void CRandLotteryDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CRandLotteryDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();//把这个注释掉,不调用基类的OnPaint()
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CRandLotteryDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CRandLotteryDlg::OnButtonStart()
{
// TODO: Add your control notification handler code here
#ifdef USE_MACHINE_SERIAL_REGEDIT
static UINT nTryOutTimes = 1; //没有注册软件可以试用次数
if (!theApp.m_bIsRegedited)
{
if (nTryOutTimes)
{
CString strTyout;
strTyout.Format("非注册软件,可以试用%d次!",nTryOutTimes);
nTryOutTimes --;
AfxMessageBox(strTyout);
}
else
{
AfxMessageBox("非注册软件,请注册后重试!");
return;
}
}
#endif
if (m_pFloatWnd->isLotteryFinished()) //抽奖结束
{
GetDlgItem(IDC_BUTTON_START)->EnableWindow(FALSE);
RollShowAllResult();
return;
}
//先设置抽奖是否已经开始
if (!m_pFloatWnd->isLotteryBegan())
{
m_pFloatWnd->SetLotteryBegan(TRUE);
}
//先计算一下目前参加抽奖人数
m_pListSet->m_nTotalAmount=m_pListSet->m_listInfo.GetItemCount();
if ((m_pListSet->m_nTotalAmount) == 0)
{
AfxMessageBox("抽奖人员全部抽完!");
return ;
}
//判断一次显示的抽奖数是否大于奖项设定的个数
//UINT nIDCount;
if ((UINT)(m_pListSet->m_nItemAmount)<(m_TitleSettingDlg.m_nIDCount))
{
//bRlayoutID = TRUE;
m_pListSet->m_nIDCount = m_pListSet->m_nItemAmount;
RelayoutIDLocation(m_pListSet->m_nIDCount); //重新布置ID区
}
else
{
m_pListSet->m_nIDCount = m_TitleSettingDlg.m_nIDCount;
if (m_bNextRank)
{
RelayoutIDLocation(m_pListSet->m_nIDCount); //重新布置ID区
m_bNextRank = FALSE;
}
}
//抽奖人数按每次显示抽奖数分组
NumOfIDOneceLottery(m_pListSet->m_nTotalAmount, m_pListSet->m_nIDCount);
//启动线程
m_pListSet->m_bRun=TRUE;
static BOOL m_bRunThread = TRUE;
if(m_bRunThread)
{
BeginThread(m_pListSet->m_nIDCount); //启动几个线程
}
CString strNotic;
strNotic.Format("正在抽取^%s^,共%d名,目前还剩%d名...",m_pListSet->m_strItemRank,_ttoi(m_pListSet->m_strItemAmount),m_pListSet->m_nItemAmount);
m_stcNotic.SetWindowText(strNotic);
//m_bRunThread = FALSE;
//GetMenu()->GetSubMenu(1)->EnableMenuItem(ID_MENU_LOTTERY_NAME, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); //disable 菜单中名单设置
if (m_MusicPlayer.m_bEnableStartMusic)
{
m_MusicPlayer.StopPlay();
m_MusicPlayer.StartMusicPlay();
}
m_stcItemShow.SetWindowText("^"+m_pListSet->m_strItemRank+"^"); //显示目前抽奖级别
GetDlgItem(IDC_BUTTON_START)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON_STOP)->EnableWindow(TRUE);
GetDlgItem(IDC_BUTTON_SETTING)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON_STOP)->SetFocus();
}
void CRandLotteryDlg::OnButtonStop()
{
// TODO: Add your control notification handler code here
CString strNotic;
m_pListSet->m_bRun = FALSE;
//m_pListSet->m_nItemAmount--; //记录子奖项
m_pListSet->m_nItemAmount-=m_TitleSettingDlg.m_nIDCount; //记录子奖项
if (m_MusicPlayer.m_bEnableStopMusic)
{
m_MusicPlayer.StopPlay();
m_MusicPlayer.StopMusicPlay();
}
else
{
m_MusicPlayer.StopPlay();
}
//GetMenu()->GetSubMenu(1)->EnableMenuItem(ID_MENU_LOTTERY_NAME, MF_BYCOMMAND | MF_ENABLED);//enable 菜单中名单设置
if (m_pListSet->m_nItemAmount<=0)
{
m_nCount--; //记录抽奖级别数
m_bNextRank = TRUE;
if(m_nCount < 0)
{
m_pFloatWnd->SetLotteryFinished(TRUE);
if (m_MusicPlayer.m_bEnableResultMusic)
{
m_MusicPlayer.StopPlay();
m_MusicPlayer.ResultMusicPlay();
(CStatic*)GetDlgItem(IDC_STATIC_SHOW_AWORD)->ShowWindow(SW_SHOW);
}
else
{
m_MusicPlayer.StopPlay();
}
GetDlgItem(IDC_BUTTON_START)->EnableWindow(FALSE);
GetDlgItem(IDC_BUTTON_STOP)->EnableWindow(FALSE);
//m_stcNotic.SetWindowText("所有奖项全部产生,本次抽奖结束!");
m_stcNotic.SetWindowText("");
return;
}
m_pListSet->m_strItemRank = m_pItemSet->m_listItem.GetItemText(m_nCount,0);
m_pListSet->m_strItemAmount = m_pItemSet->m_listItem.GetItemText(m_nCount,1);
m_pListSet->m_strItemAword = m_pItemSet->m_listItem.GetItemText(m_nCount,2);
m_pListSet->m_nItemAmount = _ttoi(m_pListSet->m_strItemAmount);
m_stcItemRank.SetWindowText("抽奖项目:"+m_pListSet->m_strItemRank);
m_stcItemAmount.SetWindowText("抽奖数目:"+m_pListSet->m_strItemAmount+"名");
m_stcItemAword.SetWindowText("奖品:"+m_pListSet->m_strItemAword);
strNotic.Format("马上抽取^%s^,共%d名,目前还剩%d名...",m_pListSet->m_strItemRank,_ttoi(m_pListSet->m_strItemAmount),m_pListSet->m_nItemAmount);
}
else
{
strNotic.Format("正在抽取^%s^,共%d名,目前还剩%d名...",m_pListSet->m_strItemRank,_ttoi(m_pListSet->m_strItemAmount),m_pListSet->m_nItemAmount);
}
m_stcNotic.SetWindowText(strNotic);
//GetDlgItem(IDC_BUTTON_START)->EnableWindow(TRUE);
GetDlgItem(IDC_BUTTON_STOP)->EnableWindow(FALSE);
//GetDlgItem(IDC_BUTTON_SETTING)->EnableWindow(TRUE);
return;
}
HBRUSH CRandLotteryDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor==CTLCOLOR_DLG||nCtlColor==CTLCOLOR_BTN||nCtlColor==CTLCOLOR_STATIC)
{
pDC->SetBkMode(TRANSPARENT);
switch(pWnd->GetDlgCtrlID())
{
case IDC_STATIC_TILTE:
pDC->SetTextColor(m_TitleSettingDlg.m_clrTitle); //设置主标题字体颜色
break;
case IDC_STATIC_TILTE2:
pDC->SetTextColor(m_TitleSettingDlg.m_clrTitle2); //设置副标题字体颜色
break;
case IDC_STATIC_ID:
case IDC_STATIC_ID1:
case IDC_STATIC_ID2:
case IDC_STATIC_ID3:
case IDC_STATIC_ID4:
case IDC_STATIC_ID5:
case IDC_STATIC_ID6:
case IDC_STATIC_ID7:
case IDC_STATIC_ID8:
case IDC_STATIC_ID9:
pDC->SetTextColor(m_TitleSettingDlg.m_clrID); //设置ID字体颜色
break;
case IDC_STATIC_ITEM_RANK:
case IDC_STATIC_ITEM_AMOUNT:
case IDC_STATIC_ITEM_AWORD:
pDC->SetTextColor(m_TitleSettingDlg.m_clrItemShow); //设置字体颜色
break;
case IDC_STATIC_NOTIC:
pDC->SetTextColor(RGB(0,2,255)); //设置字体颜色
break;
case IDC_STATIC_ITEM_SHOW:
pDC->SetTextColor(m_TitleSettingDlg.m_clrRankShow); //设置字体颜色
break;
default:
break;
}
return m_brDents;
//pDC->SetBkMode(TRANSPARENT);
//return (HBRUSH)::GetStockObject(HOLLOW_BRUSH);
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
void CRandLotteryDlg::OnButtonSetting()
{
// TODO: Add your control notification handler code here
if (m_bListDlgCreated)
{
m_pListSet->m_nTotalAmount=m_pListSet->m_listInfo.GetItemCount();
CString str;
str.Format("%d",m_pListSet->m_nTotalAmount);
m_pListSet->m_stcAmount.SetWindowText(str);
m_pListSet->ShowWindow(SW_SHOW);///显示
}
}
LRESULT CRandLotteryDlg::OnDisplay(WPARAM wParam,LPARAM lParam)
{
int nParam = (int)lParam;
int iParam = (int)wParam;
int iShow = m_pListSet->m_iRadio+1;
CString str = (m_pListSet->m_listInfo).GetItemText(iParam,iShow);
if (iShow==2) //身份证
{
CString strShow;
strShow=str.Left(6)+"***"+str.Right(4);
str = strShow;
}
if (iShow==3) //身份证
{
CString strShow;
strShow=str.Left(3)+"****"+str.Right(4);
str = strShow;
}
::SetDlgItemText(AfxGetMainWnd()->m_hWnd,IDC_STATIC_ID+nParam,str);//显示中奖名字
return 0;
}
LRESULT CRandLotteryDlg::OnWriteResultToResultList(WPARAM wParam,LPARAM lParam)
{
//中奖级别写入到中奖结果List第一列中
int iParam = (int)lParam;
CString strRank("");
GetWindowRank(strRank);
m_pShowResult->WriteRankToResultListFirstColumn(strRank);
CString str;
int i = (int)wParam;
int nCowCount = m_pShowResult->m_listShowResult.GetHeaderCtrl()->GetItemCount(); //Head 的数量
for (int n=0;n<nCowCount;n++)
{
str = (m_pListSet->m_listInfo).GetItemText(i,n);
m_pShowResult->m_listShowResult.SetItemText(0,n+1,str); //
}
#if 1
CString strName = (m_pListSet->m_listInfo).GetItemText(i,1);
CString strID = (m_pListSet->m_listInfo).GetItemText(i,2);
CString strTel = (m_pListSet->m_listInfo).GetItemText(i,3);
//g_csSectionWriteTXT.Lock();
WriteResultToTextFile(strRank,strName,strID,strTel);
//g_csSectionWriteTXT.Unlock();
#endif
//抽奖结束后自动保存抽奖结果
if (m_pFloatWnd->isLotteryFinished() && m_pShowResult->m_bAutoSavExcel)
{
m_pShowResult->GetDlgItem(IDC_BUTTON_SAVE)->EnableWindow(FALSE);
m_pShowResult->ExportToExcel(&(m_pShowResult->m_listShowResult));
m_pShowResult->GetDlgItem(IDC_BUTTON_SAVE)->EnableWindow(TRUE);
}
//eventIptEXLData.SetEvent(); //设置信号量
::SendMessage((HWND)(AfxGetMainWnd()->m_hWnd),WM_WRITE_TEXT_FILE,i,iParam); //写结果到Text文件,掉电保护
return 0;
}
LRESULT CRandLotteryDlg::OnWriteResultToTextFile(WPARAM wParam,LPARAM lParam)
{
CString strRank,strName;
int iParam = (int) lParam;
// #if 0
// strRank = (m_pShowResult->m_listShowResult).GetItemText(0,0);
// strName = (m_pShowResult->m_listShowResult).GetItemText(0,2);
// g_csSection_write_txt.Lock();
// WriteResultToTextFile(strRank,strName);
// g_csSection_write_txt.Unlock();
// #endif
if (m_pFloatWnd->isLotteryFinished()) //抽奖结束
{
//把Txt文件里面的内容顺序调换
CString strNameList("");
#if 0
ReversDisplayTxtFile(strNameList);
#endif
//滚动显示中奖结果
#if 1
strRank = _T("");
strName = _T("");
strNameList = _T("");
for (int i=0;i<(m_pShowResult->m_listShowResult).GetItemCount();i++)
{
strRank = (m_pShowResult->m_listShowResult).GetItemText(i,0);
int iShow = m_pListSet->m_iRadio+2;
strName = (m_pShowResult->m_listShowResult).GetItemText(i,iShow);
CString strShow;
if (iShow==3) //身份证
{
strShow=strName.Left(6)+"***"+strName.Right(4);
}
else if (iShow==4) //手机号
{
strShow=strName.Left(3)+"****"+strName.Right(4);
}
else
{
strShow=strName;
}
strNameList += strRank+":"+strShow+" ";
}
#endif
RollShowLotteryResult(strNameList);
}
g_hEventW[iParam].SetEvent(); //设置信号量
//::SetEvent(g_hProcess[iParam]);
return 0;
}
LRESULT CRandLotteryDlg::OnShowItemText(WPARAM wParam,LPARAM lParam)
{
BOOL bFlag = (BOOL)wParam;
m_nCount = m_pItemSet->m_listItem.GetItemCount()-1;
m_pListSet->m_strItemRank = m_pItemSet->m_listItem.GetItemText(m_nCount,0);
m_pListSet->m_strItemAmount = m_pItemSet->m_listItem.GetItemText(m_nCount,1);
m_pListSet->m_strItemAword = m_pItemSet->m_listItem.GetItemText(m_nCount,2);
m_pListSet->m_nItemAmount = _ttoi(m_pListSet->m_strItemAmount);
m_stcItemRank.SetWindowText("抽奖项目:"+m_pListSet->m_strItemRank);
m_stcItemAmount.SetWindowText("抽奖数目:"+m_pListSet->m_strItemAmount+"名");
m_stcItemAword.SetWindowText("奖品:"+m_pListSet->m_strItemAword);
//抽奖项目区字体设置
SetTextFont(&m_stcItemAmount,m_TitleSettingDlg.m_nItemShowFontSize,m_TitleSettingDlg.m_strItemShowFontName); //抽奖数量m_strItemShowFontName
SetTextFont(&m_stcItemRank,m_TitleSettingDlg.m_nItemShowFontSize,m_TitleSettingDlg.m_strItemShowFontName); //抽奖级别
SetTextFont(&m_stcItemAword,m_TitleSettingDlg.m_nItemShowFontSize,m_TitleSettingDlg.m_strItemShowFontName); //抽奖奖品
//提示notic
SetTextFont(&m_stcNotic,20,"宋体");
CString strNotic;
strNotic.Format("正在抽取^%s^,共%d名,目前还剩%d名...",m_pListSet->m_strItemRank,_ttoi(m_pListSet->m_strItemAmount),m_pListSet->m_nItemAmount);
m_stcNotic.SetWindowText(strNotic);
//提示show
SetTextFont(&m_stcItemShow,m_TitleSettingDlg.m_nRankShowFontSize,m_TitleSettingDlg.m_strRankShowFontName);
m_stcItemShow.SetWindowText("^"+m_pListSet->m_strItemRank+"^");
if (bFlag)
{
GetDlgItem(IDC_STATIC_NOTIC)->ShowWindow(bFlag);
m_TitleSettingDlg.m_bEnableShowItem?bFlag=TRUE:bFlag=FALSE;
GetDlgItem(IDC_STATIC_ITEM_RANK)->ShowWindow(bFlag);
GetDlgItem(IDC_STATIC_ITEM_AMOUNT)->ShowWindow(bFlag);
GetDlgItem(IDC_STATIC_ITEM_AWORD)->ShowWindow(bFlag);
m_TitleSettingDlg.m_bEnableShowRank?bFlag=TRUE:bFlag=FALSE;
GetDlgItem(IDC_STATIC_ITEM_SHOW)->ShowWindow(bFlag);
}
else
{
GetDlgItem(IDC_STATIC_NOTIC)->ShowWindow(bFlag);
GetDlgItem(IDC_STATIC_ITEM_RANK)->ShowWindow(bFlag);
GetDlgItem(IDC_STATIC_ITEM_AMOUNT)->ShowWindow(bFlag);
GetDlgItem(IDC_STATIC_ITEM_AWORD)->ShowWindow(bFlag);