VC++环境下Mapx地图的加载

加载显示电子地图

         2.1.给单文档工程IntTranspSystem加入MapX控件。在MapX安装目录中找到Samples40子目录,在这个目录中有两个子目录CPP和VBAsia,分别是用VC++和VB开发的基于MapX控件的应用工程。在CPP目录中可以找到两个文件,MapX.h和MapX.cpp。这两个文件实际就是MapX控件的类层次定义文件(MapX.h)和COM借口实现文件(MapX.cpp)。将这两个文件拷贝到将要开发的项目文件夹中,并将其添加到工程中。

         2.1.在CintTranspSystemView类定义的前面加入#include"mapx.h",在CintTranspSystemView中定义两个共有类型成员变量CMapX m_CtrlMapX和BOOL b_MapData。

         2.2.在WorkSpace的资源页面中选中,选中intTranspSystemresource项,单击鼠标右键。在下拉菜单中选中“ID=资源符号…”,增加MapX地图的ID资源IDC_MAP。

         2.3.为CintTranspSystemView类添加Windows消息WM_CREATE相应,增加了新的成员函数OnCreate。同样方法生成WM_SIZE消息的成员函数OnSize。

修改OnCreate成员函数如下:

intCIntTranspSystemView::OnCreate(LPCREATESTRUCT lpCreateStruct)

{

         if(CView::OnCreate(lpCreateStruct) == -1)

                   return-1;

        

         //TODO: Add your specialized creation code here

         SetCapture();

         BeginWaitCursor();

         try{

                   //取当前路径

                   charCurrentPath[80];

                   GetCurrentDirectory(80,CurrentPath);

                   charm_strPath[120];

                   strcpy(m_strPath,CurrentPath);

                   strcat(m_strPath,"\\Maps\\map.gst");

                  

                   //创建MApx地图对象

                   CRectViewRect;

                   GetClientRect(ViewRect);

                   m_ctrlMapX.Create(NULL,WS_VISIBLE,ViewRect,this,IDC_MAP);

                  

                   //设置Mapinfo数字地图

                   m_ctrlMapX.SetGeoSet(m_strPath);

                   m_ctrlMapX.SetMousePointer(miHourglassCursor);//设置鼠标形状

                   m_ctrlMapX.SetRedrawInterval(150);//地图延迟时间(0.001s)

                   CStringstr=m_ctrlMapX.GetTitleText();//显示地图标题

                   m_ctrlMapX.SetTitleText(str);

                   m_ctrlMapX.SetMapUnit(1);//地图单位(公里)

                   m_bMapData=true;//地图装入

         }

         catch(COleDispatchException*e){

                   e->ReportError();

                   e->Delete();

                  

         }

         catch(COleException*e){

                   e->ReportError();

                   e->Delete();

                  

         }

         ReleaseCapture();

         EndWaitCursor();

         m_ctrlMapX.SetMousePointer(0);

         return0;

}

修改OnSize函数如下:

void CIntTranspSystemView::OnSize(UINTnType, int cx, int cy)

{

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

        

         //TODO: Add your message handler code here

         if(m_bMapData==true&&cx!=0&&cy!=0)

         {

                   try

                   {

                            m_ctrlMapX.MoveWindow(0,0,cx,cy);//使地图充满窗口

                   }

                   catch(COleDispatchException*e){

                            e->ReportError();

                            e->Delete();

                   }

                   catch(COleException*e){

                            e->ReportError();

                            e->Delete();

                   }

         }

}

你可能感兴趣的:(VC++环境下Mapx地图的加载)