FolderListView.cpp
上传用户:szcysw
上传日期:2013-03-11
资源大小:6752k
文件大小:6k
- // FolderListView.cpp : implementation file
- //
- #include "stdafx.h"
- #include "TaxExpert.h"
- #include "FolderListView.h"
- #include "TaxExpertView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CFolderListView
- CCJTreeCtrl CFolderListView::m_TreeCtrl;
- IMPLEMENT_DYNCREATE(CFolderListView, CView)
- CFolderListView::CFolderListView()
- {
- // Create the image list used by frame buttons.
- m_ImageList.Create( IDB_PUSHPIN, 16, 1, RGB( 255, 0, 255 ));
- // Create the image list used by the tree control.
- m_ImageSmall.Create (16, 16, TRUE, 2, 1);
- for( int nIcon = IDI_ICON_OUTLOOK; nIcon <= IDI_ICON_PUBLIC; ++nIcon )
- //for( int nIcon = 131; nIcon <= 138; ++nIcon )
- {
- HICON hIcon = AfxGetApp()->LoadIcon(nIcon);
- ASSERT(hIcon);
- m_ImageSmall.Add(hIcon);
- }
- }
- CFolderListView::~CFolderListView()
- {
- }
- #define IDC_TREE_VIEW 1000
- BEGIN_MESSAGE_MAP(CFolderListView, CView)
- //{{AFX_MSG_MAP(CFolderListView)
- ON_WM_CREATE()
- ON_WM_SIZE()
- ON_BN_CLICKED(IDC_CAPT_BUTTON, OnCaptButton)
- ON_NOTIFY(TVN_SELCHANGED, IDC_TREE_VIEW, OnSelchanged)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CFolderListView drawing
- void CFolderListView::OnDraw(CDC* pDC)
- {
- CDocument* pDoc = GetDocument();
- // TODO: add draw code here
- }
- /////////////////////////////////////////////////////////////////////////////
- // CFolderListView diagnostics
- #ifdef _DEBUG
- void CFolderListView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CFolderListView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CFolderListView message handlers
- //初始化CFolderListView
- int CFolderListView::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- CString shortcut[6]={
- "税收政策",
- "税务征管",
- "财政法规",
- "涉税法规",
- "纳税辅导",
- "用户自定义"};
- CString tax[20]={
- "增值税",
- "消费税",
- "营业税",
- "企业所得税(内资)",
- "企业所得税(外资)",
- "个人所得税",
- "资源税",
- "城建税",
- "印花税",
- "车船使用税",
- "屠宰税",
- "城镇土地使用税",
- "房产税",
- "土地增值税",
- "农业税",
- "农业特产税",
- "契税",
- "车辆购置税",
- "车船牌照使用税",
- "固定资产投资方向调节税(停征)"
- };
- CString swgl[8]={
- "税收征收管理",
- "税务检查",
- "税务代理",
- "出口退税",
- "进出口税收",
- "涉外税收",
- "税收协定",
- "其他杂项",
- };
-
- if (CView::OnCreate(lpCreateStruct) == -1)
- return -1;
-
- // 建立标题
- if (!m_Caption.Create(this, _T("项目列表")))
- {
- TRACE0(_T("Unable to create caption.n"));
- return -1;
- }
- //建立按钮
- // Create the caption button.
- if (!m_CaptionButton.Create(NULL, WS_VISIBLE|BS_ICON|BS_OWNERDRAW|BS_CENTER|BS_VCENTER,
- CRect(0,0,0,0), this, IDC_CAPT_BUTTON))
- { TRACE0(_T("Unable to create caption button.n"));
- return -1;
- }
-
- m_CaptionButton.SetIcon( m_ImageList.ExtractIcon(2), CSize( 16, 15 ));
- //建立树
- if (!m_TreeCtrl.Create(WS_VISIBLE, CRect(0,0,0,0), this, IDC_TREE_VIEW))
- {
- TRACE0(_T("Unable to create tree control.n"));
- return -1;
- }
- m_TreeCtrl.SetImageList( &m_ImageSmall, TVSIL_NORMAL );
-
- //初始化树形控件:根节点
- for(int ii=0;ii<6;ii++)
- hti[ii]=m_TreeCtrl.InsertItem(shortcut[ii], 11, 11);
- //初始化树形控件:子节点1
- for (int i=0;i<20;i++)
- //6,5选中、未选中时的图标索引值
- m_TreeCtrl.InsertItem(tax[i],6, 5, hti[0]);
- //初始化树形控件:子节点2
- for (i=0;i<8;i++)
- m_TreeCtrl.InsertItem(swgl[i],6, 5, hti[1]);
-
- //展开子节点1
- m_TreeCtrl.Expand( hti[0], TVE_EXPAND );
- m_TreeCtrl.SelectItem( hti[0] );
- return 0;
- }
- void CFolderListView::OnSize(UINT nType, int cx, int cy)
- {
- CView::OnSize(nType, cx, cy);
-
- // TODO: Add your message handler code here
- if( m_Caption.GetSafeHwnd()) {
- m_Caption.MoveWindow( 0, 0, cx, 19 );
- }
- if( m_CaptionButton.GetSafeHwnd()) {
- m_CaptionButton.MoveWindow( cx-18, 2, 16, 15 );
- }
- if( m_TreeCtrl.GetSafeHwnd()) {
- m_TreeCtrl.MoveWindow( 0, 19, cx, cy-19 );
- }
- }
- void CFolderListView::OnCaptButton()
- {
- GetParent()->GetParent()->SendMessage( FM_CLOSEFOLDERLISTVIEW, 0, 0 );
- }
- #include "MainFrm.h"
- /*OnSelchanged:
- 树形视图的内容发生变化时的响应函数:
- 1、修改标题
- 2、进行分类查询
- */
- void CFolderListView::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult)
- {
- NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
- int nImage;
- HTREEITEM htItem = m_TreeCtrl.GetSelectedItem();
- m_TreeCtrl.GetItemImage( htItem, nImage, nImage );
-
- CTaxExpertDoc * pDOC=(CTaxExpertDoc *)this->GetDocument();
- CTaxExpertView* pView = DYNAMIC_DOWNCAST(CTaxExpertView, GetParent()->GetParent());
- ASSERT_KINDOF(CTaxExpertView, pView);
-
- HTREEITEM htItemnode=m_TreeCtrl.GetParentItem(htItem);
- CString caption;
- //如果选择的是根节点,不进其他行任何处理
- if(m_TreeCtrl.GetParentItem(htItem)==NULL)
- {
- caption=m_TreeCtrl.GetItemText( htItem );
- pView->current_sel_sub.Empty();
- pView->current_sel_main=m_TreeCtrl.GetItemText( htItem );
- }
- //将横标题改为 类名+详细描述
- else
- {
- caption=m_TreeCtrl.GetItemText(htItemnode)+
- "::"+m_TreeCtrl.GetItemText( htItem );
- pView->current_sel_sub=m_TreeCtrl.GetItemText( htItem );
- pView->current_sel_main=m_TreeCtrl.GetItemText(htItemnode);
- }
- caption.TrimLeft();
- caption.TrimRight();
- //修改标题栏:文字+图标
- pView->m_Caption.UpdateCaption(caption,
- m_ImageSmall.ExtractIcon(nImage));
- //设置标题栏背景
- pView->m_Caption.SetCaptionColors(RGB(111,207,78),
- RGB(111,207,78), RGB(255,255,255));
-
- if(m_TreeCtrl.GetParentItem(htItem)==NULL)
- {
- *pResult = 0;
- return;
- }
- *pResult = 0;
- CMainFrame* frm=(CMainFrame*)AfxGetMainWnd();
- //对选择的子项进行分在类查询
- CString strSelectItemText=m_TreeCtrl.GetItemText(htItem);
- ::SendMessage(frm->m_hWnd,WM_INTERACTIVE_WITH_FRAME,
- ID_FROM_FOLDERVIEW,(LPARAM)(LPCSTR)strSelectItemText);
- }