OnVScroll :从 CSpinButtonCtrl 或 Vertical ScrollBar 调用?

OnVScroll : invoked from CSpinButtonCtrl or Vertical ScrollBar?

我有一个派生的 MFC CFormView class (CMyFormView),我必须实现我自己的 OnVScroll 功能。

我的CMyFormView用于几个对话框资源,主要是为了重新实现OnCtlColor()功能。某些对话框包含 CSpinButtonCtrl 控件。

我的问题:
调用 OnVScroll 函数时,我无法知道 Windows 消息是来自 CSpinButtonCtrl 还是来自滚动条。

void CMyFormView :: OnVScroll (UINT nSBCode, UINT nPos, CScrollBar * pScrollBar)
{
// message comes from CSpinButtonCtrl or VscrollBare ?
}  

我无法使用控件的CSpinButtonCtrl ID (dlgitem),因为它们太多了

问题:
如何知道消息是来自 CSpinButtonCtrl 还是来自滚动条?

环境详细信息:

如果 OnVScroll 处理程序通过 window 的(框架提供的)滚动条中的 操作被调用 ,则 pScrollBar参数将为 NULL;如果它来自控件,则它不会是 NULL。来自 CWnd Documentation:

pScrollBar
If the scroll message came from a scroll-bar control, contains a pointer to the control. If the user clicked a window's scroll bar, this parameter is NULL. The pointer may be temporary and should not be stored for later use.

因此,您可以简单地检查 NULL 值:

void CMyFormView :: OnVScroll (UINT nSBCode, UINT nPos, CScrollBar * pScrollBar)
{
    if (!pScrollBar) {
        // From window's scrollbar...
    }
    else {
        // From a control...
    }
}