Spin Control 和 Slider Control 的用法

来源:互联网 发布:淘宝 欧丽运动是正品吗 编辑:程序博客网 时间:2024/04/29 03:48


Spin Control:

 Spin Control比较简单,简单介绍消息处理如下:

afx_msg void OnDeltaposSpin1(NMHDR *pNMHDR, LRESULT *pResult);
ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN1, &CMy2005DlgDlg::OnDeltaposSpin1)
void CMy2005DlgDlg::OnDeltaposSpin1(NMHDR *pNMHDR, LRESULT *pResult)
{
 LPNMUPDOWN pNMUpDown = reinterpret_cast<LPNMUPDOWN>(pNMHDR);
 // TODO: 在此添加控件通知处理程序代码
 *pResult = 0;
}

点击上下箭头时,可根据pNMUpDown的内容判定用户的操作,含义如下:

typedef struct _NM_UPDOWN {
  NMHDR hdr;
  int iPos;
  int iDelta;
} NMUPDOWN, FAR* LPNMUPDOWN;
Members
hdr 
NMHDR structure that contains additional information about the message. 
iPos 
Signed integer value that represents the up-down control's current position. 
iDelta 
Signed integer value that represents the proposed change in the up-down control's position. 
  
Slider Control:

1)加入控件变量:
CSliderCtrl m_sliderCtrl; 
DDX_Control(pDX, IDC_SLIDER1, m_sliderCtrl);
2)事件处理
afx_msg void OnNMCustomdrawSlider1(NMHDR *pNMHDR, LRESULT *pResult);
ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDER1, &CMy2005DlgDlg::OnNMCustomdrawSlider1)
void CMy2005DlgDlg::OnNMCustomdrawSlider1(NMHDR *pNMHDR, LRESULT *pResult)
{
 LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
 // TODO: 在此添加控件通知处理程序代码
 int pos = m_sliderCtrl.GetPos();
 *pResult = 0;
}

3)常用控制

//Sets the range (minimum and maximum positions) for the slider in a slider control.
 m_sliderCtrl.SetRange(0,100,1);

//Sets the current position of the slider in a slider control.
 m_sliderCtrl.SetPos(20);

//Sets the position of a tick mark in a slider control.
     m_sliderCtrl.SetTic(30);

// Sets the frequency with which tick marks are displayed in a slider.
     m_sliderCtrl.SetTicFreq(10);

注意:要显示刻度线,Auto Ticks要为TRUE, Tick Marks要为TRUE