📄 mytreectrl.cpp
字号:
// MyTreeCtrl.cpp : implementation file
//
#include "stdafx.h"
#include "DigitalMap.h"
#include "MainFrm.h "
#include "MyTreeCtrl.h"
#include "DigitalMapDoc.h"
#include "DigitalMapView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyTreeCtrl
CMyTreeCtrl::CMyTreeCtrl()
{
}
CMyTreeCtrl::~CMyTreeCtrl()
{
}
BEGIN_MESSAGE_MAP(CMyTreeCtrl, CTreeCtrl)
//{{AFX_MSG_MAP(CMyTreeCtrl)
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyTreeCtrl message handlers
void CMyTreeCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
point.x += 12;
HTREEITEM hItem =HitTest(point, &nFlags);
CMainFrame *pMainFrm=(CMainFrame *)AfxGetMainWnd();
CDigitalMapView *pView=(CDigitalMapView *)pMainFrm->GetActiveView();
CDigitalMapDoc *pDoc=(CDigitalMapDoc *)(pMainFrm->GetActiveDocument());
CDC *pDC=GetDC();
//
//进行的是与运算,对于 二进制数来说都为1的情况下结果为1
if ( (nFlags&TVHT_ONITEMLABEL ))
{
UINT nState = GetItemState( hItem, TVIS_STATEIMAGEMASK ) >> 12;
nState=(nState==2)?1:2;
HTREEITEM hItemParent=GetParentItem(hItem);
if(hItemParent)
{
CString m_Title=GetItemText(hItem);
//对当前层的图片状态取反
SetItemState( hItem, INDEXTOSTATEIMAGEMASK(nState), TVIS_STATEIMAGEMASK );
//根据当前层属性取出当前层的编号
CString strCode;
FromLyNameToCode(m_Title,strCode);
for(int i=0;i<pDoc->m_cGeoMap.m_vecLayers.size();i++)
{
CString strName;
pDoc->m_cGeoMap.m_vecLayers.at(i).GetLayerName(strName);
if(strCode==strName)
{
BOOL bDisplay = pDoc->m_cGeoMap.m_vecLayers.at(i).GetDisplay();
pDoc->m_cGeoMap.m_vecLayers.at(i).SetDisplay(!bDisplay);
pView->Invalidate(true);
}
}
}
}
CTreeCtrl::OnLButtonDown(nFlags, point);
}
void CMyTreeCtrl::FromLyNameToCode(CString strLayerName, CString &strCode)
{
//为图层代码与图层显示建立对照表
if(strLayerName=="独立地物符号")
{
strCode="P";
return;
}
if(strLayerName=="建筑物")
{
strCode="B";
return;
}
if(strLayerName=="道路")
{
strCode="R";
return;
}
if(strLayerName=="地貌")
{
strCode="T";
return;
}
if(strLayerName=="境界")
{
strCode="F";
return;
}
if(strLayerName=="绿化植被")
{
strCode="V";
return;
}
if(strLayerName=="水系")
{
strCode="H";
return;
}
if(strLayerName=="图幅控制网")
{
strCode="C";
return;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -