PropertiesWnd.cpp 8.2 KB

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