VC++开发GIS系统(54)Ribbon状态栏实时显示坐标

本文目录
  • 正文

有了之前文章《VC++开发GIS系统(52)补充知识Ribbon界面自定义状态栏》做基础,现在可以实现动态显示坐标了,具体方法如下:

在XXXXView.cpp中的onMouseMove函数添加下面的代码:

void CmalagisView::OnMouseMove(UINT nFlags, CPoint point)
{
    // TODO:  在此添加消息处理程序代码和/或调用默认值
    /*
    * 实时显示坐标
    */
    //View中获取MainFrame指针
    CMainFrame *pMainFrame = (CMainFrame *)AfxGetApp()->m_pMainWnd;
    //获取状态栏指针
    CMFCRibbonStatusBar *statusBar = (CMFCRibbonStatusBar *)pMainFrame->GetDescendantWindow(AFX_IDW_STATUS_BAR);
    //更改坐标
    malaPoint MyPoint;
    ScreenToCoord(point.x, point.y, mScreen, &MyPoint.x, &MyPoint.y);
    CString str;
    str.Format(_T("X=%f,Y=%f"), MyPoint.x, MyPoint.y);
    statusBar->GetElement(2)->SetText(str);
    statusBar->GetElement(2)->Redraw();

    CView::OnMouseMove(nFlags, point);
}

其中下面的代码是在view中获取mainframe的中的状态栏的指针。

    //View中获取MainFrame指针
    CMainFrame *pMainFrame = (CMainFrame *)AfxGetApp()->m_pMainWnd;
    //获取状态栏指针
    CMFCRibbonStatusBar *statusBar = (CMFCRibbonStatusBar *)pMainFrame->GetDescendantWindow(AFX_IDW_STATUS_BAR);

然后用

    statusBar->GetElement(2)->SetText(str);
    statusBar->GetElement(2)->Redraw();

状态栏的函数更改文字。效果如下:

如果编译出现下面错误

error C2065: “CMainFrame”: 未声明的标识符

解决方法《VC++开发GIS系统(53)补充知识MFC中View调用CMainFrame未声明的标识符

本项目代码:GitHub

如您有疑问,可在文末留言,或到QQ群提问。

本站QQ群:291616564 麻辣GIS

微信公众号:malagis,扫描右边二维码直接关注。

微信捐助麻辣GIS 支付宝捐助麻辣GIS

如果本文对您有所帮助,欢迎对我们团队进行打赏捐助,让我们在传播3S的路上可以走得更远。


作者:,GIS爱好者。
分享本文,请您带上本文链接

发表评论

<-2' ).Tabs({!itititcallback : func hre(){!itititit$( this ).find( '.:void(0 > 即:not(.群)' ).t> ger( 'Javle">' )&ens}!itit});!itit$( '# <-2 即.群' ).one( 'Javle">', func hre(){ !ititit$( ' .Jav2', this ).Javle">({/" targegeeffect:'fadeIn'" tarit});!itit});!itit" targege!itit" targege// code h l " tarhljs.initH l ingOnLe">();!itit// v> Catalog!ititcreateCatalog();!itit$('#v> Catalogi).re('click','li', func hre() {!itititvar inx =t$(this).ss="t() - 1;!itititvar book= (inx == -1 ? 0 : $('.justiv> h2i).eq(inx).rffset().top)&ens$(' ,bodv').an反te({ ollTop:top}, 300);!itit});!itit" tar4 l &ensif(v['in ']>940){!ititititif($("#l board")./70" s()<$("#n")./70" s()){!itititititif($("#l board")./70" s()+$(docuiv c). ollTop()>=$("#n")./70" s()){!ititititititvar l book= $("#n")./70" s() - $("#l board")./70" s()-25;!itititititit$("#l board").css({/v> i hre: "absolon">, boo: l boo+"px"t});!itit tarit}else{!itititititit$("#l board").css({/v> i hre: "fixed>, boo: "auto"t});!itit tarit} it tarit}else{!ititititit$("#l board").css({/v> i hre: "static>, boo: "auto"t});!itit tar} it tar} else {!itititit$("#l board").css({/v> i hre: "relative>, boo: "auto"t});!itit t}!ititit//" tir " tar ir H70" sResize();!itit});!it});!!it/**!it* Globalis-pdf.!it**/!!it/**!it* 右边高度自动调整!it*/!itfunc hreir H70" sResize(){!ititvar vok= viewport()&evar sck= $(docuiv c). ollTop()&evar <-2")./70" s()&evar mhk= $("#n")./70" s()&evar h k= $(wss=ow)./70" s()&evar shk= $("#/a> -->")./70" s()&evar tuihk= $("# <")./70" s()&eif(mhv c0>sh&&vp['in ']>940&&h>371){!itititvar fw=$("# <-2").in ()&ens <-2'h&min(20))k+ (">'h+min(250+20))k+ global- <,#gomoney").css({"in ":fw+"px"})&ensif(sc< <").css({v> i hre: "static>, boo: "auto"});!itit tar$("# i hre: "static>, boo: "auto"});!itit tar//$("#gomoney").css({v> i hre: "static>, boo: "auto"});!itit t}/a>&ensif(sc> <").css({v> i hre: "fixed>, boo: "5px"})&ensar$("# i hre: "fixed>, boo: 25+tuih+"px"})&ens}/a>&ensif(sc+tuih+275>mhv 5){!ititititvar boohk= mhk- 275;!itititit$("# <").css({v> i hre: "absolon">, boo: booh-tuihv c+"px"})&ensar$("# i hre: "absolon">, boo: booh+"px"})&ens}/a>&e}/a>}!it/**!it* 获取外部宽度!it**/!itfunc hreiviewport(){!ititvar ek= wss=ow!itit, ak= 'in <'&eif ( !( 'in }!!it/**!it* 生成作<目录!it**/!itfunc hreicreateCatalog()t{!ititif ($('.justiv> h2i).leng < 2)ereturn;!itit$('.justiv> h2i).each(func hre(i) {!ititit$('#v> Catalog ul').app i).eq(0).css({"maxnin ":"405px"})&e$('#v> Catalogi).show()} map (func hre(){!ititvar bpk= docuiv c.createEleiv c(' ');!ititvar curProtocolk= wss=ow.loYour W.protocol.splic(':')[0];!ititif (curProtocolk=== '" tas') {!ititititbp.srck= '" tasrgetz.bdstatic程08475ubmit" tah.js' target=" &ens}/a>&eelse {!ititititbp.srck= '" tacn" tah.zhanzhang息工程 tah.js' &ens}/a>&evar sk= docuiv c.gecEleiv csByTagName(" .)[0];!itits.patab-NodeiinsertBe" te(bp, s); })()k= func hre () {!itsetTimeout(func hre () {!ititga('s立 >