PropertySheetDlg.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:9k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // PropertySheetDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "PropertySheet.h"
  5. #include "PropertySheetDlg.h"
  6. #include "TabClientPage.h"
  7. #include "TabSamplePage.h"
  8. #include "TabListPage.h"
  9. #include "TabTreePage.h"
  10. #include "TabResizablePage.h"
  11. #include "TabLongPage.h"
  12. #ifdef _DEBUG
  13. #define new DEBUG_NEW
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CPropertySheetDlg dialog
  19. CPropertySheetDlg::CPropertySheetDlg(CWnd* pParent /*=NULL*/)
  20. : CDialog(CPropertySheetDlg::IDD, pParent)
  21. {
  22. //{{AFX_DATA_INIT(CPropertySheetDlg)
  23. // NOTE: the ClassWizard will add member initialization here
  24. //}}AFX_DATA_INIT
  25. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  26. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  27. }
  28. void CPropertySheetDlg::DoDataExchange(CDataExchange* pDX)
  29. {
  30. CDialog::DoDataExchange(pDX);
  31. //{{AFX_DATA_MAP(CPropertySheetDlg)
  32. // NOTE: the ClassWizard will add DDX and DDV calls here
  33. //}}AFX_DATA_MAP
  34. }
  35. BEGIN_MESSAGE_MAP(CPropertySheetDlg, CDialog)
  36. //{{AFX_MSG_MAP(CPropertySheetDlg)
  37. ON_WM_SYSCOMMAND()
  38. ON_WM_PAINT()
  39. ON_WM_QUERYDRAGICON()
  40. ON_BN_CLICKED(IDC_BUTTON_STANDARD, OnButtonStandard)
  41. ON_BN_CLICKED(IDC_BUTTON_LIST, OnButtonList)
  42. ON_BN_CLICKED(IDC_BUTTON_TREE, OnButtonTree)
  43. ON_BN_CLICKED(IDC_BUTTON_LIST2, OnButtonList2)
  44. ON_BN_CLICKED(IDC_BUTTON_TASKPANEL, OnButtonTaskPanel)
  45. //}}AFX_MSG_MAP
  46. END_MESSAGE_MAP()
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CPropertySheetDlg message handlers
  49. BOOL CPropertySheetDlg::OnInitDialog()
  50. {
  51. CDialog::OnInitDialog();
  52. // Add "About..." menu item to system menu.
  53. // IDM_ABOUTBOX must be in the system command range.
  54. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  55. ASSERT(IDM_ABOUTBOX < 0xF000);
  56. CMenu* pSysMenu = GetSystemMenu(FALSE);
  57. if (pSysMenu != NULL)
  58. {
  59. CString strAboutMenu;
  60. strAboutMenu.LoadString(IDS_ABOUTBOX);
  61. if (!strAboutMenu.IsEmpty())
  62. {
  63. pSysMenu->AppendMenu(MF_SEPARATOR);
  64. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  65. }
  66. }
  67. // Set the icon for this dialog.  The framework does this automatically
  68. //  when the application's main window is not a dialog
  69. SetIcon(m_hIcon, TRUE); // Set big icon
  70. SetIcon(m_hIcon, FALSE); // Set small icon
  71. // TODO: Add extra initialization here
  72. return TRUE;  // return TRUE  unless you set the focus to a control
  73. }
  74. void CPropertySheetDlg::OnSysCommand(UINT nID, LPARAM lParam)
  75. {
  76. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  77. {
  78. CAboutDlg dlgAbout;
  79. dlgAbout.DoModal();
  80. }
  81. else
  82. {
  83. CDialog::OnSysCommand(nID, lParam);
  84. }
  85. }
  86. // If you add a minimize button to your dialog, you will need the code below
  87. //  to draw the icon.  For MFC applications using the document/view model,
  88. //  this is automatically done for you by the framework.
  89. void CPropertySheetDlg::OnPaint() 
  90. {
  91. if (IsIconic())
  92. {
  93. CPaintDC dc(this); // device context for painting
  94. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  95. // Center icon in client rectangle
  96. int cxIcon = GetSystemMetrics(SM_CXICON);
  97. int cyIcon = GetSystemMetrics(SM_CYICON);
  98. CRect rect;
  99. GetClientRect(&rect);
  100. int x = (rect.Width() - cxIcon + 1) / 2;
  101. int y = (rect.Height() - cyIcon + 1) / 2;
  102. // Draw the icon
  103. dc.DrawIcon(x, y, m_hIcon);
  104. }
  105. else
  106. {
  107. CDialog::OnPaint();
  108. }
  109. }
  110. // The system calls this to obtain the cursor to display while the user drags
  111. //  the minimized window.
  112. HCURSOR CPropertySheetDlg::OnQueryDragIcon()
  113. {
  114. return (HCURSOR) m_hIcon;
  115. }
  116. void CPropertySheetDlg::OnButtonStandard() 
  117. {
  118. CXTPPropertySheet ps(_T("Standard CXTPPRopertySheet Sample"));
  119. CTabControlPage pageProperties;
  120. CTabSamplePage pageSample;
  121. ps.AddPage(&pageProperties);
  122. ps.AddPage(&pageSample);
  123. ps.DoModal();
  124. }
  125. void CPropertySheetDlg::OnButtonList() 
  126. {
  127. CXTPPropertySheet ps(_T("CXTPPropertyPageListNavigator Sample"));
  128. CXTPPropertyPageListNavigator* pList = new CXTPPropertyPageListNavigator();
  129. pList->SetListStyle(xtListBoxOffice2007);
  130. ps.SetNavigator(pList);
  131. CTabListPage pageProperties;
  132. CTabSamplePage pageSample;
  133. CTabResizablePage pageSize;
  134. ps.AddPage(&pageProperties);
  135. ps.AddPage(&pageSample);
  136. ps.AddPage(&pageSize);
  137. ps.SetResizable();
  138. ps.DoModal();
  139. }
  140. void CPropertySheetDlg::OnButtonList2() 
  141. {
  142. CXTPPropertySheet ps(_T("CXTPPropertyPageListNavigator Sample"));
  143. CXTPPropertyPageListNavigator* pList = new CXTPPropertyPageListNavigator();
  144. pList->SetListStyle(xtListBoxOffice2007);
  145. ps.SetNavigator(pList);
  146. CTabLongPage pageLong;
  147. ps.AddPage(&pageLong);
  148. ps.SetResizable();
  149. ps.SetPageSize(CSize(250, 180)); // in dialog units
  150. ps.DoModal();
  151. }
  152. class CCategoriesTreeNavigator : public CXTPPropertyPageTreeNavigator
  153. {
  154. public:
  155. CCategoriesTreeNavigator()
  156. : CXTPPropertyPageTreeNavigator(TVS_SHOWSELALWAYS | TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT)
  157. {
  158. }
  159. BOOL CreateTree()
  160. {
  161. ASSERT(m_pSheet->GetPageCount() == 2);
  162. if (m_pSheet->GetPageCount() != 2)
  163. return FALSE;
  164. HTREEITEM hItemGeneral = InsertItem(_T("General"));
  165. HTREEITEM hItemOptions = InsertItem(_T("Options"));
  166. for (int i = 0; i < m_pSheet->GetPageCount(); i++)
  167. {
  168. CXTPPropertyPage* pPage = m_pSheet->GetPage(i);
  169. CString strCaption = pPage->GetCaption();
  170. HTREEITEM hItem = InsertItem(strCaption, -1, -1, i == 0 ? hItemGeneral : hItemOptions);
  171. SetItemData(hItem, (DWORD_PTR)pPage);
  172. pPage->m_dwData = (DWORD_PTR)hItem;
  173. }
  174. return TRUE;
  175. }
  176. };
  177. void CPropertySheetDlg::OnButtonTree() 
  178. {
  179. #if 1
  180. CXTPPropertySheet ps(_T("CXTPPropertyPageTreeNavigator Sample"));
  181. ps.SetNavigator(new CCategoriesTreeNavigator());
  182. ps.m_psh.dwFlags |= PSH_NOAPPLYNOW;
  183. CTabTreePage pageProperties;
  184. CTabSamplePage pageSample2;
  185. ps.AddPage(&pageProperties);
  186. ps.AddPage(&pageSample2);
  187. ps.SetResizable();
  188. ps.DoModal();
  189. #else // Modeless
  190. class CSamplePropertySheet : public CXTPPropertySheet
  191. {
  192. public:
  193. CSamplePropertySheet()
  194. : CXTPPropertySheet(_T("CXTPPropertyPageTreeNavigator Sample"))
  195. {
  196. SetNavigator(new CCategoriesTreeNavigator());
  197. m_psh.dwFlags |= PSH_NOAPPLYNOW;
  198. AddPage(&pageProperties);
  199. AddPage(&pageSample2);
  200. SetResizable();
  201. }
  202. CTabTreePage pageProperties;
  203. CTabSamplePage pageSample2;
  204. };
  205. CSamplePropertySheet* ps = new CSamplePropertySheet();
  206. ps->Create();
  207. #endif
  208. }
  209. #ifdef _XTP_INCLUDE_TASKPANEL
  210. //////////////////////////////////////////////////////////////////////////
  211. // CPropertyPageTaskPanelNavigator
  212. class CPropertyPageTaskPanelNavigator : public CXTPTaskPanel, public CXTPPropertyPageControlNavigator
  213. {
  214. public:
  215. CPropertyPageTaskPanelNavigator();
  216. public:
  217. virtual BOOL Create();
  218. virtual void OnPageSelected(CXTPPropertyPage* pPage);
  219. virtual HWND GetSafeHwnd() const { return m_hWnd; }
  220. protected:
  221. virtual void SetFocusedItem(CXTPTaskPanelItem* pItem, BOOL bDrawFocusRect = FALSE, BOOL bSetFocus = TRUE);
  222. };
  223. CPropertyPageTaskPanelNavigator::CPropertyPageTaskPanelNavigator()
  224. {
  225. }
  226. BOOL CPropertyPageTaskPanelNavigator::Create()
  227. {
  228. CFont* pFont = m_pSheet->GetFont();
  229. if (!CXTPTaskPanel::Create(WS_VISIBLE | WS_CHILD | WS_GROUP | WS_TABSTOP, CRect(0, 0, 0, 0), m_pSheet, 1000))
  230. return FALSE;
  231. SetBehaviour(xtpTaskPanelBehaviourList);
  232. SetTheme(xtpTaskPanelThemeShortcutBarOffice2003);
  233. SetSelectItemOnFocus(TRUE);
  234. SetIconSize(CSize(32, 32));
  235. SetFont(pFont);
  236. CXTPTaskPanelGroup* pGroup = AddGroup(0);
  237. pGroup->SetCaption(_T("Properties"));
  238. for (int i = 0; i < m_pSheet->GetPageCount(); i++)
  239. {
  240. CXTPPropertyPage* pPage = m_pSheet->GetPage(i);
  241. CString strCaption = pPage->GetCaption();
  242. CXTPTaskPanelGroupItem* pItem = pGroup->AddLinkItem(i, i);
  243. pItem->SetCaption(strCaption);
  244. pItem->SetItemData((DWORD_PTR)pPage);
  245. pPage->m_dwData = (DWORD_PTR)pItem;
  246. }
  247. GetImageManager()->SetIcon(IDI_CONTACTS, 0);
  248. GetImageManager()->SetIcon(IDI_TASKS, 1);
  249. GetImageManager()->SetIcon(IDI_NOTES, 2);
  250. m_pSheet->SetPageBorderStyle(xtpPageBorderBottomLine);
  251. return TRUE;
  252. }
  253. void CPropertyPageTaskPanelNavigator::OnPageSelected(CXTPPropertyPage* pPage)
  254. {
  255. CXTPTaskPanelGroupItem* pItem = (CXTPTaskPanelGroupItem*)pPage->m_dwData;
  256. SetFocusedItem(pItem);
  257. }
  258. void CPropertyPageTaskPanelNavigator::SetFocusedItem(CXTPTaskPanelItem* pItem, BOOL bDrawFocusRect /*= FALSE*/, BOOL bSetFocus)
  259. {
  260. if (m_pItemFocused != pItem && pItem && pItem->GetType() == xtpTaskItemTypeLink)
  261. {
  262. CXTPPropertyPage* pPage = (CXTPPropertyPage*)pItem->GetItemData();
  263. if (!m_pSheet->SetActivePage(pPage))
  264. {
  265. return;
  266. }
  267. }
  268. CXTPTaskPanel::SetFocusedItem(pItem, bDrawFocusRect, bSetFocus);
  269. }
  270. void CPropertySheetDlg::OnButtonTaskPanel()
  271. {
  272. CXTPPropertySheet ps(_T("Custom Navigator Sample"));
  273. CPropertyPageTaskPanelNavigator* pList = new CPropertyPageTaskPanelNavigator();
  274. ps.SetNavigator(pList);
  275. CTabTreePage pageProperties;
  276. CTabSamplePage pageSample;
  277. CTabResizablePage pageSize;
  278. ps.AddPage(&pageProperties);
  279. ps.AddPage(&pageSample);
  280. ps.AddPage(&pageSize);
  281. ps.SetResizable();
  282. ps.DoModal();
  283. }
  284. #else // _XTP_INCLUDE_TASKPANEL
  285. void CPropertySheetDlg::OnButtonTaskPanel()
  286. {
  287. }
  288. #endif