在类C***Dlg的定义中声明BOOL CreateStateBar();函数。
以及 CStatusBarCtrl m_status_bar;//状态栏变量
函数实现方式如下:
BOOL C***Dlg::CreateStateBar()
{int nTotWide; // total width of status bar
CRect rect;
this->GetWindowRect(&rect);
rect.top = rect.bottom- 25;
BOOL m_bRvStatOk;
m_bRvStatOk = m_status_bar.Create(WS_CHILD|WS_VISIBLE ,rect,this,
IDC_STATUSBAR);
//注意:IDC_STATUSBAR为自己在Resource.h文件中define的值。大小根据实际情况。主要是资源编辑器识别。程序运行后以句柄为主要引导方式。
//如 #define IDC_STATUSBAR 1101
if (m_bRvStatOk == NULL)
{
AfxMessageBox ("Status Bar not created!", NULL, MB_OK );
}
//
// get size of window, use to configure the status
// bar with four separate parts
//
CRect rWin;
this->GetWindowRect(&rWin);
nTotWide = rWin.right-rWin.left;
//
// Make each part 1/4 of the total width of the window.
//
int m_Widths[4];
m_Widths[0] = nTotWide / 4;
m_Widths[1] = nTotWide / 2;
m_Widths[2] = nTotWide - m_Widths[0];
m_Widths[3] = -1;
m_status_bar.SetMinHeight(25);
m_status_bar.SetParts( 4, m_Widths);
m_status_bar.SetText("BAMAC高稳型加热电源上位机软件",0,0);//后面几个状态Panel以此类推。比如加载进时间等。
m_status_bar.ShowWindow(SW_SHOW);
return TRUE;
}
在C***Dlg::OnInitDialog()中调入CreateStateBar()即可创建状态栏。