在对话框中添加两个CSliderCtrl控件分别为上限和下限,其中上限要始终大于下限值,ID分别为 IDC_SL_MINLEVEL、IDC_SL_MAXLEVEL。
(1)添加消息函数声明
afx_msg void OnNMCustomdrawSlMinlevel(NMHDR *pNMHDR, LRESULT *pResult);
afx_msg void OnNMCustomdrawSlMaxlevel(NMHDR *pNMHDR, LRESULT *pResult);
(2)添加消息映射
ON_NOTIFY(NM_CUSTOMDRAW, IDC_SL_MINLEVEL, &CDTIS_FileOperateDlg::OnNMCustomdrawSlMinlevel)
ON_NOTIFY(NM_CUSTOMDRAW, IDC_SL_MAXLEVEL, &CDTIS_FileOperateDlg::OnNMCustomdrawSlMaxlevel)
(3)添加函数实现:
void CDTIS_FileOperateDlg::OnNMCustomdrawSlMinlevel(NMHDR *pNMHDR, LRESULT *pResult)
{
UpdateData(TRUE);
LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
CSliderCtrl* pMinSlider = (CSliderCtrl*)this->GetDlgItem(IDC_SL_MINLEVEL);
CSliderCtrl* pMaxSlider = (CSliderCtrl*)this->GetDlgItem(IDC_SL_MAXLEVEL);
if( pMaxSlider->GetPos() < pMinSlider->GetPos() )
{
pMaxSlider->SetPos(pMinSlider->GetPos() + 1);
// 此处不能用,有刷新问题 pMinSlider ->SetPos(pMaxSlider ->GetPos() - 1);
}
*pResult = 0;
}
void CDTIS_FileOperateDlg::OnNMCustomdrawSlMaxlevel(NMHDR *pNMHDR, LRESULT *pResult)
{
UpdateData(TRUE);
LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
CEdit* pMaxLevel = (CEdit*) this->GetDlgItem(IDC_MAXLEVEL);
CEdit* pMinLevel = (CEdit*) this->GetDlgItem(IDC_MINLEVEL);
CSliderCtrl* pMinSlider = (CSliderCtrl*)this->GetDlgItem(IDC_SL_MINLEVEL);
CSliderCtrl* pMaxSlider = (CSliderCtrl*)this->GetDlgItem(IDC_SL_MAXLEVEL);
CString sTemp;
if( pMaxSlider->GetPos() < pMinSlider->GetPos() )
{
pMinSlider->SetPos(pMaxSlider->GetPos() - 1);
// 此处不能用,有刷新问题 pMaxSlider->SetPos(pMinSlider ->GetPos() + 1);
}
sTemp.Format("%d",pMaxSlider->GetPos());
pMaxLevel->SetWindowText(sTemp);
*pResult = 0;
}