提交 | 用户 | age
|
0ed438
|
1 |
|
Q |
2 |
#include "pch.h"
|
|
3 |
#include "framework.h"
|
|
4 |
|
|
5 |
#include "PropertiesWnd.h"
|
|
6 |
#include "Resource.h"
|
|
7 |
#include "MainFrm.h"
|
|
8 |
#include "MTerm1.h"
|
|
9 |
|
|
10 |
#ifdef _DEBUG
|
|
11 |
#undef THIS_FILE
|
|
12 |
static char THIS_FILE[]=__FILE__;
|
|
13 |
#define new DEBUG_NEW
|
|
14 |
#endif
|
|
15 |
|
|
16 |
/////////////////////////////////////////////////////////////////////////////
|
|
17 |
// CResourceViewBar
|
|
18 |
|
|
19 |
CPropertiesWnd::CPropertiesWnd() noexcept
|
|
20 |
{
|
|
21 |
m_nComboHeight = 0;
|
|
22 |
}
|
|
23 |
|
|
24 |
CPropertiesWnd::~CPropertiesWnd()
|
|
25 |
{
|
|
26 |
}
|
|
27 |
|
|
28 |
BEGIN_MESSAGE_MAP(CPropertiesWnd, CDockablePane)
|
|
29 |
ON_WM_CREATE()
|
|
30 |
ON_WM_SIZE()
|
|
31 |
ON_COMMAND(ID_EXPAND_ALL, OnExpandAllProperties)
|
|
32 |
ON_UPDATE_COMMAND_UI(ID_EXPAND_ALL, OnUpdateExpandAllProperties)
|
|
33 |
ON_COMMAND(ID_SORTPROPERTIES, OnSortProperties)
|
|
34 |
ON_UPDATE_COMMAND_UI(ID_SORTPROPERTIES, OnUpdateSortProperties)
|
|
35 |
ON_COMMAND(ID_PROPERTIES1, OnProperties1)
|
|
36 |
ON_UPDATE_COMMAND_UI(ID_PROPERTIES1, OnUpdateProperties1)
|
|
37 |
ON_COMMAND(ID_PROPERTIES2, OnProperties2)
|
|
38 |
ON_UPDATE_COMMAND_UI(ID_PROPERTIES2, OnUpdateProperties2)
|
|
39 |
ON_WM_SETFOCUS()
|
|
40 |
ON_WM_SETTINGCHANGE()
|
|
41 |
END_MESSAGE_MAP()
|
|
42 |
|
|
43 |
/////////////////////////////////////////////////////////////////////////////
|
|
44 |
// CResourceViewBar 消息处理程序
|
|
45 |
|
|
46 |
void CPropertiesWnd::AdjustLayout()
|
|
47 |
{
|
|
48 |
if (GetSafeHwnd () == nullptr || (AfxGetMainWnd() != nullptr && AfxGetMainWnd()->IsIconic()))
|
|
49 |
{
|
|
50 |
return;
|
|
51 |
}
|
|
52 |
|
|
53 |
CRect rectClient;
|
|
54 |
GetClientRect(rectClient);
|
|
55 |
|
|
56 |
int cyTlb = m_wndToolBar.CalcFixedLayout(FALSE, TRUE).cy;
|
|
57 |
|
|
58 |
m_wndObjectCombo.SetWindowPos(nullptr, rectClient.left, rectClient.top, rectClient.Width(), m_nComboHeight, SWP_NOACTIVATE | SWP_NOZORDER);
|
|
59 |
m_wndToolBar.SetWindowPos(nullptr, rectClient.left, rectClient.top + m_nComboHeight, rectClient.Width(), cyTlb, SWP_NOACTIVATE | SWP_NOZORDER);
|
|
60 |
m_wndPropList.SetWindowPos(nullptr, rectClient.left, rectClient.top + m_nComboHeight + cyTlb, rectClient.Width(), rectClient.Height() -(m_nComboHeight+cyTlb), SWP_NOACTIVATE | SWP_NOZORDER);
|
|
61 |
}
|
|
62 |
|
|
63 |
int CPropertiesWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
|
|
64 |
{
|
|
65 |
if (CDockablePane::OnCreate(lpCreateStruct) == -1)
|
|
66 |
return -1;
|
|
67 |
|
|
68 |
CRect rectDummy;
|
|
69 |
rectDummy.SetRectEmpty();
|
|
70 |
|
|
71 |
// 创建组合:
|
|
72 |
const DWORD dwViewStyle = WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | WS_BORDER | CBS_SORT | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
|
|
73 |
|
|
74 |
if (!m_wndObjectCombo.Create(dwViewStyle, rectDummy, this, 1))
|
|
75 |
{
|
|
76 |
TRACE0("未能创建属性组合 \n");
|
|
77 |
return -1; // 未能创建
|
|
78 |
}
|
|
79 |
|
|
80 |
m_wndObjectCombo.AddString(_T("应用程序"));
|
|
81 |
m_wndObjectCombo.AddString(_T("属性窗口"));
|
|
82 |
m_wndObjectCombo.SetCurSel(0);
|
|
83 |
|
|
84 |
CRect rectCombo;
|
|
85 |
m_wndObjectCombo.GetClientRect (&rectCombo);
|
|
86 |
|
|
87 |
m_nComboHeight = rectCombo.Height();
|
|
88 |
|
|
89 |
if (!m_wndPropList.Create(WS_VISIBLE | WS_CHILD, rectDummy, this, 2))
|
|
90 |
{
|
|
91 |
TRACE0("未能创建属性网格\n");
|
|
92 |
return -1; // 未能创建
|
|
93 |
}
|
|
94 |
|
|
95 |
InitPropList();
|
|
96 |
|
|
97 |
m_wndToolBar.Create(this, AFX_DEFAULT_TOOLBAR_STYLE, IDR_PROPERTIES);
|
|
98 |
m_wndToolBar.LoadToolBar(IDR_PROPERTIES, 0, 0, TRUE /* 已锁定*/);
|
|
99 |
m_wndToolBar.CleanUpLockedImages();
|
|
100 |
m_wndToolBar.LoadBitmap(theApp.m_bHiColorIcons ? IDB_PROPERTIES_HC : IDR_PROPERTIES, 0, 0, TRUE /* 锁定*/);
|
|
101 |
|
|
102 |
m_wndToolBar.SetPaneStyle(m_wndToolBar.GetPaneStyle() | CBRS_TOOLTIPS | CBRS_FLYBY);
|
|
103 |
m_wndToolBar.SetPaneStyle(m_wndToolBar.GetPaneStyle() & ~(CBRS_GRIPPER | CBRS_SIZE_DYNAMIC | CBRS_BORDER_TOP | CBRS_BORDER_BOTTOM | CBRS_BORDER_LEFT | CBRS_BORDER_RIGHT));
|
|
104 |
m_wndToolBar.SetOwner(this);
|
|
105 |
|
|
106 |
// 所有命令将通过此控件路由,而不是通过主框架路由:
|
|
107 |
m_wndToolBar.SetRouteCommandsViaFrame(FALSE);
|
|
108 |
|
|
109 |
AdjustLayout();
|
|
110 |
return 0;
|
|
111 |
}
|
|
112 |
|
|
113 |
void CPropertiesWnd::OnSize(UINT nType, int cx, int cy)
|
|
114 |
{
|
|
115 |
CDockablePane::OnSize(nType, cx, cy);
|
|
116 |
AdjustLayout();
|
|
117 |
}
|
|
118 |
|
|
119 |
void CPropertiesWnd::OnExpandAllProperties()
|
|
120 |
{
|
|
121 |
m_wndPropList.ExpandAll();
|
|
122 |
}
|
|
123 |
|
|
124 |
void CPropertiesWnd::OnUpdateExpandAllProperties(CCmdUI* /* pCmdUI */)
|
|
125 |
{
|
|
126 |
}
|
|
127 |
|
|
128 |
void CPropertiesWnd::OnSortProperties()
|
|
129 |
{
|
|
130 |
m_wndPropList.SetAlphabeticMode(!m_wndPropList.IsAlphabeticMode());
|
|
131 |
}
|
|
132 |
|
|
133 |
void CPropertiesWnd::OnUpdateSortProperties(CCmdUI* pCmdUI)
|
|
134 |
{
|
|
135 |
pCmdUI->SetCheck(m_wndPropList.IsAlphabeticMode());
|
|
136 |
}
|
|
137 |
|
|
138 |
void CPropertiesWnd::OnProperties1()
|
|
139 |
{
|
|
140 |
// TODO: 在此处添加命令处理程序代码
|
|
141 |
}
|
|
142 |
|
|
143 |
void CPropertiesWnd::OnUpdateProperties1(CCmdUI* /*pCmdUI*/)
|
|
144 |
{
|
|
145 |
// TODO: 在此处添加命令更新 UI 处理程序代码
|
|
146 |
}
|
|
147 |
|
|
148 |
void CPropertiesWnd::OnProperties2()
|
|
149 |
{
|
|
150 |
// TODO: 在此处添加命令处理程序代码
|
|
151 |
}
|
|
152 |
|
|
153 |
void CPropertiesWnd::OnUpdateProperties2(CCmdUI* /*pCmdUI*/)
|
|
154 |
{
|
|
155 |
// TODO: 在此处添加命令更新 UI 处理程序代码
|
|
156 |
}
|
|
157 |
|
|
158 |
void CPropertiesWnd::InitPropList()
|
|
159 |
{
|
|
160 |
SetPropListFont();
|
|
161 |
|
|
162 |
m_wndPropList.EnableHeaderCtrl(FALSE);
|
|
163 |
m_wndPropList.EnableDescriptionArea();
|
|
164 |
m_wndPropList.SetVSDotNetLook();
|
|
165 |
m_wndPropList.MarkModifiedProperties();
|
|
166 |
|
|
167 |
CMFCPropertyGridProperty* pGroup1 = new CMFCPropertyGridProperty(_T("外观"));
|
|
168 |
|
|
169 |
pGroup1->AddSubItem(new CMFCPropertyGridProperty(_T("三维外观"), (_variant_t) false, _T("指定窗口的字体不使用粗体,并且控件将使用三维边框")));
|
|
170 |
|
|
171 |
CMFCPropertyGridProperty* pProp = new CMFCPropertyGridProperty(_T("边框"), _T("对话框外框"), _T("其中之一: “无”、“细”、“可调整大小”或“对话框外框”"));
|
|
172 |
pProp->AddOption(_T("无"));
|
|
173 |
pProp->AddOption(_T("细"));
|
|
174 |
pProp->AddOption(_T("可调整大小"));
|
|
175 |
pProp->AddOption(_T("对话框外框"));
|
|
176 |
pProp->AllowEdit(FALSE);
|
|
177 |
|
|
178 |
pGroup1->AddSubItem(pProp);
|
|
179 |
pGroup1->AddSubItem(new CMFCPropertyGridProperty(_T("标题"), (_variant_t) _T("关于"), _T("指定窗口标题栏中显示的文本")));
|
|
180 |
|
|
181 |
m_wndPropList.AddProperty(pGroup1);
|
|
182 |
|
|
183 |
CMFCPropertyGridProperty* pSize = new CMFCPropertyGridProperty(_T("窗口大小"), 0, TRUE);
|
|
184 |
|
|
185 |
pProp = new CMFCPropertyGridProperty(_T("高度"), (_variant_t) 250l, _T("指定窗口的高度"));
|
|
186 |
pProp->EnableSpinControl(TRUE, 50, 300);
|
|
187 |
pSize->AddSubItem(pProp);
|
|
188 |
|
|
189 |
pProp = new CMFCPropertyGridProperty( _T("宽度"), (_variant_t) 150l, _T("指定窗口的宽度"));
|
|
190 |
pProp->EnableSpinControl(TRUE, 50, 200);
|
|
191 |
pSize->AddSubItem(pProp);
|
|
192 |
|
|
193 |
m_wndPropList.AddProperty(pSize);
|
|
194 |
|
|
195 |
CMFCPropertyGridProperty* pGroup2 = new CMFCPropertyGridProperty(_T("字体"));
|
|
196 |
|
|
197 |
LOGFONT lf;
|
|
198 |
CFont* font = CFont::FromHandle((HFONT) GetStockObject(DEFAULT_GUI_FONT));
|
|
199 |
font->GetLogFont(&lf);
|
|
200 |
|
|
201 |
_tcscpy_s(lf.lfFaceName, _T("宋体, Arial"));
|
|
202 |
|
|
203 |
pGroup2->AddSubItem(new CMFCPropertyGridFontProperty(_T("字体"), lf, CF_EFFECTS | CF_SCREENFONTS, _T("指定窗口的默认字体")));
|
|
204 |
pGroup2->AddSubItem(new CMFCPropertyGridProperty(_T("使用系统字体"), (_variant_t) true, _T("指定窗口使用“MS Shell Dlg”字体")));
|
|
205 |
|
|
206 |
m_wndPropList.AddProperty(pGroup2);
|
|
207 |
|
|
208 |
CMFCPropertyGridProperty* pGroup3 = new CMFCPropertyGridProperty(_T("杂项"));
|
|
209 |
pProp = new CMFCPropertyGridProperty(_T("(名称)"), _T("应用程序"));
|
|
210 |
pProp->Enable(FALSE);
|
|
211 |
pGroup3->AddSubItem(pProp);
|
|
212 |
|
|
213 |
CMFCPropertyGridColorProperty* pColorProp = new CMFCPropertyGridColorProperty(_T("窗口颜色"), RGB(210, 192, 254), nullptr, _T("指定默认的窗口颜色"));
|
|
214 |
pColorProp->EnableOtherButton(_T("其他..."));
|
|
215 |
pColorProp->EnableAutomaticButton(_T("默认"), ::GetSysColor(COLOR_3DFACE));
|
|
216 |
pGroup3->AddSubItem(pColorProp);
|
|
217 |
|
|
218 |
static const TCHAR szFilter[] = _T("图标文件(*.ico)|*.ico|所有文件(*.*)|*.*||");
|
|
219 |
pGroup3->AddSubItem(new CMFCPropertyGridFileProperty(_T("图标"), TRUE, _T(""), _T("ico"), 0, szFilter, _T("指定窗口图标")));
|
|
220 |
|
|
221 |
pGroup3->AddSubItem(new CMFCPropertyGridFileProperty(_T("文件夹"), _T("c:\\")));
|
|
222 |
|
|
223 |
m_wndPropList.AddProperty(pGroup3);
|
|
224 |
|
|
225 |
CMFCPropertyGridProperty* pGroup4 = new CMFCPropertyGridProperty(_T("层次结构"));
|
|
226 |
|
|
227 |
CMFCPropertyGridProperty* pGroup41 = new CMFCPropertyGridProperty(_T("第一个子级"));
|
|
228 |
pGroup4->AddSubItem(pGroup41);
|
|
229 |
|
|
230 |
CMFCPropertyGridProperty* pGroup411 = new CMFCPropertyGridProperty(_T("第二个子级"));
|
|
231 |
pGroup41->AddSubItem(pGroup411);
|
|
232 |
|
|
233 |
pGroup411->AddSubItem(new CMFCPropertyGridProperty(_T("项 1"), (_variant_t) _T("值 1"), _T("此为说明")));
|
|
234 |
pGroup411->AddSubItem(new CMFCPropertyGridProperty(_T("项 2"), (_variant_t) _T("值 2"), _T("此为说明")));
|
|
235 |
pGroup411->AddSubItem(new CMFCPropertyGridProperty(_T("项 3"), (_variant_t) _T("值 3"), _T("此为说明")));
|
|
236 |
|
|
237 |
pGroup4->Expand(FALSE);
|
|
238 |
m_wndPropList.AddProperty(pGroup4);
|
|
239 |
}
|
|
240 |
|
|
241 |
void CPropertiesWnd::OnSetFocus(CWnd* pOldWnd)
|
|
242 |
{
|
|
243 |
CDockablePane::OnSetFocus(pOldWnd);
|
|
244 |
m_wndPropList.SetFocus();
|
|
245 |
}
|
|
246 |
|
|
247 |
void CPropertiesWnd::OnSettingChange(UINT uFlags, LPCTSTR lpszSection)
|
|
248 |
{
|
|
249 |
CDockablePane::OnSettingChange(uFlags, lpszSection);
|
|
250 |
SetPropListFont();
|
|
251 |
}
|
|
252 |
|
|
253 |
void CPropertiesWnd::SetPropListFont()
|
|
254 |
{
|
|
255 |
::DeleteObject(m_fntPropList.Detach());
|
|
256 |
|
|
257 |
LOGFONT lf;
|
|
258 |
afxGlobalData.fontRegular.GetLogFont(&lf);
|
|
259 |
|
|
260 |
NONCLIENTMETRICS info;
|
|
261 |
info.cbSize = sizeof(info);
|
|
262 |
|
|
263 |
afxGlobalData.GetNonClientMetrics(info);
|
|
264 |
|
|
265 |
lf.lfHeight = info.lfMenuFont.lfHeight;
|
|
266 |
lf.lfWeight = info.lfMenuFont.lfWeight;
|
|
267 |
lf.lfItalic = info.lfMenuFont.lfItalic;
|
|
268 |
|
|
269 |
m_fntPropList.CreateFontIndirect(&lf);
|
|
270 |
|
|
271 |
m_wndPropList.SetFont(&m_fntPropList);
|
|
272 |
m_wndObjectCombo.SetFont(&m_fntPropList);
|
|
273 |
}
|