mapx toolused 事件代码例子

/*
MapInfo Products Knowledge Base
Product: MapX
Version: 2.0
Platform: Window 95/Windows NT
Category: C++
Summary:
A ToolUsed handler for C++ that changes the style of a feature.
Question:
A ToolUsed handler for C++.
Answer:
Below is a ToolUsed handler for C++ that: changes the style of an existing feature; and adds new Symbol features to the layer.
*/

void  CMapxSampleView::OnToolUsed( short  ToolNum,  double  X1, double  Y1,  double  X2,  double  Y2,  double  Distance,
BOOL Shift, BOOL Ctrl, BOOL
*  EnableDefault)
{
CString str;
CMapXPoint pnt;

str.Format(
"Tool=%d, [%f,%f] [%f, %f], dist=%f, %s %s ",ToolNum, X1,Y1,X2,Y2,Distance, (Shift)?"Shift":"",(Ctrl)?"Ctrl":"");
TRACE(str);
// change the style of the feature under the cursor
if (ToolNum == MAP_TOOL_CHANGESTYLE) {
try 
{
// Need the dispatch to use the point
if (pnt.CreateDispatch(pnt.GetClsid())) 
{
pnt.Set(X1, Y1);
}

else 
{
// something went wrong, can't use the point...
AfxThrowOleException(CO_E_CLASS_CREATE_FAILED);
}


CMapXLayers layers 
= m_ctrlMapX.GetLayers();
// Get the USA Layer features under the cursor
CMapXFeatures ftrs = layers.Item("USA").SearchAtPoint(LPDISPATCH(pnt));
// work on only the first feature
CMapXFeature ftr = ftrs.Item(1);
// get the style object from the feature
CMapXStyle style = ftr.GetStyle();

style.SetRegionBackColor(
255);
// update the feature in the layer
ftr.Update();
}

catch (COleDispatchException *e) 
{
e
->ReportError();
e
->Delete();
}

catch (COleException *e) 
{
e
->ReportError();
e
->Delete();
}

}

// place a new symbol at the point clicked on
else if (ToolNum == MAP_TOOL_NEWPOINT) 
{
try 
{
CMapXLayers layers 
= m_ctrlMapX.GetLayers();
CMapXFeature ftr;
// Need the dispatch id to use the feature
if (ftr.CreateDispatch(ftr.GetClsid())) 
{
// Symbol feature
ftr.SetType(miFeatureTypeSymbol);
// Get the point object from the feature and call the Set method
ftr.GetPoint().Set(X1, Y1);
// Add it to the layer
layers.Item("USA").AddFeature(ftr);
}

else 
{
AfxThrowOleException(CO_E_CLASS_CREATE_FAILED);
}

}

catch (COleDispatchException *e) 
{
e
->ReportError();
e
->Delete();
}

catch (COleException *e) 
{
e
->ReportError();
e
->Delete();
}

}

}


// Last Modified: 2001-06-04 12:56:31
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值