您的位置:首页 > 其它

ribbon界面状态栏显示鼠标坐标

2011-07-06 21:11 302 查看
实现功能:在ribbon界面下,打开图像,鼠标在图像上移动时,状态栏上实时显示鼠标所在位置的坐标。方法:
在mainframe类中添加如下函数:
void CMainFrame::UpdateStatusBar(int nID, CString str)
{
CMFCRibbonBaseElement* pPane = m_wndStatusBar.FindByID(nID);
if (pPane != NULL)
{
pPane->SetText(str);
}
m_wndStatusBar.Invalidate();
m_wndStatusBar.UpdateWindow();
}
void CMainFrame::UpdateUI(CFancyView* pCurrView, CString point)
{
UpdateStatusBar(ID_STATUSBAR_PANE1, point);
}
在OnCreate函数里改把相应的语句改为:
m_wndStatusBar.AddDynamicElement(new CMFCRibbonStatusBarPane(ID_STATUSBAR_PANE1, strTitlePane1, TRUE,NULL,_T("x=0000,y=0000")));
在view类中,用classwizard添加WM_MOUSEMOVE消息,然后在view中出现了void CFancyView::OnMouseMove(UINT nFlags, CPoint point)
在里面添加如下代码:
CFancyDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
int offsetX = GetScrollPos(SB_HORZ);
int offsetY = GetScrollPos(SB_VERT);
point.x = point.x + offsetX;	// 处理Zoom和滚动条的位置
point.y = point.y + offsetY;
strmouse.Format("x=%d,y=%d",point.x,point.y);
((CMainFrame*)AfxGetMainWnd())->UpdateUI(this,strmouse);
CScrollView::OnMouseMove(nFlags, point);
这样就可以了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: