MFC状态栏设置

#include "stdafx.h"
#include "resource.h"

UINT g_nIndicator[]={
	ID_SEPARATOR,
	ID_SEPARATOR,
	ID_INDICATOR_NUM,//数字 等等 参数自己设定
	ID_INDICATOR_OVR,
	ID_INDICATOR_CAPS,
	ID_INDICATOR_SCRL,


};
class MFCStatusFrame:public CFrameWnd
{
    DECLARE_MESSAGE_MAP()
public:
	afx_msg int OnCreate(LPCREATESTRUCT lpCreate);
	afx_msg void OnTimer(int nIDevent);
public:
	CStatusBar m_wndStatusBar;
};

BEGIN_MESSAGE_MAP(MFCStatusFrame,CFrameWnd)
	ON_WM_CREATE()
	ON_WM_TIMER()
END_MESSAGE_MAP()

void MFCStatusFrame::OnTimer(int nIDevent){
	//获取时间
	CTime tmCurrent =CTime::GetCurrentTime();
	CString strTime=tmCurrent.Format("%Y-%m-%D %H:%M:%S");
	m_wndStatusBar.SetPaneText(1,strTime,true);
	
}
int MFCStatusFrame::OnCreate(LPCREATESTRUCT lpCreate)
{
	CFrameWnd::OnCreate(lpCreate);
	//添加菜单
	CMenu menu;
	menu.LoadMenu(IDR_MAINFRM);
	SetMenu(&menu);
	menu.Detach();

	//创建状态栏
	m_wndStatusBar.Create(this);
	//设置指示器
	m_wndStatusBar.SetIndicators(g_nIndicator,
		sizeof(g_nIndicator)/sizeof(UINT));
	m_wndStatusBar.SetPaneText(1,"我的状态栏",false);

	//创建定时器
	SetTimer(1,1000,NULL);
	return 1;
}


class MFCStatusApp:public CWinApp{
public:
    virtual BOOL InitInstance();
};

MFCStatusApp theApp;
BOOL MFCStatusApp::InitInstance(){
    MFCStatusFrame *pWnd=new MFCStatusFrame();
    pWnd->Create(NULL,"MFCStatusApp");
    m_pMainWnd=pWnd;
    m_pMainWnd->ShowWindow(SW_SHOW);
    m_pMainWnd->UpdateWindow();
    return true;

}

你可能感兴趣的:(MFC状态栏设置)