FolderListView.cpp
上传用户:szcysw
上传日期:2013-03-11
资源大小:6752k
文件大小:6k
源码类别:

界面编程

开发平台:

Visual C++

  1. // FolderListView.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "TaxExpert.h"
  5. #include "FolderListView.h"
  6. #include "TaxExpertView.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CFolderListView
  14. CCJTreeCtrl CFolderListView::m_TreeCtrl;
  15. IMPLEMENT_DYNCREATE(CFolderListView, CView)
  16. CFolderListView::CFolderListView()
  17. {
  18. // Create the image list used by frame buttons.
  19. m_ImageList.Create( IDB_PUSHPIN, 16, 1, RGB( 255, 0, 255 ));
  20. // Create the image list used by the tree control.
  21. m_ImageSmall.Create (16, 16, TRUE, 2, 1);
  22. for( int nIcon = IDI_ICON_OUTLOOK; nIcon <= IDI_ICON_PUBLIC; ++nIcon ) 
  23. //for( int nIcon = 131; nIcon <= 138; ++nIcon ) 
  24. {
  25. HICON hIcon = AfxGetApp()->LoadIcon(nIcon);
  26. ASSERT(hIcon);
  27. m_ImageSmall.Add(hIcon);
  28. }
  29. }
  30. CFolderListView::~CFolderListView()
  31. {
  32. }
  33. #define IDC_TREE_VIEW 1000
  34. BEGIN_MESSAGE_MAP(CFolderListView, CView)
  35. //{{AFX_MSG_MAP(CFolderListView)
  36. ON_WM_CREATE()
  37. ON_WM_SIZE()
  38. ON_BN_CLICKED(IDC_CAPT_BUTTON, OnCaptButton)
  39. ON_NOTIFY(TVN_SELCHANGED, IDC_TREE_VIEW, OnSelchanged)
  40. //}}AFX_MSG_MAP
  41. END_MESSAGE_MAP()
  42. /////////////////////////////////////////////////////////////////////////////
  43. // CFolderListView drawing
  44. void CFolderListView::OnDraw(CDC* pDC)
  45. {
  46. CDocument* pDoc = GetDocument();
  47. // TODO: add draw code here
  48. }
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CFolderListView diagnostics
  51. #ifdef _DEBUG
  52. void CFolderListView::AssertValid() const
  53. {
  54. CView::AssertValid();
  55. }
  56. void CFolderListView::Dump(CDumpContext& dc) const
  57. {
  58. CView::Dump(dc);
  59. }
  60. #endif //_DEBUG
  61. /////////////////////////////////////////////////////////////////////////////
  62. // CFolderListView message handlers
  63. //初始化CFolderListView
  64. int CFolderListView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  65. {
  66. CString shortcut[6]={
  67. "税收政策",
  68. "税务征管",
  69. "财政法规",
  70. "涉税法规",
  71. "纳税辅导",
  72. "用户自定义"};
  73. CString tax[20]={
  74. "增值税",
  75. "消费税",
  76. "营业税",
  77. "企业所得税(内资)",
  78. "企业所得税(外资)",
  79. "个人所得税",
  80. "资源税",
  81. "城建税",
  82. "印花税",
  83. "车船使用税",
  84. "屠宰税",
  85. "城镇土地使用税",
  86. "房产税",
  87. "土地增值税",
  88. "农业税",
  89. "农业特产税",
  90. "契税",
  91. "车辆购置税",
  92. "车船牌照使用税",
  93. "固定资产投资方向调节税(停征)"
  94. };
  95. CString swgl[8]={
  96. "税收征收管理",
  97. "税务检查",
  98. "税务代理",
  99. "出口退税",
  100. "进出口税收",
  101. "涉外税收",
  102. "税收协定",
  103. "其他杂项",
  104. };
  105. if (CView::OnCreate(lpCreateStruct) == -1)
  106. return -1;
  107. // 建立标题
  108. if (!m_Caption.Create(this, _T("项目列表")))
  109. {
  110. TRACE0(_T("Unable to create caption.n"));
  111. return -1;
  112. }
  113. //建立按钮
  114. // Create the caption button.
  115. if (!m_CaptionButton.Create(NULL, WS_VISIBLE|BS_ICON|BS_OWNERDRAW|BS_CENTER|BS_VCENTER,
  116. CRect(0,0,0,0), this, IDC_CAPT_BUTTON))
  117. { TRACE0(_T("Unable to create caption button.n"));
  118. return -1;
  119. }
  120. m_CaptionButton.SetIcon( m_ImageList.ExtractIcon(2), CSize( 16, 15 ));
  121. //建立树
  122. if (!m_TreeCtrl.Create(WS_VISIBLE, CRect(0,0,0,0), this, IDC_TREE_VIEW))
  123. {
  124. TRACE0(_T("Unable to create tree control.n"));
  125. return -1;
  126. }
  127. m_TreeCtrl.SetImageList( &m_ImageSmall, TVSIL_NORMAL );
  128. //初始化树形控件:根节点
  129. for(int ii=0;ii<6;ii++)
  130. hti[ii]=m_TreeCtrl.InsertItem(shortcut[ii], 11, 11);
  131. //初始化树形控件:子节点1
  132. for (int i=0;i<20;i++)
  133. //6,5选中、未选中时的图标索引值
  134. m_TreeCtrl.InsertItem(tax[i],6,  5, hti[0]);
  135. //初始化树形控件:子节点2
  136. for (i=0;i<8;i++)
  137. m_TreeCtrl.InsertItem(swgl[i],6,  5, hti[1]);
  138. //展开子节点1
  139. m_TreeCtrl.Expand( hti[0], TVE_EXPAND );
  140. m_TreeCtrl.SelectItem( hti[0] );
  141. return 0;
  142. }
  143. void CFolderListView::OnSize(UINT nType, int cx, int cy) 
  144. {
  145. CView::OnSize(nType, cx, cy);
  146. // TODO: Add your message handler code here
  147. if( m_Caption.GetSafeHwnd()) {
  148. m_Caption.MoveWindow( 0, 0, cx, 19 );
  149. }
  150. if( m_CaptionButton.GetSafeHwnd()) {
  151. m_CaptionButton.MoveWindow( cx-18, 2, 16, 15 );
  152. }
  153. if( m_TreeCtrl.GetSafeHwnd()) {
  154. m_TreeCtrl.MoveWindow( 0, 19, cx, cy-19 );
  155. }
  156. }
  157. void CFolderListView::OnCaptButton()
  158. {
  159. GetParent()->GetParent()->SendMessage( FM_CLOSEFOLDERLISTVIEW, 0, 0 );
  160. }
  161. #include "MainFrm.h"
  162. /*OnSelchanged:
  163. 树形视图的内容发生变化时的响应函数:
  164. 1、修改标题
  165. 2、进行分类查询
  166. */
  167. void CFolderListView::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult) 
  168. {
  169. NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
  170. int nImage;
  171. HTREEITEM htItem = m_TreeCtrl.GetSelectedItem();
  172. m_TreeCtrl.GetItemImage( htItem, nImage, nImage );
  173. CTaxExpertDoc * pDOC=(CTaxExpertDoc *)this->GetDocument();
  174. CTaxExpertView* pView = DYNAMIC_DOWNCAST(CTaxExpertView, GetParent()->GetParent());
  175. ASSERT_KINDOF(CTaxExpertView, pView);
  176. HTREEITEM htItemnode=m_TreeCtrl.GetParentItem(htItem);
  177. CString caption;
  178. //如果选择的是根节点,不进其他行任何处理
  179. if(m_TreeCtrl.GetParentItem(htItem)==NULL)
  180. {
  181. caption=m_TreeCtrl.GetItemText( htItem );
  182. pView->current_sel_sub.Empty();
  183. pView->current_sel_main=m_TreeCtrl.GetItemText( htItem );
  184. }
  185. //将横标题改为 类名+详细描述
  186. else
  187. {
  188. caption=m_TreeCtrl.GetItemText(htItemnode)+
  189. "::"+m_TreeCtrl.GetItemText( htItem );
  190. pView->current_sel_sub=m_TreeCtrl.GetItemText( htItem );
  191. pView->current_sel_main=m_TreeCtrl.GetItemText(htItemnode);
  192. }
  193. caption.TrimLeft();
  194. caption.TrimRight();
  195. //修改标题栏:文字+图标
  196. pView->m_Caption.UpdateCaption(caption,
  197. m_ImageSmall.ExtractIcon(nImage));
  198. //设置标题栏背景
  199. pView->m_Caption.SetCaptionColors(RGB(111,207,78),
  200. RGB(111,207,78), RGB(255,255,255));
  201. if(m_TreeCtrl.GetParentItem(htItem)==NULL)
  202. {
  203. *pResult = 0;
  204. return;
  205. }
  206. *pResult = 0;
  207. CMainFrame* frm=(CMainFrame*)AfxGetMainWnd();
  208. //对选择的子项进行分在类查询
  209. CString strSelectItemText=m_TreeCtrl.GetItemText(htItem);
  210. ::SendMessage(frm->m_hWnd,WM_INTERACTIVE_WITH_FRAME,
  211. ID_FROM_FOLDERVIEW,(LPARAM)(LPCSTR)strSelectItemText);
  212. }