void CSkinVerticleScrollbar::OnMouseMove(UINT nFlags, CPoint point) { CRect clientRect; GetClientRect(&clientRect); if(bMouseDown) { nThumbTop = point.y-13; //-13 so mouse is in middle of thumb
double nMax = pTree->GetScrollLimit(SB_VERT); int nPos = pTree->GetScrollPos(SB_VERT); double nHeight = clientRect.Height()-98; double nVar = nMax; dbThumbInterval = nHeight/nVar; //figure out how many times to scroll total from top //then minus the current position from it int nScrollTimes = (int)((nThumbTop-36)/dbThumbInterval)-nPos; //grab the row height dynamically //so if the font size or type changes //our scroll will still work properly // CRect itemrect; // pTree->GetItemRect(0,&itemrect, LVIR_BOUNDS); // CSize size; // size.cx = 0; // size.cy = nScrollTimes*itemrect.Height();
老是弹回原处的问题,应该是你没有设置它的位置吧,用这个试一下SetScrollInfo。例:
scrollinfo.nPos = nPos;
SetScrollInfo(SB_VERT,&scrollinfo,SIF_ALL);
{
CRect clientRect;
GetClientRect(&clientRect); if(bMouseDown)
{
nThumbTop = point.y-13; //-13 so mouse is in middle of thumb
double nMax = pTree->GetScrollLimit(SB_VERT);
int nPos = pTree->GetScrollPos(SB_VERT); double nHeight = clientRect.Height()-98;
double nVar = nMax;
dbThumbInterval = nHeight/nVar; //figure out how many times to scroll total from top
//then minus the current position from it
int nScrollTimes = (int)((nThumbTop-36)/dbThumbInterval)-nPos; //grab the row height dynamically
//so if the font size or type changes
//our scroll will still work properly
// CRect itemrect;
// pTree->GetItemRect(0,&itemrect, LVIR_BOUNDS); // CSize size;
// size.cx = 0;
// size.cy = nScrollTimes*itemrect.Height();
// pTree->SetScrollTime(nScrollTimes); LimitThumbPosition(); Draw();
}
CStatic::OnMouseMove(nFlags, point);
}这是代码,int nPos = pTree->GetScrollPos(SB_VERT);总是得到零,设置pTree->SetScrollPos()也就没意义了!
帮忙!先谢谢了!
========================
你这样得到的值应该是pTree原来的滑动条的值,你并不是移动的它,因此它的值总是零,改变你现在重绘的滑动块的值应该不是在这里。在你的重绘代码里应该是