-
Notifications
You must be signed in to change notification settings - Fork 0
/
CSELECTION.cpp
296 lines (245 loc) · 7.96 KB
/
CSELECTION.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
// CSELECTION.cpp: 实现文件
//
#include "pch.h"
#include "TXZ.h"
#include "CSELECTION.h"
#include "afxdialogex.h"
/*
xht:
关于控件大小、位置常量的代码,迟早得统统重构
*/
// CSELECTION 对话框
IMPLEMENT_DYNAMIC(CSELECTION, CDialogEx)
CSELECTION::CSELECTION(CRESOURCE* currentRes, CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_SELECTION, pParent),
myDisplay(NULL), myMap(NULL), myRes(currentRes)
{
}
CSELECTION::~CSELECTION()
{
}
void CSELECTION::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CSELECTION, CDialogEx)
ON_BN_CLICKED(IDC_SELECTION_CONFIRMBUTTON, &CSELECTION::OnBnClickedSelectionConfirmbutton)
ON_BN_CLICKED(IDC_SELECTION_CANCELBUTTON, &CSELECTION::OnBnClickedSelectionCancelbutton)
ON_LBN_SELCHANGE(IDC_SELECTION_MAPLIST, &CSELECTION::OnLbnSelchangeSelectionMaplist)
END_MESSAGE_MAP()
// CSELECTION 消息处理程序
BOOL CSELECTION::OnInitDialog()
{
CDialogEx::OnInitDialog();
// TODO: 在此添加额外的初始化
// 设置窗口
// 满屏代码
CRect ClientRect;
GetParent()->GetClientRect(ClientRect);
MoveWindow(ClientRect);
const int DIALOG_HEIGHT = ClientRect.Height();
const int DIALOG_WIDTH = ClientRect.Width();
// 设置窗口控件
const int BUTTON_HEIGHT = (int)(DIALOG_HEIGHT * 0.1);
const int BUTTON_WIDTH = (int)(DIALOG_WIDTH * 0.4);
GetDlgItem(IDC_SELECTION_CONFIRMBUTTON)->MoveWindow((int)(DIALOG_WIDTH * 0.55), (int)(DIALOG_HEIGHT * 0.6), BUTTON_WIDTH, BUTTON_HEIGHT);
GetDlgItem(IDC_SELECTION_CANCELBUTTON)->MoveWindow((int)(DIALOG_WIDTH * 0.55), (int)(DIALOG_HEIGHT * 0.75), BUTTON_WIDTH, BUTTON_HEIGHT);
const int LIST_HEIGHT = (int)(DIALOG_HEIGHT * 0.7);
const int LIST_WIDTH = (int)(DIALOG_WIDTH * 0.45);
GetDlgItem(IDC_SELECTION_MAPLIST)->MoveWindow((int)(DIALOG_WIDTH * 0.05), (int)(DIALOG_HEIGHT * 0.05), LIST_WIDTH, LIST_HEIGHT);
// 开始创建动态预览图
myDisplay = new CBASE_Display(CRect((int)(DIALOG_WIDTH * 0.55), (int)(DIALOG_HEIGHT * 0.1), (int)(DIALOG_WIDTH * 0.95), (int)(DIALOG_HEIGHT*0.6)), myRes);
myDisplay->Create(IDD_DISPLAY, this);
// 创建Map
myMap = new CBASE_Map(myDisplay,false);
// 失败图片
CStatic* pic = (CStatic*)GetDlgItem(IDC_SELECTION_PREVIEWIMAGE);
pic->ShowWindow(SW_HIDE);
pic->SetBitmap(myRes->GetPic(PIC_PREVIEW_FAIL));
pic->MoveWindow((int)(DIALOG_WIDTH * 0.55), (int)(DIALOG_HEIGHT * 0.05), (int)(DIALOG_WIDTH * 0.4), (int)(DIALOG_HEIGHT * 0.45));
// 字体、文字大小、文字内容
m_buttonFont.CreateFont(
(int)(BUTTON_HEIGHT * 0.6), // nHeight
0, // nWidth
0, // nEscapement
0, // nOrientation
//FW_BOLD, // nWeight
FW_NORMAL, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
FALSE, // cStrikeOut
//ANSI_CHARSET, // nCharSet
GB2312_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
_T("隶书")
); // lpszFac
GetDlgItem(IDC_SELECTION_CANCELBUTTON)->SetFont(&m_buttonFont);
GetDlgItem(IDC_SELECTION_CANCELBUTTON)->SetWindowText(_T("返回"));
GetDlgItem(IDC_SELECTION_CANCELBUTTON)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_SELECTION_CONFIRMBUTTON)->SetFont(&m_buttonFont);
GetDlgItem(IDC_SELECTION_CONFIRMBUTTON)->SetWindowText(_T("确认"));
GetDlgItem(IDC_SELECTION_CONFIRMBUTTON)->ShowWindow(SW_SHOW);
m_listFont.CreateFont(
(int)(LIST_HEIGHT * 0.1), // nHeight
0, // nWidth
0, // nEscapement
0, // nOrientation
//FW_BOLD, // nWeight
FW_NORMAL, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
FALSE, // cStrikeOut
//ANSI_CHARSET, // nCharSet
GB2312_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
_T("黑体")
); // lpszFac
GetDlgItem(IDC_SELECTION_MAPLIST)->SetFont(&m_listFont);
InitList();
GetDlgItem(IDC_SELECTION_MAPLIST)->ShowWindow(SW_SHOW);
return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}
void CSELECTION::OnBnClickedSelectionCancelbutton()
{
// TODO: 在此添加控件通知处理程序代码
GetParent()->PostMessage(WM_TOHOMEPAGE);
}
void CSELECTION::OnBnClickedSelectionConfirmbutton()
{
// TODO: 在此添加控件通知处理程序代码
CListBox* myList = (CListBox*)GetDlgItem(IDC_SELECTION_MAPLIST);
CString tempStr;
myList->GetText(myList->GetCurSel(), tempStr);
tempStr = mapPath + tempStr + _T(".txm");
GetParent()->PostMessage(WM_TOGAME, (WPARAM)tempStr.AllocSysString());
}
BOOL CSELECTION::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN)
{
switch (pMsg->wParam)
{
case VK_ESCAPE:
#ifdef MYDEBUG
MessageBox(_T("ESC"), _T("From xht"));
#endif // MYDEBUG
OnBnClickedSelectionCancelbutton();
return TRUE;
break;
/*
case VK_RETURN:
HWND hwnd1 = ((CEdit*)GetDlgItem(IDC_IDINPUT))->m_hWnd;
if (pMsg->hwnd == hwnd1)
{
OnBnClickedConfirmbutton();
return TRUE;
}
break;
*/
}
}
return CDialogEx::PreTranslateMessage(pMsg);
}
void CSELECTION::UpdatePreview(CString mapName) // 显示mapName的缩略图
{
CStatic* pic = (CStatic*)GetDlgItem(IDC_SELECTION_PREVIEWIMAGE); // 预览图的控件
CString selectedMapDir;
selectedMapDir = mapPath + mapName + _T(".txm");
myDisplay->ShowWindow(SW_HIDE);
if (myMap->SetMap(selectedMapDir))
{
myDisplay->ShowWindow(SW_SHOW);
pic->ShowWindow(SW_HIDE);
}
else
{
pic->ShowWindow(SW_SHOW);
}
/*
CStatic* pic = (CStatic*)GetDlgItem(IDC_SELECTION_PREVIEWIMAGE); // 预览图的控件
pic->ShowWindow(SW_HIDE);
CString previewImageDir; // 位图位置
HBITMAP hBMP; // 载入的bmp
previewImageDir = mapPath + mapName + _T(".bmp");
hBMP = (HBITMAP)LoadImage(NULL, previewImageDir, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
if (hBMP == NULL)
{
// 没有缩略图就显示一个默认的defaultmap.bmp
previewImageDir = mapPath + _T("defaultmap.bmp");
hBMP = (HBITMAP)LoadImage(NULL, previewImageDir, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
}
pic->SetBitmap(hBMP);
double tempRatio;
CRect tempRect;
pic->GetClientRect(tempRect);
tempRatio = (double)tempRect.Height() / (double)tempRect.Width();
GetClientRect(tempRect);
const int DIALOG_HEIGHT = tempRect.Height();
const int DIALOG_WIDTH = tempRect.Width();
const int PREVIEW_SIZE = min((int)(DIALOG_HEIGHT * 0.4), (int)(DIALOG_WIDTH * 0.4));
int tempHeight, tempWidth;
if (tempRatio > 1)
{
tempHeight = PREVIEW_SIZE;
tempWidth = (int)(PREVIEW_SIZE / tempRatio);
}
else
{
tempHeight = (int)(PREVIEW_SIZE * tempRatio);
tempWidth = PREVIEW_SIZE;
}
pic->MoveWindow((int)(DIALOG_WIDTH * 0.55) + (PREVIEW_SIZE - tempWidth) / 2, (int)(DIALOG_HEIGHT * 0.05) + (PREVIEW_SIZE - tempHeight) / 2, tempWidth, tempHeight, TRUE);
pic->ShowWindow(SW_SHOW);
*/
}
void CSELECTION::InitList()
{
CFileFind tempFind;
BOOL IsFind = tempFind.FindFile(mapPath + _T("/*.txm"));
CListBox* myList = (CListBox*)GetDlgItem(IDC_SELECTION_MAPLIST);
myList->ResetContent();
while (IsFind)
{
IsFind = tempFind.FindNextFile(); // 找到最后一个文件时返回FALSE
if (tempFind.IsDots() || tempFind.IsDirectory())
{
continue;
}
CString filename = tempFind.GetFileName();
filename = filename.Left(filename.ReverseFind('.'));
myList->AddString(filename);
}
if (myList->GetCount() > 0)
{
myList->SetCurSel(0);
OnLbnSelchangeSelectionMaplist();
GetDlgItem(IDC_SELECTION_CONFIRMBUTTON)->EnableWindow(TRUE);
}
else
{
GetDlgItem(IDC_SELECTION_CONFIRMBUTTON)->EnableWindow(FALSE);
}
}
void CSELECTION::OnLbnSelchangeSelectionMaplist()
{
// TODO: 在此添加控件通知处理程序代码
CListBox* myList = (CListBox*)GetDlgItem(IDC_SELECTION_MAPLIST);
CString tempStr;
myList->GetText(myList->GetCurSel(), tempStr);
UpdatePreview(tempStr);
}
BOOL CSELECTION::DestroyWindow()
{
// TODO: 在此添加专用代码和/或调用基类
myDisplay->DestroyWindow();
delete myDisplay;
delete myMap;
return CDialogEx::DestroyWindow();
}