VS2010 状态栏信息显示

步骤:

<1> : 现在CMainFrame类中定义:

CMFCStatusBar     m_wndStatusBar;//有MFC3字母,很多教材都使用CStatusBar

<2> : 定义indicator指示器

static UINT indicators[] =
{
 ID_SEPARATOR,
 ID_SEPARATOR,           // status line indicator
 ID_INDICATOR_STR,
 ID_INDICATOR_CAPS,
 ID_INDICATOR_NUM,
 ID_INDICATOR_SCRL,
};

红色的系统已经预定义了,添加一个自定义的举例

在res资源中在string中添加ID_INDICATOR_STR字段,预设值"asssd",根据需要.

<3> : 在CMainFrame类创建OnCreate中:

if (!m_wndStatusBar.Create(this))
 {
  TRACE0("Failed to create status bar\n");
  return -1;      // fail to create
 }
 m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT));

<4> : 显示信息,显示鼠标坐标

在C***View类中添加鼠标移动事件,第一种显示方式:

void C***View::OnMouseMove(UINT nFlags, CPoint point)
{
 // TODO: Add your message handler code here and/or call default
 
 CString strr;
 strr.Format(_T("X=%d,Y=%d"),point.x,point.y);

 ((CFrameWnd*)GetParent())->SetMessageText(strr);

 CView::OnMouseMove(nFlags, point);
}

第二种显示方式

void CHelloWorld2View::OnMouseMove(UINT nFlags, CPoint point)
{
 // TODO: Add your message handler code here and/or call default
 
 CString strr;
 CMFCStatusBar* pStatus;
 strr.Format(_T("X=%d,Y=%d"),point.x,point.y);

 pStatus=(CMFCStatusBar*)(AfxGetApp()->m_pMainWnd->GetDescendantWindow(AFX_IDW_STATUS_BAR));
 pStatus->SetPaneText(1,strr);

 CView::OnMouseMove(nFlags, point);
}

<5> : 在状态栏显示时间:

a> : 先创建一个指示器元素ID_INDICATOR_TIMER字段,字符"Show Time";

b> : 在CMainFrame类中的OnCreate中添加:

SetTimer(1,1000,NULL);
 CTime time=CTime::GetCurrentTime();
 CString str=time.Format("%H:%M:%S");
 CClientDC dc(this);
 CSize sz=dc.GetTextExtent(str);

 m_wndStatusBar.SetPaneInfo(1,ID_INDICATOR_TIMER,SBPS_POPOUT,sz.cx);
 m_wndStatusBar.SetPaneText(0,str);

c> : 然后添加OnTimer事件

void CMainFrame::OnTimer(UINT_PTR nIDEvent)
{
 // TODO: Add your message handler code here and/or call default
 CTime time=CTime::GetCurrentTime();
 CString str=time.Format("%H:%M:%S");

 m_wndStatusBar.SetPaneText(0,str);

 CFrameWndEx::OnTimer(nIDEvent);
}

d> : 运行即可得到结果!

e> : 添加状态栏几个常用属性设置:

m_wndStatusBar.SetPaneWidth(0,250);
 m_wndStatusBar.SetPaneTextColor (0, RGB(255,0,0));
 m_wndStatusBar.SetPaneBackgroundColor(0,RGB(255,255,255));

......

 

转载于:https://www.cnblogs.com/MMLoveMeMM/articles/2993417.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值