原文鏈接: http://blog.chinaunix.net/uid-9847882-id-1996528.html
方法一:
1.添加成員變量CStatusBarCtrl m_StatusBar;
2.在OnInitDialog()中加入:
m_StatusBar.Create(WS_CHILD|WS_VISIBLE|SBT_OWNERDRAW, CRect(0,0,0,0), this, 0);
int strPartDim[3]= {100, 200, -1}; //分割數量
m_StatusBar.SetParts(3, strPartDim);
//設置狀態欄文本
m_StatusBar.SetText("分欄一", 0, 0);
m_StatusBar.SetText("分欄二", 1, 0);
m_StatusBar.SetText("分欄三", 2, 0);
//下面是在狀態欄中加入圖標
m_StatusBar.SetIcon(1,
SetIcon(AfxGetApp()->LoadIcon(IDR_MAINFRAME),
FALSE));//為第二個分欄中加的圖標
方法二:
1.添加成員變量CStatusBar m_wndStatusBar;
2.在OnInitDialog()中加入:
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS, //CAP lock indicator.
ID_INDICATOR_NUM, //NUM lock indicator.
ID_INDICATOR_SCRL, //SCRL lock indicator.
};
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
UINT nID; //控制狀態欄里面的分欄
m_wndStatusBar.SetPaneInfo(0,nID,SBPS_STRETCH|SBPS_NOBORDERS,100); //返回值存nID中
m_wndStatusBar.SetPaneText(0,"就緒");
m_wndStatusBar.SetPaneInfo(1,nID,SBPS_NORMAL,100);
m_wndStatusBar.SetPaneText(1,"大寫");
m_wndStatusBar.SetPaneInfo(2,nID,SBPS_POPOUT,100);
m_wndStatusBar.SetPaneText(2,"數字");
//SetPaneInfo()函數的第三個參數的可選項如下:
//The following indicator styles are supported:
// SBPS_NOBORDERS No 3-D border around the pane.
// SBPS_POPOUT Reverse border so that text "pops out."
// SBPS_DISABLED Do not draw text.
// SBPS_STRETCH Stretch pane to fill unused space. Only one pane per status bar can have this style.
// SBPS_NORMAL No stretch, borders, or pop-out.
//----------------讓這個狀態欄最終顯示在對話框中-------------
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);
