1. 程式人生 > >MFC-CProgressCtrl進度條控制元件

MFC-CProgressCtrl進度條控制元件

知識點:
CSpinButtonCtrl常用屬性
CSpinButtonCtrl類常用成員函式
CSpinButtonCtrl程式碼示例

一、CSpinButtonCtrl控制元件屬性
1.新增EDIT控制元件
2.新增Spin控制元件
如果不是這樣的順序的話,使用ctrl+D改變Tab順序,使spin緊靠edit後面
3.在EDIT控制元件上面設定group屬性(特別注意)
4.設定Spin屬性
Auto 為Buddy //為 true 表示按Z序自動關聯一個夥伴視窗
Set Buddy Integer //為 true 表示在夥伴視窗上顯示數值
Alignment 為Right Align //表示spin控制元件在夥伴視窗中右對齊
Orientation // 水平,還是垂直
Wrap //數值超過範圍時迴圈數值超過範圍時迴圈
Arrow keys //為True(當按下向上和向下方向鍵時,控制元件可以增加或減小)

二、CSpinButtonCtrl類常用成員函式

SetAccel
為spin按鈕設定一個加速值。
GetAccel
Retrieves acceleration information for a spin button control.
SetBase
此成員函式用來設定一個旋轉按鈕控制元件的基數。這個基數值決定了夥伴視窗顯示的數字是十進位制的還是十六進位制的。十六進位制的數總是無符號的;十進位制的數是有符號的。

GetBase
Retrieves the current base for a spin button control.
SetBuddy
為spin按鈕設定一個夥伴視窗,點選spin按鈕時焦點會落在這個夥伴視窗上
GetBuddy
Retrieves a pointer to the current buddy window.
SetPos
為spin控制元件設定一個當前位置。
GetPos
Retrieves the current position of a spin button control.
SetRange
設定範圍值。
GetRange
Retrieves the upper and lower limits (range) for a spin button control.
SetRange32
設定32位的範圍值
GetRange32
Retrieves the 32-bit range for a spin button control.

三、 程式碼示例
// CDialog_SPIN_Test 訊息處理程式

int CDialog_SPIN_Test::OnInitDialog(void)
{
CDialog::OnInitDialog();
//獲取物件指標
CSpinButtonCtrl* pSpin=(CSpinButtonCtrl*)GetDlgItem(IDC_SPIN1);
CEdit* pedt=(CEdit*)GetDlgItem(IDC_EDIT2);
pSpin->SetRange32(0,1000);//設定範圍
pSpin->SetBase(10);//設定基數,進位制或者進位制顯示
pSpin->SetBuddy(pedt);//設定合作者視窗
UDACCEL a[2];//for
a[0].nSec=1;
a[0].nInc=1;
a[1].nSec=3;
a[1].nInc=20;
pSpin->SetAccel(2,a);//設定加速度
return 0;
}