由于view类窗口始终都是在框架类之上,所以我们在捕获鼠标移动的时候应该在view类中操作。首先在view类中增加WM_MOUSEMOVE消息的响应然后有以下方法获得:
(1)
CString str;
str.Format("x=%d,y=%d",point.x,point.y);
((CMainFrame*) GetParent_r())->m_wndStatusBar.SetWindowText(str);//获得父窗口的指针,然后获得状态栏m_wndStatusBar(一般都是在框架窗口定义的),调用SetWindowText()函数
//((CMainFrame*) GetParentOwner_r())->m_wndStatusBar.SetWindowText(str);
(2)
CString str;
str.Format("x=%d,y=%d",point.x,point.y);
((CMainFrame*) GetParent_r())->SetMessa geText_r(str);
应用SetMessageText方法:
CFrameWnd::SetMessageText
void SetMessa geText_r( LPCTSTR lpszText );
void SetMessa geText_r( UINT nID );
这个函数直接放置字符串到状态栏。
(3)
CString str;
str.Format("x=%d,y=%d",point.x,point.y);
((CMainFrame*) GetParent_r())-> GetMessageBar_r()->SetWindowText(str);
应用 GetMessageBar_r()函数:
CFrameWnd::GetMessageBar
virtual CWnd* GetMessageBar_r( );
直接获得状态栏的指针,不需要调用MainFrame中定义的成员函数了。
(4)
CString str;
str.Format("x=%d,y=%d",point.x,point.y);
GetParent_r()-> GetDescendantWindow_r(AFX_IDW_STATUS_BAR)->SetwindowText(str);
函数GetDescendantWindow():
CWnd::GetDescendantWindow
CWnd* GetDescendantWindow_r( int nID, BOOL bOnlyPerm = FALSE ) const;
调用此函数,根据给定的子孙窗口的状态栏的ID号,这个ID号在我们创建状态栏的时候已经默认给定了:CStatusBar::Create
BOOL Create( CWnd* pParentWnd, DWORD dwStyle = WS_CHILD | WS_VISIBLE | CBRS_BOTTOM, UINT nID = AFX_IDW_STATUS_BAR );
然后和前边一样调用SetWindowText();
ZZ:http://blog.sina.com.cn/s/blog_4bc179a80100giy4.html