在使用Ribbon的MFC程序状态栏中显示鼠标坐标值

来源:互联网 发布:塞班系统下载软件 编辑:程序博客网 时间:2024/05/17 20:33
这两天在练习程序中需要获取鼠标当前点的坐标值,以前使用的MFC Standard风格中可以使用CStatusBar中的SetPaneText方法来设置。但是使用了Ribbon风格后,我们可以从MainFrame中看到相应的类已经变为:在VS Ribbon界面下,CMainFrame类包含了三个成员变量:m_wndRibbonBar、 m_MainButton、m_wndStatusBar,分别用于控制VS Ribbon界面的命令面板,应用程序按钮和状态栏。清楚了各个变量对应的 VS Ribbon界面元素后,我们就可以操作相应的成员变量,在VS Ribbon界面上添加我们需要的内容。


   在Ribbon下没有CStatusBar,怎么更新呢?我在网上搜了半天也没找到结果,到国外的网站也看了看,有几个可能有结果的还没屏蔽了,无语中。。。后来又找MSDN,在运气的帮助下,找到了一个方法,我不知道这个方法有没有什么副作用,不过至少要求的功能实现了。好了,直接上代码。


   在View类中实现OnMouseMove(UINT nFlags, CPoint point),其中代码如下:

        CString str;
        str.Format("鼠标指针的当前坐标(X:%d, Y:%d)", point.x, point.y);  
        CMainFrame *pFrame=(CMainFrame*)AfxGetApp()->m_pMainWnd;
        CMFCRibbonStatusBar* statusBar = (CMFCRibbonStatusBar*)&pFrame->m_wndStatusBar;
        statusBar->SetInformation(str);

   在这里使用了CMFCRibbonStatusBar::SetInformation,成功。

        void SetInformation(LPCTSTR lpszInfo);
Remarks:       

Use this method to put the status bar in the information mode. In this mode, the status bar hides all panes and displays the information string specified bylpszInfo.

When lpszInfo is NULL, the status bar reverts to regular mode.