MyAssistantView.cpp
上传用户:shcaka8
上传日期:2013-04-06
资源大小:103k
文件大小:7k
源码类别:

家庭/个人应用

开发平台:

Visual C++

  1. // MyAssistantView.cpp : implementation of the CMyAssistantView class
  2. //
  3. #include "stdafx.h"
  4. #include "MyAssistant.h"
  5. #include "MyAssistantDoc.h"
  6. #include "MyAssistantView.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CMyAssistantView
  14. IMPLEMENT_DYNCREATE(CMyAssistantView, CFormView)
  15. BEGIN_MESSAGE_MAP(CMyAssistantView, CFormView)
  16. //{{AFX_MSG_MAP(CMyAssistantView)
  17. // NOTE - the ClassWizard will add and remove mapping macros here.
  18. //    DO NOT EDIT what you see in these blocks of generated code!
  19. ON_BN_CLICKED(IDC_DSP_MONEY, OnDspMoney)
  20. ON_BN_CLICKED(IDC_DSP_ADDRLIST, OnDspAddrList)
  21. //}}AFX_MSG_MAP
  22. // Standard printing commands
  23. ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
  24. ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
  25. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
  26. END_MESSAGE_MAP()
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CMyAssistantView construction/destruction
  29. CMyAssistantView::CMyAssistantView()
  30. : CFormView(CMyAssistantView::IDD)
  31. {
  32. //{{AFX_DATA_INIT(CMyAssistantView)
  33. // NOTE: the ClassWizard will add member initialization here
  34. //}}AFX_DATA_INIT
  35. // TODO: add construction code here
  36. m_Leaf = 0;
  37. }
  38. CMyAssistantView::~CMyAssistantView()
  39. {
  40. }
  41. void CMyAssistantView::DoDataExchange(CDataExchange* pDX)
  42. {
  43. CFormView::DoDataExchange(pDX);
  44. //{{AFX_DATA_MAP(CMyAssistantView)
  45. // NOTE: the ClassWizard will add DDX and DDV calls here
  46. //}}AFX_DATA_MAP
  47. }
  48. BOOL CMyAssistantView::PreCreateWindow(CREATESTRUCT& cs)
  49. {
  50. // TODO: Modify the Window class or styles here by modifying
  51. //  the CREATESTRUCT cs
  52. return CFormView::PreCreateWindow(cs);
  53. }
  54. void CMyAssistantView::OnInitialUpdate()
  55. {
  56. CFormView::OnInitialUpdate();
  57. GetParentFrame()->RecalcLayout();
  58. ResizeParentToFit();
  59. CRect rect(0,0,800,600); //调整主窗口大小
  60. MoveWindow(&rect,TRUE );
  61. rect.CopyRect(new CRect(30,20,800-30,600-50));
  62. m_PropertySheet.m_Rect = rect;
  63. m_PropertySheet.m_nPages = -1; // init this membervariable
  64. m_PropertySheet.m_nActPage =  0; // init this membervariable
  65. //创建属性页
  66. m_PropertySheet.Create (WS_VISIBLE | WS_CHILD | WS_TABSTOP,
  67. m_PropertySheet.m_Rect, this, m_PropertySheet.m_nCtrlID);
  68. InitPropertySheet(0);
  69. }
  70. /////////////////////////////////////////////////////////////////////////////
  71. // CMyAssistantView printing
  72. BOOL CMyAssistantView::OnPreparePrinting(CPrintInfo* pInfo)
  73. {
  74. // default preparation
  75. return DoPreparePrinting(pInfo);
  76. }
  77. void CMyAssistantView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  78. {
  79. // TODO: add extra initialization before printing
  80. }
  81. void CMyAssistantView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  82. {
  83. // TODO: add cleanup after printing
  84. }
  85. void CMyAssistantView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
  86. {
  87. // TODO: add customized printing code here
  88. }
  89. /////////////////////////////////////////////////////////////////////////////
  90. // CMyAssistantView diagnostics
  91. #ifdef _DEBUG
  92. void CMyAssistantView::AssertValid() const
  93. {
  94. CFormView::AssertValid();
  95. }
  96. void CMyAssistantView::Dump(CDumpContext& dc) const
  97. {
  98. CFormView::Dump(dc);
  99. }
  100. CMyAssistantDoc* CMyAssistantView::GetDocument() // non-debug version is inline
  101. {
  102. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyAssistantDoc)));
  103. return (CMyAssistantDoc*)m_pDocument;
  104. }
  105. #endif //_DEBUG
  106. /////////////////////////////////////////////////////////////////////////////
  107. // CMyAssistantView message handlers
  108. void CMyAssistantView::InitPropertySheet(UINT flag)
  109. {
  110. m_PropertySheet.DeleteAllItems();
  111. //添加属性页
  112. CPropertyPages * pPropPage = NULL;
  113. TC_ITEM Item;
  114. Item.mask = TCIF_TEXT;
  115. if(flag == 0)
  116. {
  117. int nN;
  118. int nPages = 3; // in my example I have two pages
  119. for (nN = 0; nN < nPages; nN++) {
  120. pPropPage = new (CPropertyPages); // new it
  121. // Create the tab and the dialog
  122. switch (nN) 
  123. {
  124. case 0:
  125. Item.pszText = "编辑";
  126. pPropPage->m_pDialogPage = (CDialog*)&m_MoneyDlg;
  127. pPropPage->m_pDialogPage->
  128. Create(IDD_MONEY_EDIT, &m_PropertySheet);
  129. break;
  130. case 1:
  131. Item.pszText = "查看";
  132. pPropPage->m_pDialogPage = (CDialog*)&m_MoneyViewDlg;
  133. pPropPage->m_pDialogPage->
  134. Create(IDD_MONEY_VIEW, &m_PropertySheet);
  135. break;
  136. case 2:
  137. Item.pszText = "图解";
  138. pPropPage->m_pDialogPage = (CDialog*)&m_MoneyChart;
  139. pPropPage->m_pDialogPage->
  140. Create(IDD_MONEY_CHART, &m_PropertySheet);
  141. break;
  142. }
  143. m_PropertySheet.InsertItem (nN,&Item);
  144. m_PropertySheet.m_Dialogs.Add(pPropPage);
  145. m_PropertySheet.m_nPages++;
  146. pPropPage->m_Rect.top =
  147. m_PropertySheet.m_Rect.top  + 15;
  148. pPropPage->m_Rect.left =
  149. m_PropertySheet.m_Rect.left + 10;
  150. pPropPage->m_Rect.bottom =
  151. m_PropertySheet.m_Rect.bottom - m_PropertySheet.m_Rect.top  - 10;
  152. pPropPage->m_Rect.right =
  153. m_PropertySheet.m_Rect.right  - m_PropertySheet.m_Rect.left - 10;
  154. pPropPage->m_pDialogPage->SetWindowPos(NULL, pPropPage->m_Rect.left,
  155. pPropPage->m_Rect.top, 0, 0,
  156. SWP_HIDEWINDOW | SWP_NOSIZE);
  157. } //
  158. m_MoneyDlg.SetWindowPos(NULL, pPropPage->m_Rect.left,
  159. pPropPage->m_Rect.top, 0, 0,
  160. SWP_SHOWWINDOW | SWP_NOSIZE);
  161. }
  162. else if(flag == 1)
  163. {
  164. int nN;
  165. int nPages = 1; // in my example I have two pages
  166. for (nN = 0; nN < nPages; nN++) {
  167. pPropPage = new (CPropertyPages); // new it
  168. // Create the tab and the dialog
  169. switch (nN) 
  170. {
  171. case 0:
  172. Item.pszText = "地址";
  173. pPropPage->m_pDialogPage = (CDialog*)&m_AddrListDlg;
  174. pPropPage->m_pDialogPage->
  175. Create(IDD_ADDR_EDITLIST, &m_PropertySheet);
  176. break;
  177. }
  178. m_PropertySheet.InsertItem (nN,&Item);
  179. m_PropertySheet.m_Dialogs.Add(pPropPage);
  180. m_PropertySheet.m_nPages++;
  181. pPropPage->m_Rect.top =
  182. m_PropertySheet.m_Rect.top  + 15;
  183. pPropPage->m_Rect.left =
  184. m_PropertySheet.m_Rect.left + 10;
  185. pPropPage->m_Rect.bottom =
  186. m_PropertySheet.m_Rect.bottom - m_PropertySheet.m_Rect.top  - 10;
  187. pPropPage->m_Rect.right =
  188. m_PropertySheet.m_Rect.right  - m_PropertySheet.m_Rect.left - 10;
  189. pPropPage->m_pDialogPage->SetWindowPos(NULL, pPropPage->m_Rect.left,
  190. pPropPage->m_Rect.top, 0, 0,
  191. SWP_HIDEWINDOW | SWP_NOSIZE);
  192. } //
  193. pPropPage->m_pDialogPage->SetWindowPos(NULL, pPropPage->m_Rect.left,
  194. pPropPage->m_Rect.top, 0, 0,
  195. SWP_SHOWWINDOW | SWP_NOSIZE);
  196. }
  197. }
  198. void CMyAssistantView::OnDspMoney() 
  199. {
  200. if(m_Leaf != 0) {
  201. m_AddrListDlg.DestroyWindow();
  202. InitPropertySheet(0);
  203. m_Leaf = 0;
  204. }
  205. }
  206. void CMyAssistantView::OnDspAddrList() 
  207. {
  208. if(m_Leaf != 2) {
  209. m_MoneyDlg.DestroyWindow();
  210. m_MoneyViewDlg.DestroyWindow();
  211. m_MoneyChart.DestroyWindow();
  212. InitPropertySheet(1);
  213. m_Leaf = 2;
  214. }
  215. }