Usage of the CScrollView class to add scrolling functionality to your application By VGirish Step by step usage of the CScrollView class to add scrolling to your application http://codeproject.com/docview/cscrollview.asp
Tracking The Mouse In A View By John Simmons / outlaw programmer Track a mouse click, even in a scrolled view http://codeproject.com/docview/regiontracker.asp
void CGraphView::AutoScroll(UINT nRefMessage)
{ //当按下鼠标左键拖动出客户区时,窗口自动滚动
MSG msg;
CPoint ptScrollPos;
CPoint ptDevScrollPos;
CPoint ptCursorPos;
CRect rc;
long dx,dy;
SIZE sizeTotal;
SIZE sizePage;
SIZE sizeLine;
int nMapMode;
int nMapFactor;
int xMin;
int xMax;
int yMin;
int yMax; msg.message=0;
SetCapture(); //捕获鼠标
GetDeviceScrollSizes(nMapMode,sizeTotal,sizePage,sizeLine);
GetScrollRange(SB_HORZ,&xMin,&xMax);
GetScrollRange(SB_VERT,&yMin,&yMax);
while(msg.message!=nRefMessage)
{
if(PeekMessage(&msg,0,0,0,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
} ptScrollPos=GetScrollPosition();
ptDevScrollPos=GetDeviceScrollPosition();
GetCursorPos(&ptCursorPos);
ScreenToClient(&ptCursorPos);
GetClientRect(&rc);
dx=0L;
dy=0L; if((ptCursorPos.y<0)&&(ptDevScrollPos.y!=yMin))
dy=min(-sizeLine.cy,max(-sizePage.cy,(ptCursorPos.y/10)*sizeLine.cy));
else if((ptCursorPos.y>rc.bottom)&&(ptDevScrollPos.y!=yMax))
dy=max(sizeLine.cy,min(sizePage.cy,
((ptCursorPos.y-rc.bottom)/10)*sizeLine.cy));
if((ptCursorPos.x<0)&&(ptDevScrollPos.x!=xMin))
dx=min(-sizeLine.cx,max(-sizePage.cx,(ptCursorPos.x/10)*sizeLine.cx));
else if((ptCursorPos.x>rc.right)&&(ptDevScrollPos.x!=xMax))
dx=max(sizeLine.cx,min(sizePage.cx,
((ptCursorPos.x-rc.right)/10)*sizeLine.cx));
if((dx!=0)||(dy!=0))
{
nMapFactor=(nMapMode==MM_TEXT)?1:-1;
ptScrollPos.y+=(int)dy*nMapFactor;
ptScrollPos.x+=(int)dx;
ScrollToPosition(ptScrollPos);
}
}
ReleaseCapture();}//使用自动滚动函数
void CGraphView::OnLButtonDown(UINT nFlags, CPoint point)
{
...
AutoScroll(WM_LBUTTONUP);
}
By VGirish Step by step usage of the CScrollView class to add scrolling to your application
http://codeproject.com/docview/cscrollview.asp
By John Simmons / outlaw programmer Track a mouse click, even in a scrolled view
http://codeproject.com/docview/regiontracker.asp