workbar.cpp
上传用户:netltd
上传日期:2013-02-12
资源大小:7234k
文件大小:5k
- // mybar.cpp : implementation file
- //
- #include "stdafx.h"
- #include "resource.h"
- #include "workbar.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- void CProjectTree::InsertProject(CString name)
- {
- HTREEITEM RootItem = InsertItem((LPCTSTR)name, ICON_PROJECT, ICON_PROJECT, TVI_ROOT, TVI_SORT);
- SetItemData(RootItem, TREE_PROJECT_ITEM);
- }
- HTREEITEM CProjectTree::InsertFile(CString name)
- {
- HTREEITEM RootItem;
- HTREEITEM fileitem;
- RootItem = GetRootItem();
- fileitem = InsertItem((LPCTSTR)name, ICON_FILE, ICON_FILE, RootItem);
- SetItemData(fileitem, TREE_FILE_ITEM);
- Expand(RootItem, TVE_EXPAND);
- return fileitem;
- }
- HTREEITEM CProjectTree::InsertLayer(HTREEITEM fileitem, CString name, UINT nIocn)
- {
- HTREEITEM RootItem;
- HTREEITEM layerItem;
- RootItem = GetRootItem();
- layerItem = InsertItem((LPCTSTR)name, nIocn, nIocn, fileitem);
- SetItemData(layerItem, TREE_LAYER_ITEM);
- Expand(RootItem, TVE_EXPAND);
- Expand(fileitem, TVE_EXPAND);
- return layerItem;
- }
- HTREEITEM CProjectTree::FindFileItem(CString filename)
- {
- HTREEITEM RootItem;
- HTREEITEM FileItem;
- RootItem = GetRootItem();
- FileItem = GetChildItem(RootItem);
- for(;;)
- {
- if(FileItem == NULL)
- break;
- CString name = GetItemText(FileItem);
- if(name == filename)
- return FileItem;
- FileItem = GetNextSiblingItem(FileItem);
- }
- return NULL;
- }
- HTREEITEM CProjectTree::FindLayerItem(HTREEITEM fileitem, CString layername)
- {
- HTREEITEM LayerItem;
- LayerItem = GetChildItem(fileitem);
- for(;;)
- {
- if(LayerItem == NULL)
- break;
- CString name = GetItemText(LayerItem);
- if(name == layername)
- return LayerItem;
- LayerItem = GetNextSiblingItem(LayerItem);
- }
- return NULL;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMyWorkBar
- CMyWorkBar::CMyWorkBar()
- {
- }
- CMyWorkBar::~CMyWorkBar()
- {
- }
- BEGIN_MESSAGE_MAP(CMyWorkBar, CSizingControlBar)
- //{{AFX_MSG_MAP(CMyWorkBar)
- ON_WM_CREATE()
- ON_WM_SIZE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMyWorkBar message handlers
- int CMyWorkBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CSizingControlBar::OnCreate(lpCreateStruct) == -1)
- return -1;
- if (!m_wndTab.Create(WS_CHILD | WS_VISIBLE, CRect(0,0,0,0), this, IDC_TAB))
- return -1;
- if (!m_wndTree.Create(WS_CHILD | WS_VISIBLE | TVS_LINESATROOT | TVS_HASLINES
- | TVS_HASBUTTONS | WS_BORDER | WS_TABSTOP | WS_VSCROLL,
- CRect(0,0,0,0), this, IDC_TREE))
- return -1;
- pTree = &m_wndTree;
- //设置3D外观
- m_wndTree.ModifyStyleEx(0, WS_EX_CLIENTEDGE);
- if (!m_wndList.Create(WS_CHILD | WS_VISIBLE | WS_BORDER | WS_EX_CLIENTEDGE,
- CRect(0,0,0,0), this, IDC_LIST))
- return -1;
- pList = &m_wndList;
- //设置3D外观的另一种方法
- SetWindowLong(m_wndList.GetSafeHwnd(), GWL_EXSTYLE, WS_EX_CLIENTEDGE);
- //设置字体
- if (!m_font.CreateStockObject(DEFAULT_GUI_FONT))
- return -1;
- m_wndTab.SetFont(&m_font);
- //初始化工作区
- m_wndTab.InsertItem(0, "项目");
- m_wndTab.InsertItem(1, "元件");
- //初始化树形框
- //给树形控件绑定图标
- CImageList m_TreeImageList;
- m_TreeImageList.Create(16, 16, ILC_MASK, 2, 2);
- m_TreeImageList.Add(AfxGetApp()->LoadIcon(IDI_PROJECT));
- m_TreeImageList.Add(AfxGetApp()->LoadIcon(IDI_FILE));
- m_TreeImageList.Add(AfxGetApp()->LoadIcon(IDI_LAYER));
- m_TreeImageList.Add(AfxGetApp()->LoadIcon(IDI_CURRENTLAYER));
- m_TreeImageList.Add(AfxGetApp()->LoadIcon(IDI_LOCKLAYER));
- m_TreeImageList.Add(AfxGetApp()->LoadIcon(IDI_CURRENTLOCKLAYER));
- m_TreeImageList.Add(AfxGetApp()->LoadIcon(IDI_HIDELAYER));
- m_TreeImageList.Add(AfxGetApp()->LoadIcon(IDI_CURRENTHIDELAYER));
- m_TreeImageList.Add(AfxGetApp()->LoadIcon(IDI_LOCKHIDELAYER));
- m_TreeImageList.Add(AfxGetApp()->LoadIcon(IDI_CURRENTLOCKHIDELAYER));
- m_wndTree.SetImageList(&m_TreeImageList, TVSIL_NORMAL);
- m_TreeImageList.Detach();
- m_wndTree.ShowWindow(FALSE);
-
- //初始化列表框
- CImageList m_ListImageList;
- m_ListImageList.Create(32, 32, ILC_MASK, 2, 2);
- m_ListImageList.Add(AfxGetApp()->LoadIcon(IDI_FILE));
- m_ListImageList.Add(AfxGetApp()->LoadIcon(IDI_FILE));
- m_wndList.SetImageList(&m_ListImageList, TVSIL_NORMAL);
- m_ListImageList.Detach();
- m_wndList.ShowWindow(FALSE);
- return 0;
- }
- void CMyWorkBar::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler)
- {
- UpdateDialogControls(pTarget, bDisableIfNoHndler);
- }
- void CMyWorkBar::OnSize(UINT nType, int cx, int cy)
- {
- CSizingControlBar::OnSize(nType, cx, cy);
-
- CRect rc;
- GetClientRect(rc);
- rc.DeflateRect(4, 4);
- m_wndTab.MoveWindow(rc);
- rc.left += 5;
- rc.top += 30;
- rc.right -= 5;
- rc.bottom -= 10;
- m_wndTree.MoveWindow(rc);
- m_wndList.MoveWindow(rc);
- }
- /////////////////////////////////////////////////////////////////////////////