在MFC的的单文档应用中,在建好应用程序之后,在CMainFrame类中定义状态栏对象CStatusBar m_wndStatusBar;
step 1.定义状态栏对象CStatusBar m_wndStatusBar;
G:\stock\TskingVS2019\src\Client\StkUI\MainFrm.h
class CMainFrame : public CTskMainFrame
{
...
CStatusBar m_wndStatusBar;
....
step 2: CMainFrame::OnCreate()函数中进行状态栏的创建
2.1 向indicators数组里面添加元素
G:\stock\TskingVS2019\src\Client\StkUI\MainFrm.cpp
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
// toolbar buttons - IDs are command buttons
static UINT indicators[] =
{
//ID_SEPARATOR, // status line indicator
//ID_SEPARATOR, // stock indicator, and progress indicator
//ID_SEPARATOR, // stock indicator
//ID_SEPARATOR, // time indicator
//ID_INDICATOR_CAPS,
ID_SEPARATOR, // 状态行指示器
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL
};
2.2 在int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)函数中进行状态栏的创建,代码如下:
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CTskMainFrame::OnCreate(lpCreateStruct) == -1)
return -1;
// ******************************************
// 自定义状态栏
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
...
}
运行程序后,状态栏的右下角默认有三个Pane,其定义在MainFrm.cpp文件中的indicators数组里面.
第二部分 修改面板属性
// Set Status Bar Styles
UINT nID, nStyle;
int cxWidth;
m_wndStatusBar.GetPaneInfo(1, nID, nStyle, cxWidth);
m_wndStatusBar.SetPaneInfo(1, nID, nStyle, 200);
m_wndStatusBar.GetPaneInfo(2, nID, nStyle, cxWidth);
m_wndStatusBar.SetPaneInfo(2, nID, nStyle, 200);
m_wndStatusBar.GetPaneInfo(3, nID, nStyle, cxWidth);
m_wndStatusBar.SetPaneInfo(3, nID, nStyle, 50);
m_wndStatusBar.GetStatusBarCtrl().SetMinHeight(20);
HICON icon = AfxGetApp()->LoadIcon(IDI_INDICATOR);
m_wndStatusBar.GetStatusBarCtrl().SetIcon(0, icon);
//m_wndStatusBar.GetStatusBarCtrl().SetBkColor(RGB(180, 180, 180));
https://docs.microsoft.com/en-us/cpp/mfc/reference/cstatusbar-class?view=vs-2019
第三部分 用定时器更新状态条信息
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnTimer(UINT nIDEvent)
{
if (TIMER_TIME == nIDEvent)
{
CSPTime time = CSPTime::GetCurrentTime();
CString string = (LPCTSTR)AfxGetTimeString(time.GetTime(), "%H:%M:%S", FALSE);
m_wndStatusBar.SetPaneText(3, string);
}
else if (TIMER_STOCKINDEXREFRESH == nIDEvent)
{
CString strSHTipFmt, strSZTipFmt;
strSHTipFmt.LoadString(IDS_MAINFRAME_SHINDEXTIP);
strSZTipFmt.LoadString(IDS_MAINFRAME_SZINDEXTIP);
double dDevided = 100000000;
#ifdef CLKLAN_ENGLISH_US
dDevided = 1000000000;
#endif
CString string;
double dDiff = 0;
CStockInfo info;
COLORREF clrRise = AfxGetProfile().GetColor(CColorClass::clrRise);
COLORREF clrFall = AfxGetProfile().GetColor(CColorClass::clrFall);
//取上证指数,这里为000001 ,取到了股票代码,有问题 by freeman 2019/06/08
if (AfxGetStockContainer().GetStockInfo(STKLIB_CODE_SZZS, &info))
{
info.GetDiff(&dDiff, info.m_datetech, 1);
string.Format(strSHTipFmt, info.m_fClose, dDiff, info.m_fAmount / dDevided);
// m_wndStatusBar.SetPaneColor(dDiff > 0 ? clrRise : clrFall);
m_wndStatusBar.SetPaneText(1, string);
}
//取深证成指 by freeman
if (AfxGetStockContainer().GetStockInfo(STKLIB_CODE_SZNCZ, &info))
{
info.GetDiff(&dDiff, info.m_datetech, 1);
string.Format(strSZTipFmt, info.m_fClose, dDiff, info.m_fAmount / dDevided);
// m_wndStatusBar.SetPaneColor(dDiff > 0 ? clrRise : clrFall);
m_wndStatusBar.SetPaneText(2, string);
}
在MFC的的单文档应用中,在建好应用程序之后,CMainFrame类中定义状态栏对象CStatusBar
http://blog.sina.com.cn/s/blog_8584c97c01010b5j.html
CStatusBar类和 CMFCStatusBar使用方法解释
http://www.jizhuomi.com/software/219.html
Add status bar to an MFC dialog, CStatusBar
http://www.ucancode.net/Visual_C_MFC_Samples/Add_Status_CStatusBar_MFC_Dialog_Sample.htm
CMFCStatusBar Class
https://docs.microsoft.com/en-us/cpp/mfc/reference/cmfcstatusbar-class?view=vs-2019