-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainFrm.cpp
263 lines (200 loc) · 7.19 KB
/
MainFrm.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
// MainFrm.cpp : CMainFrame 类的实现
//
#include "stdafx.h"
#include "sweepMineMFC.h"
#include "MainFrm.h"
#include "sweepMineMFCView.h"
#include "sweepMineMFCDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
ON_WM_CREATE()
ON_COMMAND(ID_GRADE_PRIMARY, &CMainFrame::OnGradePrimary)
ON_COMMAND(ID_GRADE_DEDIUM, &CMainFrame::OnGradeDedium)
ON_COMMAND(ID_GRADE_SENIOR, &CMainFrame::OnGradeSenior)
ON_COMMAND(ID_SET_BY_YOURSELF, &CMainFrame::OnSetByYourself)
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // 状态行指示器
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
// CMainFrame 构造/析构
CMainFrame::CMainFrame()
{
// TODO: 在此添加成员初始化代码
CBitmap bitmap;
BITMAP bitMapInfo;
bitmap.LoadBitmap(IDB_BITMAP_PRIMACY_SQUARE);
bitmap.GetBitmap(&bitMapInfo);
m_mineBlockSize.w = (UINT8)bitMapInfo.bmWidth;
m_mineBlockSize.h = (UINT8)bitMapInfo.bmHeight;
m_minMineMapWidth = 400;
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
// | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
// !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
// {
// TRACE0("未能创建工具栏\n");
// return -1; // 未能创建
// }
//
// if (!m_wndStatusBar.Create(this) ||
// !m_wndStatusBar.SetIndicators(indicators,
// sizeof(indicators)/sizeof(UINT)))
// {
// TRACE0("未能创建状态栏\n");
// return -1; // 未能创建
// }
// TODO: 如果不需要工具栏可停靠,则删除这三行
// m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
// EnableDocking(CBRS_ALIGN_ANY);
// DockControlBar(&m_wndToolBar);
SetWindowLong(m_hWnd, GWL_STYLE, GetWindowLong(m_hWnd, GWL_STYLE) & ~WS_MAXIMIZEBOX);
SetMenu(NULL);
CMenu m_sweepMineMenu;
m_sweepMineMenu.LoadMenu(IDR_MENU_SWEEPMINE);
SetMenu(&m_sweepMineMenu);
m_sweepMineMenu.Detach();
m_bAutoMenuEnable = FALSE;
SetSubMenuGray(SUBMENUGRAY_PRIMACY);
RECT rect;
GetClientRect(&rect);
int x = m_mineBlockSize.w * (GRADE_PRIMACY_MAP_SIZE + 2) + 15;
int y = m_mineBlockSize.h * (GRADE_PRIMACY_MAP_SIZE + 4) + 15;
int cx = GetSystemMetrics(SM_CXSCREEN);
int cy = GetSystemMetrics(SM_CYSCREEN);
m_location.x = (UINT16)((cx - (rect.right - rect.left)) / 2);
m_location.y = (UINT16)((cy - (rect.bottom - rect.top)) / 3);
SetWindowPos(&wndTop, m_location.x, m_location.y, x, y, SWP_NOACTIVATE);
SetTimer(1, 1000, NULL);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: 在此处通过修改
// CREATESTRUCT cs 来修改窗口类或样式
cs.cx = 30 * (GRADE_PRIMACY_MAP_SIZE + 2) + 15;
cs.cy = 30 * (GRADE_PRIMACY_MAP_SIZE + 4) + 15;
cs.style &= ~FWS_ADDTOTITLE;
cs.style &= ~WS_THICKFRAME;
cs.lpszName = _T("扫雷");
return TRUE;
}
// CMainFrame 诊断
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
// CMainFrame 消息处理程序
void CMainFrame::SetSubMenuGray(UINT8 type) {
if (SUBMENUGRAY_ALL == type) {
GetMenu()->GetSubMenu(0)->EnableMenuItem(0, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
GetMenu()->GetSubMenu(0)->EnableMenuItem(1, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
GetMenu()->GetSubMenu(0)->EnableMenuItem(2, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
}
else if (SUBMENUGRAY_PRIMACY == type) {
GetMenu()->GetSubMenu(0)->EnableMenuItem(0, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
GetMenu()->GetSubMenu(0)->EnableMenuItem(1, MF_BYPOSITION | MF_ENABLED);
GetMenu()->GetSubMenu(0)->EnableMenuItem(2, MF_BYPOSITION | MF_ENABLED);
}
else if (SUBMENUGRAY_MEDIUM == type) {
GetMenu()->GetSubMenu(0)->EnableMenuItem(0, MF_BYPOSITION | MF_ENABLED);
GetMenu()->GetSubMenu(0)->EnableMenuItem(1, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
GetMenu()->GetSubMenu(0)->EnableMenuItem(2, MF_BYPOSITION | MF_ENABLED);
}
else if (SUBMENUGRAY_SENIOR == type){
GetMenu()->GetSubMenu(0)->EnableMenuItem(0, MF_BYPOSITION | MF_ENABLED);
GetMenu()->GetSubMenu(0)->EnableMenuItem(1, MF_BYPOSITION | MF_ENABLED);
GetMenu()->GetSubMenu(0)->EnableMenuItem(2, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
}
else if (SUBMENUGRAY_NULL == type) {
GetMenu()->GetSubMenu(0)->EnableMenuItem(0, MF_BYPOSITION | MF_ENABLED);
GetMenu()->GetSubMenu(0)->EnableMenuItem(1, MF_BYPOSITION | MF_ENABLED);
GetMenu()->GetSubMenu(0)->EnableMenuItem(2, MF_BYPOSITION | MF_ENABLED);
}
}
void CMainFrame::OnGradePrimary()
{
// TODO: 在此添加命令处理程序代码
int x = m_mineBlockSize.w * (GRADE_PRIMACY_MAP_SIZE + 2) + 15;
x = x > m_minMineMapWidth ? x : m_minMineMapWidth;
int y = m_mineBlockSize.h * (GRADE_PRIMACY_MAP_SIZE + 4) + 15;
SetSubMenuGray(SUBMENUGRAY_PRIMACY);
SetWindowPos(&wndTop, m_location.x, m_location.y, x, y, SWP_NOACTIVATE);
SetMineInfo(GRADE_PRIMACY_MAP_SIZE, GRADE_PRIMACY_MINE_COUNT, IDB_BITMAP_PRIMACY_SQUARE);
}
void CMainFrame::OnGradeDedium()
{
// TODO: 在此添加命令处理程序代码
CBitmap bitmap;
BITMAP bitMapInfo;
bitmap.LoadBitmap(IDB_BITMAP_MEDIUM_SQUARE);
bitmap.GetBitmap(&bitMapInfo);
int x = bitMapInfo.bmWidth * (GRADE_MEDIUM_MAP_SIZE + 2) + 15;
x = x > m_minMineMapWidth ? x : m_minMineMapWidth;
int y = bitMapInfo.bmHeight * (GRADE_MEDIUM_MAP_SIZE + 5) + 15;
SetSubMenuGray(SUBMENUGRAY_MEDIUM);
SetWindowPos(&wndTop, m_location.x, m_location.y, x, y, SWP_NOACTIVATE);
SetMineInfo(GRADE_MEDIUM_MAP_SIZE, GRADE_MEDIUM_MINE_COUNT, IDB_BITMAP_MEDIUM_SQUARE);
}
void CMainFrame::OnGradeSenior()
{
// TODO: 在此添加命令处理程序代码
CBitmap bitmap;
BITMAP bitMapInfo;
bitmap.LoadBitmap(IDB_BITMAP_SENIOR_SQUARE);
bitmap.GetBitmap(&bitMapInfo);
int x = bitMapInfo.bmWidth * (GRADE_SENIOR_MAP_SIZE + 2) + 15;
x = x > m_minMineMapWidth ? x : m_minMineMapWidth;
int y = bitMapInfo.bmHeight * (GRADE_SENIOR_MAP_SIZE + 6) + 25;
SetSubMenuGray(SUBMENUGRAY_SENIOR);
SetWindowPos(&wndTop, m_location.x, m_location.y, x, y, SWP_NOACTIVATE);
SetMineInfo(GRADE_SENIOR_MAP_SIZE, GRADE_SENIOR_MINE_COUNT, IDB_BITMAP_SENIOR_SQUARE);
}
void CMainFrame::CustomMineMap()
{
// TODO: 在此添加命令处理程序代码
CBitmap bitmap;
BITMAP bitMapInfo;
bitmap.LoadBitmap(IDB_BITMAP_PRIMACY_SQUARE);
bitmap.GetBitmap(&bitMapInfo);
SetSubMenuGray(SUBMENUGRAY_NULL);
int x = bitMapInfo.bmWidth * (m_setMineMapDlg.m_size + 2) + 15;
x = x > m_minMineMapWidth ? x : m_minMineMapWidth;
int y = bitMapInfo.bmHeight * (m_setMineMapDlg.m_size + 4) + 15;
SetWindowPos(&wndTop, m_location.x, m_location.y, x, y, SWP_NOACTIVATE);
SetMineInfo(m_setMineMapDlg.m_size, m_setMineMapDlg.m_cnt, IDB_BITMAP_PRIMACY_SQUARE);
}
void CMainFrame::OnSetByYourself()
{
// TODO: 在此添加命令处理程序代码
if (IDOK == m_setMineMapDlg.DoModal()) {
CustomMineMap();
}
}
void CMainFrame::SetMineInfo(UINT8 mineSize, UINT16 mineCnt, UINT16 grade)
{
CsweepMineMFCView *pView = (CsweepMineMFCView *)GetActiveView();
pView->SetMineMap(mineSize, mineCnt, grade);
}