MFC增加状态栏
2023-08-30
13
1
MFC增加状态栏
增加状态栏,并将状态栏分为2部分。
m_StatusBar.Create(this);
UINT indicators[2];
m_StatusBar.SetIndicators(indicators, 2);
CRect rect;
GetClientRect(&rect);
for (int i = 0; i < 2; i++)
{
m_StatusBar.SetPaneInfo(i, 0, 0, rect.Width() / 2);
}
m_StatusBar.SetPaneText(0, L"aaa", TRUE);
m_StatusBar.SetPaneText(1, L"bbb", TRUE);
RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);
为了使状态栏随窗口大小而跟随变化:
void CDupFileDlg::OnSize(UINT nType, int cx, int cy)
{
CDialogEx::OnSize(nType, cx, cy);
CRect rcClient(0, 0, cx, cy);
RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST, 0, 0, &rcClient);
RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST, reposQuery, &rcClient, &rcClient);
}
注意事项:
在自定义创建的线程中使用SetPaneText会导致失败。可使用发送消息的方式来实现:
void CDupFileDlg::SetStatusBarText(int index, TCHAR* text)
{
::SendMessage(m_StatusBar.m_hWnd, SB_SETTEXT, index, (LPARAM)text);
}
参考文章:https://blog.csdn.net/ljh0302/article/details/50238419/