gpt4 book ai didi

visual-c++ - 更改特定 slider 时的事件

转载 作者:行者123 更新时间:2023-12-03 01:00:12 25 4
gpt4 key购买 nike

我正在编写一个基于 C++ MFC 对话框的应用程序,我的程序有很多 slider 。我希望程序根据用户正在更改的 slider 来调用函数。我尝试使用 GetPos() 但到目前为止还没有取得多大成功。有更简单的方法吗?

消息映射:

BEGIN_MESSAGE_MAP(CSerialPortDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
//ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
ON_BN_CLICKED(IDC_READ_COMM, OnBnClickedReadComm)
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_WRITE, OnBnClickedWrite)
//ON_CBN_SELCHANGE(IDC_SENSORS, OnCbnSelchangeSensors)
//ON_CBN_SELCHANGE(IDC_SENSOR_LIST, OnCbnSelchangeSensorList)
ON_BN_CLICKED(IDC_GO, OnGo)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_KILL_TIMER, OnBnClickedKillTimer)
ON_BN_CLICKED(IDC_READ_TIMER, OnBnClickedReadTimer)
ON_BN_CLICKED(IDC_WRITE_COMM, OnBnClickedWriteComm)
ON_BN_CLICKED(IDC_TERMINATE, OnBnClickedTerminate)
ON_BN_CLICKED(IDC_RUN, OnBnClickedRun)
ON_CONTROL(NM_CLICK,IDC_BOOM_SLIDER, Write_Boom)
ON_CONTROL(NM_CLICK,IDC_PITCH_SLIDER, Write_Pitch)
END_MESSAGE_MAP()

...

最佳答案

slider 控件在水平或垂直滚动​​时发送 WM_HSCROLL 或 WM_VSCROLL 通知。在对话框中捕获它们,然后您可以调用所需的函数,具体取决于发送通知的人。

BEGIN_MESSAGE_MAP(CMyDlg, CDialog)  
//...
ON_WM_HSCROLL()
//...
END_MESSAGE_MAP()


//////////////////////////
// nSBCode: The operation performed on the slider
// nPos: New position of the slider
// pScrollBar: The scrollbar (slider ctrl in this case) that sent the notification

void CMyDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
CSliderCtrl* pSlider = reinterpret_cast<CSliderCtrl*>(pScrollBar);

// Check which slider sent the notification
if (pSlider == &c_Slider1)
{
}
else if (pSlider == &c_Slider2)
{
}

// Check what happened
switch(nSBCode)
{
case TB_LINEUP:
case TB_LINEDOWN:
case TB_PAGEUP:
case TB_PAGEDOWN:
case TB_THUMBPOSITION:
case TB_TOP:
case TB_BOTTOM:
case TB_THUMBTRACK:
case TB_ENDTRACK:
default:
break;
}

//...
}
`

关于visual-c++ - 更改特定 slider 时的事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7269834/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com