1. 要在View中捕获WM_MOUSEMOVE消息,而不是在FRAME中,因为框架被VIEW类覆盖了.
2. 在CMainFrame中 public: CStatusBar m_wndStatusBar; // 设置为public,一边view中访问
四种方式:
void CStyleView::OnMouseMove(UINT nFlags, CPoint point)
{// TODO: Add your message handler code here and/or call defaultCString str; str.Format("x=%d,y=%d",point.x,point.y);//格式化str//------方式一:m_wndStatusBar.SetWindowText(str)//((CMainFrame*)GetParent())->m_wndStatusBar.SetWindowText(str);//------方式二:用CMainFrame的成员函数 SetMessageText(),它唯一的用途就是在ID为0的状态栏的pane上设置text//((CMainFrame*)GetParent())->SetMessageText(str);//------方式三:用CMainFrame的成员函数GetMessageBar()//((CMainFrame*)GetParent())->GetMessageBar()->SetWindowText(str);//------方式四:用CWnd的成员函数GetDescendantWindow(),查找指定ID的子窗口GetParent()->GetDescendantWindow(AFX_IDW_STATUS_BAR,FALSE)->SetWindowText(str);CView::OnMouseMove(nFlags, point);
}
GetDescendantWindow() 函数中涉及到一个所谓的永久性窗口和临时窗口的概念,需要搞清楚.
CWnd* GetDescendantWindow( int nID, BOOL bOnlyPerm = FALSE ) const;
Return Value
A pointer to a CWnd object, or NULL if no child window is found.
Parameters
nID
Specifies the identifier of the control or child window to be retrieved.
bOnlyPerm
Specifies whether the window to be returned can be temporary. If TRUE, only a permanent window can be returned; if FALSE, the function can return a temporary window. For more information on temporary windows see Technical Note 3.
Remarks
//---
//---