CWnd::OnHScroll

当用户单击窗口的水平滚动条记录时,框架调用该成员函数。

afx_msg void OnHScroll( 
   UINT nSBCode, 
   UINT nPos, 
   CScrollBar* pScrollBar  
);

参数

  • nSBCode
    指定指示用户滚动请求的滚动条代码。 此参数可以是下列值之一:

    • SB_LEFT 滚动到最左侧。

    • SB_ENDSCROLL 结束滚动。

    • SB_LINELEFT 滚动。

    • SB_LINERIGHT 滚动权限。

    • SB_PAGELEFT 滚动一页。

    • SB_PAGERIGHT 滚动一页权限。

    • SB_RIGHT 滚动到最右边。

    • 为绝对位置的SB_THUMBPOSITION 滚动。 当前位置由 nPos 参数指定。

    • SB_THUMBTRACK 拖动到指定位置的滚动框。 当前位置由 nPos 参数指定。

  • nPos
    如果滚动条代码是 SB_THUMBPOSITIONSB_THUMBTRACK,指定滚动框位置;否则,未使用。 基于初始滚动大小,nPos 可以为负的,因此如果需要,转换到 int。

  • pScrollBar
    如果滚动消息来自滚动条控件,其中包含指向该控件。 如果用户单击窗口滚动条,此参数是 NULL。 指针可能是瞬态的,不应存储以供将来使用。

备注

提供反馈的应用程序通常使用 SB_THUMBTRACK 滚动条代码,在滚动框拖动时。

如果应用程序移动滚动条控件的内容,它还必须重置滚动框的位置具有 SetScrollPos 成员函数。

备注

此成员函数由框架调用提供您的应用程序处理Windows消息。当接收消息,参数传递给函数以反映结构接收的参数。如果调用此函数的基类实现,该实现将使用参数最初用消息您提供给函数而非参数。

示例

void CMdiView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
   // Get the minimum and maximum scroll-bar positions. 
   int minpos;
   int maxpos;
   GetScrollRange(SB_HORZ, &minpos, &maxpos); 
   maxpos = GetScrollLimit(SB_HORZ);

   // Get the current position of scroll box. 
   int curpos = GetScrollPos(SB_HORZ);

   // Determine the new position of scroll box. 
   switch (nSBCode)
   {
   case SB_LEFT:      // Scroll to far left.
      curpos = minpos;
      break;

   case SB_RIGHT:      // Scroll to far right.
      curpos = maxpos;
      break;

   case SB_ENDSCROLL:   // End scroll. 
      break;

   case SB_LINELEFT:      // Scroll left. 
      if (curpos > minpos)
         curpos--;
      break;

   case SB_LINERIGHT:   // Scroll right. 
      if (curpos < maxpos)
         curpos++;
      break;

   case SB_PAGELEFT:    // Scroll one page left.
   {
      // Get the page size. 
      SCROLLINFO   info;
      GetScrollInfo(SB_HORZ, &info, SIF_ALL);

      if (curpos > minpos)
      curpos = max(minpos, curpos - (int) info.nPage);
   }
      break;

   case SB_PAGERIGHT:      // Scroll one page right.
   {
      // Get the page size. 
      SCROLLINFO   info;
      GetScrollInfo(SB_HORZ, &info, SIF_ALL);

      if (curpos < maxpos)
         curpos = min(maxpos, curpos + (int) info.nPage);
   }
      break;

   case SB_THUMBPOSITION: // Scroll to absolute position. nPos is the position
      curpos = nPos;      // of the scroll box at the end of the drag operation. 
      break;

   case SB_THUMBTRACK:   // Drag scroll box to specified position. nPos is the
      curpos = nPos;     // position that the scroll box has been dragged to. 
      break;
   }

   // Set the new position of the thumb (scroll box).
   SetScrollPos(SB_HORZ, curpos);

   CView::OnHScroll(nSBCode, nPos, pScrollBar);
}

要求

Header: afxwin.h

请参见

参考

CWnd 类

层次结构图

CWnd::SetScrollPos

CWnd::OnVScroll

WM_HSCROLL