DlgDlg.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. // DlgDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "dlgsample.h"
  5. #include "DlgDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. #define IDC_PROPERTYTREE 100
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CDlgDlg dialog
  14. CDlgDlg::CDlgDlg(CWnd* pParent /*=NULL*/)
  15. : CDialog(CDlgDlg::IDD, pParent)
  16. {
  17. //{{AFX_DATA_INIT(CDlgDlg)
  18. // NOTE: the ClassWizard will add member initialization here
  19. //}}AFX_DATA_INIT
  20. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  21. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  22. }
  23. void CDlgDlg::DoDataExchange(CDataExchange* pDX)
  24. {
  25. CDialog::DoDataExchange(pDX);
  26. //{{AFX_DATA_MAP(CDlgDlg)
  27. // NOTE: the ClassWizard will add DDX and DDV calls here
  28. //}}AFX_DATA_MAP
  29. }
  30. BEGIN_MESSAGE_MAP(CDlgDlg, CDialog)
  31. //{{AFX_MSG_MAP(CDlgDlg)
  32. ON_WM_PAINT()
  33. ON_WM_QUERYDRAGICON()
  34. ON_WM_SIZE()
  35. ON_WM_ERASEBKGND()
  36. //}}AFX_MSG_MAP
  37. ON_NOTIFY(PTN_ITEMCHANGED, IDC_PROPERTYTREE, OnItemChanged)
  38. END_MESSAGE_MAP()
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CDlgDlg message handlers
  41. BOOL CDlgDlg::OnInitDialog()
  42. {
  43. CDialog::OnInitDialog();
  44. // Set the icon for this dialog. The framework does this automatically
  45. // when the application's main window is not a dialog
  46. SetIcon(m_hIcon, TRUE); // Set big icon
  47. SetIcon(m_hIcon, FALSE); // Set small icon
  48. DWORD dwStyle;
  49. CRect rc;
  50. // PTS_NOTIFY - CPropTree will send notification messages to the parent window
  51. dwStyle = WS_CHILD|WS_VISIBLE|PTS_NOTIFY;
  52. // Init the control's size to cover the entire client area
  53. GetClientRect(rc);
  54. // Create CPropTree control
  55. m_Tree.Create(dwStyle, rc, this, IDC_PROPERTYTREE);
  56. //
  57. // Create some tree items
  58. //
  59. // Create a root item (root items should always be CPropTreeItem object since they
  60. // can not have properties
  61. CPropTreeItem* pRoot;
  62. pRoot = m_Tree.InsertItem(new CPropTreeItem());
  63. pRoot->SetLabelText(_T("Properties"));
  64. pRoot->SetInfoText(_T("This is a root level item"));
  65. pRoot->Expand(); // have this item expanded by default
  66. // Create a static item
  67. CPropTreeItem* pItem;
  68. pItem = m_Tree.InsertItem(new CPropTreeItem(), pRoot);
  69. pItem->SetLabelText(_T("Sub Item"));
  70. pItem->SetInfoText(_T("This is a simple subitem"));
  71. // Create a dropdown combolist box
  72. CPropTreeItemCombo* pCombo;
  73. pCombo = (CPropTreeItemCombo*)m_Tree.InsertItem(new CPropTreeItemCombo(), pRoot);
  74. pCombo->SetLabelText(_T("Combo Item"));
  75. pCombo->SetInfoText(_T("This is a TRUE/FALSE dropdown combo list"));
  76. pCombo->CreateComboBoxBool(); // create the ComboBox control and auto fill with TRUE/FALSE values
  77. pCombo->SetItemValue(TRUE); // set the combo box to default as TRUE
  78. // Create another item
  79. pItem = m_Tree.InsertItem(new CPropTreeItemStatic(), pRoot);
  80. pItem->SetLabelText(_T("Sub Item 2"));
  81. pItem->SetInfoText(_T("This is item has child items"));
  82. pItem->SetItemValue((LPARAM)_T("Text Info"));
  83. // Create a child item
  84. pItem = m_Tree.InsertItem(new CPropTreeItem(), pItem);
  85. pItem->SetLabelText(_T("SubSub"));
  86. pItem->SetInfoText(_T("This is item has a check box"));
  87. pItem->HasCheckBox(); // we want this item to have a checkbox
  88. pItem->Check(); // have the checkbox initially checked
  89. // Create another item
  90. pItem = m_Tree.InsertItem(new CPropTreeItem(), pRoot);
  91. pItem->SetLabelText(_T("Sub Item 3"));
  92. // Create another root item
  93. pRoot = m_Tree.InsertItem(new CPropTreeItem());
  94. pRoot->SetLabelText(_T("Styles"));
  95. // Create a color item
  96. CPropTreeItemColor* pColor;
  97. pColor = (CPropTreeItemColor*)m_Tree.InsertItem(new CPropTreeItemColor(), pRoot);
  98. pColor->SetLabelText(_T("Color"));
  99. pColor->SetInfoText(_T("Simple color picker"));
  100. pColor->SetItemValue((LPARAM)RGB(0xff, 0xff, 0x00)); // default as color yellow
  101. CPropTreeItemEdit* pEdit;
  102. pEdit = (CPropTreeItemEdit*)m_Tree.InsertItem(new CPropTreeItemEdit(), pRoot);
  103. pEdit->SetLabelText(_T("Name"));
  104. pEdit->SetInfoText(_T("Edit text attribute"));
  105. pEdit->SetItemValue((LPARAM)_T("This text is editable"));
  106. pEdit = (CPropTreeItemEdit*)m_Tree.InsertItem(new CPropTreeItemEdit(), pRoot);
  107. pEdit->SetLabelText(_T("Number"));
  108. pEdit->SetInfoText(_T("Number edit box"));
  109. pEdit->SetValueFormat(CPropTreeItemEdit::ValueFormatNumber); // this allows you to
  110. // pass in a number in SetItemValue
  111. pEdit->SetItemValue((LPARAM)56);
  112. return TRUE; // return TRUE unless you set the focus to a control
  113. }
  114. // If you add a minimize button to your dialog, you will need the code below
  115. // to draw the icon. For MFC applications using the document/view model,
  116. // this is automatically done for you by the framework.
  117. void CDlgDlg::OnPaint()
  118. {
  119. if (IsIconic())
  120. {
  121. CPaintDC dc(this); // device context for painting
  122. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  123. // Center icon in client rectangle
  124. int cxIcon = GetSystemMetrics(SM_CXICON);
  125. int cyIcon = GetSystemMetrics(SM_CYICON);
  126. CRect rect;
  127. GetClientRect(&rect);
  128. int x = (rect.Width() - cxIcon + 1) / 2;
  129. int y = (rect.Height() - cyIcon + 1) / 2;
  130. // Draw the icon
  131. dc.DrawIcon(x, y, m_hIcon);
  132. }
  133. else
  134. {
  135. CDialog::OnPaint();
  136. }
  137. }
  138. // The system calls this to obtain the cursor to display while the user drags
  139. // the minimized window.
  140. HCURSOR CDlgDlg::OnQueryDragIcon()
  141. {
  142. return (HCURSOR) m_hIcon;
  143. }
  144. void CDlgDlg::OnSize(UINT nType, int cx, int cy)
  145. {
  146. CDialog::OnSize(nType, cx, cy);
  147. // resize the control to always fit the dialog
  148. if (::IsWindow(m_Tree.GetSafeHwnd()))
  149. m_Tree.SetWindowPos(NULL, -1, -1, cx, cy, SWP_NOMOVE|SWP_NOZORDER);
  150. }
  151. BOOL CDlgDlg::OnEraseBkgnd(CDC*)
  152. {
  153. // don't bother erasing the background since our control will always
  154. // cover the entire client area
  155. return TRUE;
  156. }
  157. void CDlgDlg::OnItemChanged(NMHDR* pNotifyStruct, LRESULT* plResult)
  158. {
  159. LPNMPROPTREE pNMPropTree = (LPNMPROPTREE)pNotifyStruct;
  160. if (pNMPropTree->pItem)
  161. {
  162. CString s;
  163. s.Format(_T("Item '%s' has been changed\n"), pNMPropTree->pItem->GetLabelText());
  164. OutputDebugString(s);
  165. }
  166. *plResult = 0;
  167. }