基於對話方塊MFC程式新增狀態列
阿新 • • 發佈:2019-01-29
首先 需要建立一個 狀態列物件:
CStatusBar m_Statusbar; //狀態列
然後在初始化程式中
//建立狀態列 m_Statusbar.Create(this); m_Statusbar.SetIndicators(indicators,sizeof(indicators)/sizeof(UINT)); CRect rect; GetWindowRect(rect); m_Statusbar.SetPaneInfo(0,ID_STAUTSTIP,SBPS_STRETCH, rect.Width()/4); m_Statusbar.SetPaneInfo(1,ID_STAUTSSPEED,SBPS_NORMAL ,rect.Width()/4); m_Statusbar.SetPaneInfo(2,ID_STAUTSPORT,SBPS_NORMAL, rect.Width()/4); m_Statusbar.SetPaneInfo(3,ID_STAUTSCOUNT,SBPS_NORMAL ,rect.Width()/4); //m_Statusbar.SetPaneText(0,"就緒"); //m_Statusbar.SetPaneText(1,"速度:0kb/s"); //m_Statusbar.SetPaneText(2,"埠:8888"); //m_Statusbar.SetPaneText(3,"連線:0"); RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST,0);//很重要****
indicators結構體定義如下:
static UINT indicators[] =
{
ID_STAUTSTIP, // status line indicator
ID_STAUTSSPEED,
ID_STAUTSPORT,
ID_STAUTSCOUNT
};
這裡結構體中的紅關聯string tabel,如圖:
如無關聯字串,則可以使用SetPaneText函式設定狀態列的內容
效果如下: