vc 滚动条使用

void CDIALOGNOSE::OnSize(UINT nType, int cx, int cy)
{
 CDialog::OnSize(nType, cx, cy);

 

  SCROLLINFO si; 
 int nVScrollMax = 0;
 m_nVScrollPos = m_nVPageSize = 0;

 if (cy < m_nViewHeight) {
  nVScrollMax = m_nViewHeight - 1;
  m_nVPageSize = cy;
  m_nVScrollPos = min (m_nVScrollPos, m_nViewHeight -
   m_nVPageSize - 1);
 }

 si.fMask = SIF_PAGE | SIF_RANGE | SIF_POS;
 si.nMin = 0;
 si.nMax =nVScrollMax;
 si.nPos = m_nVScrollPos;
 si.nPage = m_nVPageSize;

 SetScrollInfo (SB_VERT, &si, TRUE);
 // TODO: 在此处添加消息处理程序代码
}

 

int CDIALOGNOSE::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
 if (CDialog::OnCreate(lpCreateStruct) == -1)
  return -1;
 CClientDC dc (this);
 m_nCellWidth = dc.GetDeviceCaps (LOGPIXELSX);
 m_nCellHeight = dc.GetDeviceCaps (LOGPIXELSY) / 4;
 m_nRibbonWidth = m_nCellWidth / 2;
 m_nViewWidth = (26 * m_nCellWidth) + m_nRibbonWidth;
 m_nViewHeight = m_nCellHeight * 50;
 CRect rect;
 GetClientRect(&rect);
 //m_nViewWidth = (26 * m_nCellWidth) + m_nRibbonWidth;
 
 // TODO:  在此添加您专用的创建代码

 return 0;
}

 

void CDIALOGNOSE::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
 // TODO: 在此添加消息处理程序代码和/或调用默认值
 int nDelta;

 
  Compute the vertical scroll distance, or "delta."
 
 switch (nSBCode) {

 case SB_LINEUP:
  nDelta = -LINESIZE;
  break;

 case SB_PAGEUP:
  nDelta = -m_nVPageSize;
  break;

 case SB_THUMBTRACK:
  nDelta = (int) nPos - m_nVScrollPos;
  break;

 case SB_PAGEDOWN:
  nDelta = m_nVPageSize;
  break;

 case SB_LINEDOWN:
  nDelta = LINESIZE;
  break;
 case SB_BOTTOM:
  nDelta = heifht;
  break;
 default:
  return;
 }


 int nScrollPos = m_nVScrollPos + nDelta;
 int nMaxPos = m_nViewHeight - m_nVPageSize;

 if (nScrollPos < 0)
  nDelta = -m_nVScrollPos;
 else if (nScrollPos > nMaxPos)
  nDelta = nMaxPos - m_nVScrollPos;

 //
 // Update the scroll position and scroll the window.
 //
 if (nDelta != 0) {
  m_nVScrollPos += nDelta;
  SetScrollPos (SB_VERT, m_nVScrollPos, TRUE);
  ScrollWindow (0, -nDelta);
 }

 

 CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值