当前时间显示在状态栏HTML,在状态栏中显示当前时间

//MyStatusBar.h:

//==============

class CMyStatusBar : public CStatusBar {

DECLARE_DYNCREATE(CMyStatusBar)

public:

CMyStatusBar();

~CMyStatusBar();

private:

CString m_strClockFormat;

public:

void SetClockFormat(LPCTSTR strClockFormat);

// Overrides

// ClassWizard generated virtual function overrides

//{{AFX_VIRTUAL(CMyStatusBar)

//}}AFX_VIRTUAL

// Generated message map functions

//{{AFX_MSG(CMyStatusBar)

afx_msg void OnDestroy();

afx_msg void OnUpdateIndicatorTime(CCmdUI* pCmdUI);

afx_msg int OnCreate( LPCREATESTRUCT lpCreateStruct );

//}}AFX_MSG

DECLARE_MESSAGE_MAP()

};

/

//MyStatusBar.cpp:

//==============

#include "stdafx.h"

#include "MyStatusBar.h"

#include "Resource.h"

#ifdef _DEBUG

#undef THIS_FILE

static char BASED_CODE THIS_FILE[] = __FILE__;

#endif

IMPLEMENT_DYNCREATE(CMyStatusBar, CStatusBar)

BEGIN_MESSAGE_MAP(CMyStatusBar, CStatusBar)

ON_WM_CREATE()

ON_WM_DESTROY()

ON_UPDATE_COMMAND_UI(ID_INDICATOR_TIME, OnUpdateIndicatorTime)

END_MESSAGE_MAP()

CMyStatusBar::CMyStatusBar()

: CStatusBar()

, m_strClockFormat("%H:%M:%S")

{

}

CMyStatusBar::~CMyStatusBar() {

}

void CMyStatusBar::SetClockFormat(LPCTSTR strClockFormat) {

m_strClockFormat = strClockFormat;

}

int CMyStatusBar::OnCreate(LPCREATESTRUCT lpCreateStruct) {

// make sure time gets updated every second, even when idle

CStatusBar::OnCreate(lpCreateStruct);

SetTimer(ID_INDICATOR_TIME,1000,NULL);

return 0;

}

void CMyStatusBar::OnUpdateIndicatorTime(CCmdUI* pCmdUI) {

pCmdUI->Enable(true);

pCmdUI->SetText(CTime::GetCurrentTime().Format(m_strClockFormat));

}

void CMyStatusBar::OnDestroy() {

KillTimer(ID_INDICATOR_TIME);

ProgressDestroy();

CStatusBar::OnDestroy();

}

Step 2:

添加一个字符串资源,ID是ID_INDICATOR_TIME,值为HH:MM:SS

Step 3:

Add a new indicator pane called ID_INDICATOR_TIME to your list of indicator in your mainframe eg. this is my indicator list...

static const UINT indicators[] = {

ID_SEPARATOR, // status line indicator

ID_INDICATOR_CAPS,

ID_INDICATOR_NUM,

ID_INDICATOR_SCRL,

ID_INDICATOR_TIME, //

};

Step 4:

Replace all existing uses of CStatusBar in your app with CMyStatusBar - in particular, the member variable in your mainframe m_wndStatusBar;

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值