防止鼠标滚轮滚动控件
我正在使用MFC库开发应用程序,并且当前正在尝试防止用户在滚动鼠标滚轮时意外更改其中一个组合框控件.
I am developing an application using the MFC library and I am currently trying to prevent the user accidentally changing one of the combo box controls when they are scrolling the mouse wheel.
我正在寻找一种解决方案,而不必从CComboBox
类派生新类并防止鼠标滚动到那里.
I am looking for a solution without deriving a new class from the CComboBox
class and preventing the mouse scrolling there.
我对系统的理解是Windows将WM_MOUSEWHEEL
消息传递给处理它的组合框控件(滚动组合框),然后将其沿父控件链传播(因此将它们传播到我的CFormView
等等),这意味着我无法通过在表单视图中捕获事件来阻止滚动.
My understanding of the system is that Windows passes the WM_MOUSEWHEEL
message to the Combo box control which handles it (scrolling the combo box) and then this is propagated up the chain of parent controls (so them to my CFormView
etc.), which means I cannot prevent the scrolling by capturing the event in my form view.
有人可以解决这个问题吗?预先感谢!
Does anyone have a solution to this problem? Thanks in advance!
在主窗口类中重写PreTranslateMessage处理程序,然后查找WM_MOUSEWHEEL消息.将PreTranslateMessage处理程序中的pMsg-> hwnd处理与组合框处理进行比较,如果找到,则将消息过滤掉.
Override the PreTranslateMessage handler in the main window class and look for WM_MOUSEWHEEL messages. Compare the pMsg->hwnd handle in PreTranslateMessage handler with the combobox handle, if found, filter the messages away.