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 default
CString 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
//---
//---
本文详细介绍了如何在视图(View)中捕获WM_MOUSEMOVE消息,并通过多种方法更新状态栏(Status Bar)文本。包括在CMainFrame类中设置公共访问权限,以及四种更新状态栏文本的具体实现方式:直接设置文本、使用CMainFrame的成员函数SetMessageText()、GetMessageBar()和GetDescendantWindow()查找指定ID的子窗口。同时,解释了CWnd类中GetDescendantWindow()函数涉及的永久性窗口和临时窗口概念。
4936

被折叠的 条评论
为什么被折叠?



