使用CTOCControl控件

本文介绍了一个用于 ArcGIS 的 Table Of Contents (TOC) 控件的定制功能实现,包括开始和结束标签编辑、鼠标点击事件处理等。通过这些功能可以实现对地图图层名称的编辑和交互。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这个控件不太好用,只能使用这点功能了:

void CTocDlg::OnOnBeginLabelEditToccontrol1(long x, long y, BOOL FAR* CanEdit)

{  //

   esriTOCControlItem item = esriTOCControlItemNone;

    IBasicMapPtr ipBasicMap = 0;  

ILayerPtr ipLayer = 0;  

 IUnknownPtr ipUnk = 0;  

 CComVariant data = 0;

  // Determine what kind of item has been clicked on  

LPUNKNOWN pUnk = m_TOCControl.GetControlUnknown();  

   LPDISPATCH pDisp = 0;  

pUnk->QueryInterface(IID_IDispatch, (void **) &m_ipTOCControl);   

 m_ipTOCControl->HitTest(x, y, &item, &ipBasicMap, &ipLayer, &ipUnk, &data);

  //Only layer items can have their labels edited  

 if (item != esriTOCControlItemLayer)   

  *CanEdit = VARIANT_FALSE;

} ////////////////////////////////////////////////// //

void CTocDlg::OnOnEndLabelEditToccontrol1(long x, long y, LPCTSTR newLabel, BOOL FAR* CanEdit)

{  //  

CComBSTR bstr(newLabel);  

if (SysStringLen(bstr.m_str) == 0)    

 *CanEdit = VARIANT_FALSE;

} ///////////////////////////////////////////////////// //

void CTocDlg::OnOnMouseDownToccontrol1(long button, long shift, long x, long y)

{  

esriTOCControlItem item = esriTOCControlItemNone;

 IBasicMapPtr ipBasicMap = 0;  

ILayerPtr ipLayer = 0;

 IUnknownPtr ipUnk = 0;  

CComVariant data = 0;

 LPUNKNOWN pUnk = m_TOCControl.GetControlUnknown();   

  LPDISPATCH pDisp = 0;  

pUnk->QueryInterface(IID_IDispatch, (void **) &m_ipTOCControl);   

 m_ipTOCControl->HitTest(x, y, &item, &ipBasicMap, &ipLayer, &ipUnk, &data);

 switch(button)

 {  

case 2:  

 {  

  if (item == esriTOCControlItemMap)    

 MessageBox("New GroupLayer!");   

 if(item == esriTOCControlItemLayer)    

 MessageBox("New Element Layer!");  

 }   

break;  

case 1:  

default:   

break;

 };  

}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值