您的位置:首页 > 编程语言 > PHP开发

CSpinButtonCtrl::GetPos()和GetPos32( )两个函数的用法

2008-01-15 12:30 567 查看
CSpinButtonCtrl::GetPos()和GetPos32( )两个函数的用法

今天写了一个程序,里面的结果有点意思,在BOOL Cex06aDlg::OnInitDialog()中,使用了spinbutton控件

设置如下:

CSpinButtonCtrl *pSpin = (CSpinButtonCtrl *)GetDlgItem(IDC_SPIN1);
pSpin->SetRange(0, 100);
pSpin->SetPos(25);

//m_strMyedit = _T("25"); //.Format()
m_strMyedit.Format( _T("%3.1lf"), (double)pSpin->GetPos());
SetDlgItemText(IDC_BUDDY_SPIN1, m_strMyedit);

显示在文本编辑框里面的居然不是25.0,我之后还有一个消息函数,也是点击spinbutton控件来实现文本编辑诓的变化,如下:

void Cex06aDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default

if (nSBCode == SB_ENDSCROLL)
return;
if (pScrollBar->GetDlgCtrlID() == IDC_SPIN1) {
CSpinButtonCtrl *pSpin = (CSpinButtonCtrl *)pScrollBar;
m_strMyedit.Format(_T("%3.1lf"), double(pSpin->GetPos()) );
SetDlgItemText(IDC_BUDDY_SPIN1, m_strMyedit);
}

CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}

结果都是从62256.0开始变化奇怪了,于是我便查msdn,关于这个函数的使用:

Retrieves the current position of a spin button control.

int GetPos( ) const;
int GetPos32(
   LPBOOL lpbError = NULL 
) const;

Parameters

lpbError
A pointer to a boolean value that is set to zero if the value is successfully retrieved or non-zero if an error occurs. If this parameter is set to NULL, errors are not reported.

Return Value

The first version returns the 16-bit current position in the low-order word. The high-order word is nonzero if an error occurred.

The second version returns the 32-bit position.

Remarks

When it processes the value returned, the control updates its current position based on the caption of the buddy window. The control returns an error if there is no buddy window or if the caption specifies an invalid or out-of-range value.

Requirements

Header: afxcmn.h



这个一看就晓得了,GetPos32( )才可以实现32位的数据,而不带32的就只能得到16位,另外16就要问xp了,呵呵

把GetPos()改变为GetPos32( )一切ok啦。

不过在消息函数里面也可以不用上面的方法,用getbuddy()得到文本指针,再setwindowtext(m_strMystr)来显示。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: