孙鑫VC++深入详解:Lesson9 Part7---在状态栏中显示鼠标的位置

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



//---

//---

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值