天天看點

VC++對話框中添加狀态欄的方法

方法一:

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,

m_StatusBar.SetText("分欄二", 1,

m_StatusBar.SetText("分欄三", 2,

//下面是在狀态欄中加入圖示

m_StatusBar.SetIcon(1, 

SetIcon(AfxGetApp()->LoadIcon(IDR_MAINFRAME),

FALSE));//為第二個分欄中加的圖示

方法二:

1.添加成員變量CStatusBar

m_wndStatusBar;

static UINT indicators[]

=

{

ID_SEPARATOR,                       

// status line

indicator

ID_INDICATOR_CAPS,             

//CAP lock

indicator.

ID_INDICATOR_NUM,              

//NUM lock

ID_INDICATOR_SCRL,             

//SCRL lock

};

if (!m_wndStatusBar.Create(this)

||

!m_wndStatusBar.SetIndicators(indicators,

sizeof(indicators)/sizeof(UINT)))

TRACE0("Failed to create status

barn");

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);