在视图类的ONCreate中
m_spin.Create(WS_CHILD|WS_VISIBLE|UDS_ARROWKEYS|UDS_ALIGNRIGHT|UDS_WRAP,CRect(0,0,0,0),this,2);
m_spin.SetBuddy(&m_edit);
m_spin.SetRange(100,1);
m_spin.SetPos(10);然后在Onlbuttondown中:
CString str;;
str.Format("%d",m_spin.GetPos());
MessageBox(str);
发现m_spin.GetPos的值为65536,根本不对,但是如果在创建时指定UDS_SETBUDDYINT样式,那么一切正常,
这是问什么呢???????????????

解决方案 »

  1.   

    没有指定UDS_SETBUDDYINT,那么向上箭头是减少的,向下箭头是增加的。
      

  2.   

    UDS_SETBUDDYINT
    当位置改变时,使控件设置伙伴窗口的文本(使用WM_SETTEXT消息)。文本是按十进制或十六进制格式化后的位置值。 
      

  3.   

    我还没有按箭头呢?getPos就不对了,难道我的SetPos不起作用吗????没有UDS_SETBUDDYINT就不行吗??
      

  4.   

    用SetRange32、SetPos32、GetPos32试试。
      

  5.   

    没有SetPos32、GetPos32,只有SetRange32.试了,不行
      

  6.   

    你用的是VC6?
    你再看看GetPos的值是65536还是65546?如果是65546,可以将GetPos的返回值强制转换为short型来用。
    另外,你为何不用UDS_SETBUDDYINT风格?
      

  7.   

    1.对我用的是VC6.2.是65546.确实将其强制转换为short型就变成正常了.我又看了msdn.他说返回的Pos放在低位字.所以转换为short确实没错.但是他说如果高位字为1,就说明出错了.那这么看来我的程序出错了,但是哪里有错呢????3.是这样的我想调整的是小数,不是整数,正常情况下他只能显示整数,所以我这样写:void CShiyanView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
    {
    // TODO: Add your message handler code here and/or call default
    CSpinButtonCtrl *p=(CSpinButtonCtrl*)pScrollBar;
    CString str; if(p==&m_spin){
    str.Format("%f",m_spin.GetPos()*0.1);
    m_edit.SetWindowText(str);
    }

    CView::OnVScroll(nSBCode, nPos, pScrollBar);
    }
    这样就可以变成小数了,但是就在m_spin.GetPos()出了问题.所以就发了这个帖子.
      

  8.   

    更改后的源码如下:
    int CShiyanView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
    {
    if (CView::OnCreate(lpCreateStruct) == -1)
    return -1;

    // TODO: Add your specialized creation code here
    m_edit.Create(WS_CHILD|WS_VISIBLE|WS_BORDER,CRect(100,100,180,140),this,1);
    m_edit.SetWindowText("1.0");
    m_spin.Create(WS_CHILD|WS_VISIBLE|UDS_ARROWKEYS|UDS_ALIGNRIGHT|UDS_WRAP,CRect(0,0,0,0),this,2);
    m_spin.SetBuddy(&m_edit);
    m_spin.SetRange(100,10);
    m_spin.SetPos(10);
    return 0;
    }void CShiyanView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
    {
    // TODO: Add your message handler code here and/or call default
    CSpinButtonCtrl *p=(CSpinButtonCtrl*)pScrollBar;
    CString str; if(p==&m_spin){
    str.Format("%.1f",((short)m_spin.GetPos())*0.1);
    m_edit.SetWindowText(str);
    }

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

  9.   

    以下摘自MSDN:
    When processing this message, the up-down control updates its current position based on the caption of the buddy window. The up-down control returns an error if there is no buddy window or if the caption specifies an invalid or out-of-range value. Also, an error flag is set in the HIWORD of the return if the control is created without the UDS_SETBUDDYINT style, even though it returns a valid position value in the LOWORD of the return.
      

  10.   

    我的msdn是6.0版的版本比较低,上面的说明不太一样.现在知道原因了.但是我也知道我那样来处理小数不行.如果只通过按上下的按钮箭头,那么没问题,但是一但我用键盘在edit输入小数,然后在用按钮箭头的话就会出现问题.不知道有没有其他方法来处理小数的.问题有点多啊.但是先给分把