2,142
社区成员
发帖
与我相关
我的任务
分享
void CHomeworkDlg::OnToolUsedMap1(short ToolNum, double X1, double Y1, double X2, double Y2, double Distance, BOOL Shift, BOOL Ctrl, BOOL FAR* EnableDefault)
{
CCMapXPoint point;
COleVariant empty;
empty.vt = VT_ERROR;
empty.scode = DISP_E_PARAMNOTFOUND;
point.Set(X1,Y1);
features = myLayer.SearchAtPoint(point, empty);
}
void CMetCenView::OnToolUsedMap1(short ToolNum, double X1, double Y1, double X2, double Y2, double Distance, BOOL Shift, BOOL Ctrl, BOOL FAR* EnableDefault)
{
CMapXPoint point;
point.CreateDispatch(point.GetClsid()); //忘记这句就会出现你的那个错误
point.Set(X1,Y1);
//-----------------------------------------------------//因为我的工程没有全局变量 所以这里重新去获得了一下图层
CMapXLayers layers;
layers = m_CtrMap.GetLayers();
int m = layers.GetCount();
//------------------------------------------------------
CMapXLayer m_traceLayer;
m_traceLayer =layers.Item(3); //随便选择了一个图层
m_traceLayer.SetSelectable( TRUE ); //这句加不加是不是也会造成一些问题呢? 如果图层不可选,估计什么都选不到吧
CMapXFeatures features = m_traceLayer.SearchAtPoint( point, miSearchResultAll);
int k = features.GetCount(); //我在我的工程里面试验了,随便点了一个地方 显示1 说明有Feature被选中了。
}
//In cases where you are creating a MapX subordinate object yourself, you need to cause it to create its own
//internal IDispatch *. That is done by calling CreateDispatch on the object and passing the class ID from the Windows
//Registry. This is made easier by the provision in most MapX subordinate object classes of a function called Classid().
//So use the following form: CMapXFeature NewFeature; NewFeature.CreateDispatch(NewFeature.Classid());
//Failure to do this will cause your program to experience an Access Violation the moment you try to do anything to the object.
CCMapXPoint point;
COleVariant searchType;
searchType.vt = VT_I4;
searchType.lVal = miSearchResultRegion;
point.Set(X1,Y1);
features = myLayer.SearchAtPoint(point, searchType);