【转】在VC++中用AE做鹰眼

转自:http://hi.baidu.com/giswoduxing/blog/item/12a6f388a2fb38b90e244445.html

 

一,新建一个单文档工程命名为:鹰眼.在向导最后,改View类为CFromView.

二,向工程中导入库,参见上文“AO二次开发导入库文件\"

三,向工程中添加一个Toolbar控件,一个TOCControl控件,二个MapControl控件.分别命名

为:m_ToolBar,m_TOCControl,m_MapControl1,m_Control2。再添加二个View类的全局变量:IMapPtr

m_Map1;IMapPtr m_Map2 。向CMOnInitialUpdate函数中添加代码如下:

void CMyView::OnInitialUpdate()

{

CFormView::OnInitialUpdate();

GetParentFrame()->RecalcLayout();

ResizeParentToFit();

CRect windowrect;

GetWindowRect(windowrect);

//设定三个控件的位置

if(m_ToolBar)

   m_ToolBar.SetWindowPos(this,5,0,windowrect.Width(),20,SWP_NOZORDER);

if(m_TOCControl)

   m_TOCControl.SetWindowPos(this,5,25,(windowrect.Width()-15)/5,

   (windowrect.Height()-35)*3/5,SWP_NOZORDER);

if(m_MapControl1)

   m_MapControl1.SetWindowPos(this,(windowrect.Width()-15)/5+10,25,

   (windowrect.Width()-15)*4/5,windowrect.Height()-35,SWP_NOZORDER);

if(m_MapControl2)

   m_MapControl2.SetWindowPos(this,5,(windowrect.Height()-35)*3/5+30,

   (windowrect.Width()-15)/5,(windowrect.Height()-35)*2/5,SWP_NOZORDER);

//设置伙伴关系

LPUNKNOWN lpUK=m_MapControl1.GetControlUnknown();

LPDISPATCH lpDis=0;

lpUK->QueryInterface(IID_IDispatch,(void**)&lpDis);

m_ToolBar.SetBuddyControl(lpDis);

m_TOCControl.SetBuddyControl(lpDis);

m_Map1=m_MapControl1.GetMap();

m_Map2=m_MapControl2.GetMap();

long i,layercount;

ILayerPtr layer;

m_Map1->get_LayerCount(&layercount);

for(i=0;i<layercount;i++)

{

   m_Map1->get_Layer(i,&layer);

   m_Map2->AddLayer(layer);

}

}

向View类添加WM_SIZE消息响应事件,代码如下:

void CMyView::OnSize(UINT nType, int cx, int cy)

{

CFormView::OnSize(nType, cx, cy);

// TODO: Add your message handler code here

CRect windowrect;

GetWindowRect(windowrect);

if(m_ToolBar)

   m_ToolBar.SetWindowPos(this,5,0,windowrect.Width(),20,SWP_NOZORDER);

if(m_TOCControl)

   m_TOCControl.SetWindowPos(this,5,25,(windowrect.Width()-15)/5,

   (windowrect.Height()-35)*3/5,SWP_NOZORDER);

if(m_MapControl1)

   m_MapControl1.SetWindowPos(this,(windowrect.Width()-15)/5+10,25,

   (windowrect.Width()-15)*4/5,windowrect.Height()-35,SWP_NOZORDER);

if(m_MapControl2)

   m_MapControl2.SetWindowPos(this,5,(windowrect.Height()-35)*3/5+30,

   (windowrect.Width()-15)/5,(windowrect.Height()-35)*2/5,SWP_NOZORDER);

}

四,为MapControl1控件添加OnAfterScreenDraw事件响应函数,代码如下:

void CMyView::OnOnAfterScreenDrawMapcontrol1(long hdc)

{

// TODO: Add your control notification handler code here

IActiveViewPtr ipActive(m_Map2);

IGraphicsContainerPtr ipGraphics(ipActive);

//清除MapControl2的Element

ipGraphics->DeleteAllElements();

//给MapControl2添加与MapControl1相同的图层

m_MapControl2.ClearLayers();

long i,layercount;

ILayerPtr layer;

m_Map1->get_LayerCount(&layercount);

for(i=0;i<layercount;i++)

{

   m_Map1->get_Layer(i,&layer);

   m_Map2->AddLayer(layer);

}

//设置在MapControl2中显示的范围框

IRgbColorPtr ipRgb(CLSID_RgbColor);

ipRgb->put_Blue(0);

ipRgb->put_Green(0);

ipRgb->put_Red(255);

IColorPtr ipColor(ipRgb);

IEnvelopePtr ipEnvelope;

ipEnvelope=m_MapControl1.GetExtent();

ISimpleLineSymbolPtr ipSimpleLineSymbol(CLSID_SimpleLineSymbol);

ipSimpleLineSymbol->put_Color(ipColor);

ipSimpleLineSymbol->put_Width(1);

ipSimpleLineSymbol->put_Style(esriSLSSolid);

ILineSymbolPtr ipLineSymbol(ipSimpleLineSymbol);

ISimpleFillSymbolPtr ipSimpleFillSymbol(CLSID_SimpleFillSymbol);

ipColor->put_Transparency(0);

ipSimpleFillSymbol->put_Color(ipColor);

ipSimpleFillSymbol->put_Outline(ipLineSymbol);

IRectangleElementPtr ipRectangleElement(CLSID_RectangleElement);

IGeometryPtr ipGeometry(ipEnvelope);

IFillSymbolPtr ipFillSymbol(ipSimpleFillSymbol);

IFillShapeElementPtr ipFillShape(ipRectangleElement);

ipFillShape->put_Symbol(ipFillSymbol);

IElementPtr ipElement(ipFillShape);

ipElement->put_Geometry(ipGeometry);

ipGraphics->AddElement(ipElement,0);

}

五,为MapControl2添加OnMouseDown事件响应函数,代码如下:

void CMyView::OnOnMouseDownMapcontrol2(long button, long shift, long X, long Y, double mapX, double

mapY)

{

// TODO: Add your control notification handler code here

IEnvelopePtr ipEnvelope(CLSID_Envelope);

ipEnvelope=m_MapControl1.GetExtent();

IPointPtr ipPoint(CLSID_Point);

ipPoint->PutCoords(mapX,mapY);

ipEnvelope->CenterAt(ipPoint);

m_MapControl1.SetExtent(ipEnvelope);//此时为激活OnOnAfterScreenDrawMapcontrol1函数

}

到此鹰眼便做好了.不足之处,还请大家赐教!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值