打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
单文档添加地图(VC++6.0)

给单文档添加地图的方法

创建单文档后,在程序的目录文件里面考入两个类的头文件和源文件:yimaencyimaenchead还有授权的lib文件。哦,对了,还有例子里面的3个文件夹。

一:CMainFrame头文件添加public控件对象:

       CYimaEnc m_yimaEncCtrl;

莫要忘记包含头文件:#include "yimaenc.h"

#include "yimaenchead.h"

 

二:CMainFrame::OnCreate里面创建控件

 

       m_yimaEncCtrl.Create(NULL, NULL, CRect(0, 0, 0, 0), this,

              ID_YIMAENC_CTRL); 

       TCHAR curWorkDir[1024];

       GetCurrentDirectory(1024, curWorkDir);

       if (!m_yimaEncCtrl.Init(curWorkDir)) //YIMAENC COMMENT:  YimaEnc Control interoped!

       {

              AfxMessageBox("Failed to init YimaEnc Control, may be the config files are not exits!");

              return -1;

       }  

       m_yimaEncCtrl.tmOpenMapDataFile("MarineMap\\marineMap.ymc"); //读入自定义海图数据文件

 

        三:在view类里添加消息响应:WM_SETFOCUS

并在头文件里添加       CYimaEnc* m_pYimaEncCtrl;

在新增函数OnSetFocus里添加下列代码

       if (m_pYimaEncCtrl == NULL)

       {

              CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);

             

              if (pFrame != NULL)

              {

                     m_pYimaEncCtrl = &pFrame->m_yimaEncCtrl;

                    

                     RECT clientRect;

                     GetClientRect(&clientRect);

                    

                     // RefreshDrawer 在初始化屏幕 改变海图屏幕大小时应该被调用

                     m_pYimaEncCtrl->RefreshDrawer((long)m_hWnd,

                            clientRect.right - clientRect.left,

                            clientRect.bottom - clientRect.top,

                            0, 0);

                    

                     bool bTestGetLibMapInfo = false;

                     if (bTestGetLibMapInfo)

                     {

                            float originalScale = 0;

                            long left, right, up, down;

                           

                            m_pYimaEncCtrl->GetLibMapInfo(0, NULL, NULL, &originalScale,

                                   &left, &right, &up, &down, NULL, NULL); //得到海图库海图信息

                           

                            m_pYimaEncCtrl->SetCurrentScale(originalScale);

                           

                            m_pYimaEncCtrl->CenterMap( ((float)left + right) / 2,

                                   ((float)up + down) / 2);                                         

                           

                                   /* YIMAENC COMMENT: 注意!! 由于地理坐标值可能接近4字节

                                   long 型变量的上限(但不会超出),所以在做加法或乘法时需要转换为float

                            以防止溢出!*/                                      

                     }

                    

                     m_pYimaEncCtrl->FocusLibMap(0);

              }

       }

}

 

 

动态添加新函数RefreshScreenMap

并添加代码

void CText1View::RefreshScreenMap()

{

       if (m_pYimaEncCtrl != NULL)

       { 

              HDC hdc = ::GetDC(m_hWnd);

              m_pYimaEncCtrl->DrawMapsInScreen((long)hdc);

              ::ReleaseDC(m_hWnd, hdc);

       }

}

 

四:添加WM_SIZE
并添加代码

       if (m_pYimaEncCtrl != NULL)

       {

              RECT clientRect;

              GetClientRect(&clientRect);

             

              // RefreshDrawer 在初始化屏幕 改变海图屏幕大小时应该被调用

              m_pYimaEncCtrl->RefreshDrawer((long)m_hWnd,

                     clientRect.right - clientRect.left,

                     clientRect.bottom - clientRect.top,

                     0, 0); 

             

              CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;

             

动态添加函数RefreshScaleStatusBar

       /***************** 刷新比例尺信息显示栏 ********************/

void CTextView::RefreshScaleStatusBar()

{

       CStatusBar * pStatusBar = (CStatusBar *)AfxGetApp()->m_pMainWnd->

              GetDescendantWindow(AFX_IDW_STATUS_BAR);

      

       if (pStatusBar!=NULL)

       {

              float curScale = m_pYimaEncCtrl->GetCurrentScale();

             

              CString strCurScale;                   

              strCurScale.Format("比例尺 1 : %d", (int)curScale);

              pStatusBar->SetPaneText(INDEX_PANE_FOR_SCALE, strCurScale);

       }

}

 

 

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
用Windows API实现一个简单的文本输入框
vc 控件 自绘
Bezier曲线原理及实现代码(c++)
VC编程小技巧之框架窗口及其他
VC窗体设计集锦
孙鑫VC视频教程笔记之第九课“程序外观修改及工具栏状态栏编程”
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服