VC:状态栏增加时间显示信息

 

STEP1:在resource 的 string table中,增加IDS_TIMER
STEP2:在indicators[]数组中,增加 IDS_TIMER 项
STEP3:修改如下函数

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

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
 
 SetTimer(1,1000,NULL);
 
 CTime t=CTime::GetCurrentTime();
 CString str=t.Format("%H:%M:%S");
 CClientDC dc(this);
 CSize sz=dc.GetTextExtent(str);
 int index=0;
 index=m_wndStatusBar.CommandToIndex(IDS_TIMER);
 m_wndStatusBar.SetPaneInfo(index,IDS_TIMER,SBPS_NORMAL,sz.cx);
 m_wndStatusBar.SetPaneText(index,str);

}


void CMainFrame::OnTimer(UINT nIDEvent)
{
 // TODO: Add your message handler code here and/or call default

 CTime t=CTime::GetCurrentTime();
 CString str=t.Format("%H:%M:%S");
 CClientDC dc(this);
 CSize sz=dc.GetTextExtent(str);
 m_wndStatusBar.SetPaneInfo(1,IDS_TIMER,SBPS_NORMAL,sz.cx);
 m_wndStatusBar.SetPaneText(1,str);

 CFrameWnd::OnTimer(nIDEvent);
}

说明:
m_wndStatusBar.SetPaneInfo(index,IDS_TIMER,SBPS_NORMAL,sz.cx);
上面函数的功能,是使显示的窗口与内容相符。否则,显示内容可能不全。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值