再探MFC(六)狀態列
狀態列使用
step1
對話方塊新增變數
// 狀態列物件
CStatusBarm_wndStatusBar;
step2
定義狀態列各Indicator資源ID
例如
Resource.h
#defineID_CALL_STATUS 32783
step3
OnInitDialog呼叫
//建立和初始化狀態列
BOOLCLBDKFODlg::CreateStatusBar()
{
static UINT nIndicators[] = {
ID_CALL_STATUS
};
if (!m_wndStatusBar.Create (this))
return FALSE;
m_wndStatusBar.SetIndicators (nIndicators,1);
CRectrect;
GetClientRect(&rect);
m_wndStatusBar.SetPaneInfo(0,ID_CALL_STATUS,SBPS_NORMAL,rect.Width());
//m_wndStatusBar.GetStatusBarCtrl().SetBkColor(RGB(180,180,180));
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,ID_CALL_STATUS);
return TRUE;
}
step4
更新狀態列文字
m_wndStatusBar.SetPaneText(0,"空閒");
Tocreate a status bar, follow these steps:
- Construct the CStatusBar object.
- Call the Create (or CreateEx) function to create the status-bar window and attach it to the CStatusBar object.
-
Call SetIndicators to associate a string ID with each indicator.
There are three ways to update the text in a status-bar pane:
- Call CWnd::SetWindowText to update the text in pane 0 only.
- Call CCmdUI::SetText in the status bar's ON_UPDATE_COMMAND_UI handler.
- Call SetPaneText to update the text for any pane.
參考資料