使用API函数CreateWindow或者CreateWindowEx,并将类名指定为STATUSCLASSNAME就可以创建一个状态栏
MFC封装类CStatusBar
新建基于对话框的工程StatusBarDemo
添加ID为ID_EDT_INPUT的多行文本框,并关联变量m_edt_input
///
protect:
CStatusBar m_status;
///OnInitDialog中
创建状态栏,并新建两个子窗格
m_status.Create(this);
UINT nID[] = {ID_SEPARATOR ,100};
m_status.SetIndicators(nID ,2);///设置指示器
///移动状态栏到合适的位置
RECT rect = {0};
GetClientRect(&rect);
m_status.MoveWindow(0 , rect.bottom- 20 ,rect.right -10 ,20 ,true);
///将第二个格子的宽度设置为80
m_status.SetPaneInfo(0,0,0,rect.right -10 - 80);
m_status.SetPaneInfo(1,100,0,80);
///添加EN_CHANGE消息响应函数
void CStatusBarDemoDlg::OnChangeEdtInput()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
///获取文本长度,并显示到状态栏
int nLen = m_edt_input.GetWindowTextLength();
CString str;
str.Format(_T("字节:%d") , nLen);
m_status.SetPaneText(1,str,true);
// TODO: Add your control notification handler code here
}