控制滚动条

来源:清泛编译     2016-05-23 13:43:54    人气:     我有话说( 0 人参与)

1.属性页的添加:创建对话框的类,该类要从CpropertyPage继承;然后在要添加该对话框为 属性页的类(头文件)里创建CpropertySheet类的一

12. 控制滚动条

BOOL CDiagramShowView::PreTranslateMessage(MSG* pMsg) 

"CFileTreeDoc* pDoc = (CFileTreeDoc*)GetDocument();
"CPoint point = GetScrollPosition();
"
"if(pMsg->message == WM_KEYDOWN) 
"{ 
""switch(pMsg->wParam) 
""{ 
""case VK_LEFT:
"""if( point.x > 10)
"""{
""""EndPoint.x = EndPoint.x - 10;
""""EndPoint.y = EndPoint.y;
"""}
"""else
"""{
""""EndPoint.x = 0;
""""EndPoint.y = EndPoint.y;
"""}
"""ScrollToPosition(EndPoint);
"""InvalidateRect(NULL,TRUE);
"""break;
""case VK_RIGHT:
"""if( point.x < pDoc->intDiagramColumnCount * pDoc->intColumnWidth - 10 )
"""{
""""EndPoint.x = EndPoint.x + 10;
""""EndPoint.y = EndPoint.y;
"""}
"""else
"""{
""""EndPoint.y = pDoc->intDiagramColumnCount * pDoc->intColumnWidth;
""""EndPoint.x = EndPoint.x;
"""}
"""ScrollToPosition(EndPoint);
"""InvalidateRect(NULL,TRUE);
"""break;
""case VK_UP:
"""if( point.y > 10)
"""{
""""EndPoint.y = EndPoint.y - 10;
""""EndPoint.x = EndPoint.x;
"""}
"""else
"""{
""""EndPoint.y = 0;
""""EndPoint.x = EndPoint.x;
"""}
"""ScrollToPosition(EndPoint);
"""InvalidateRect(NULL,TRUE);
"""break;
""case VK_DOWN:
"""if( point.y < pDoc->intDiagramRowCount * pDoc->intRowHeight - 10 )
"""{
""""EndPoint.y = EndPoint.y + 10;
""""EndPoint.x = EndPoint.x;
"""}
"""else
"""{
""""EndPoint.y = pDoc->intDiagramRowCount * pDoc->intRowHeight;
""""EndPoint.x = EndPoint.x;
"""}
"""ScrollToPosition(EndPoint);
"""InvalidateRect(NULL,TRUE);
"""break;
""default:
"""break;
""} 
"} 
"return FALSE;



// 通过正负号判断是向上还是向下滚动
if(zDelta==120) 
向上滚动
if(zDelta==-120)
向下滚动

BOOL CDiagramShowView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt) 
{
"CFileTreeDoc* pDoc = (CFileTreeDoc*)GetDocument();
"CPoint point = GetScrollPosition();
"
"if(zDelta==120)
"{
""if( point.y >= 20 )
""{
"""EndPoint.x = point.x;
"""EndPoint.y = point.y;
"""
"""EndPoint.x = EndPoint.x;
"""EndPoint.y = EndPoint.y - 20;
""}
""else
""{
"""EndPoint.x = EndPoint.x;
"""EndPoint.y = 0;
""}
"}
"
"if(zDelta==-120)
"{
""if( point.y <= pDoc->intDiagramRowCount * pDoc->intRowHeight - 20 )
""{
"""EndPoint.x = point.x;
"""EndPoint.y = point.y;
"""
"""EndPoint.x = EndPoint.x;
"""EndPoint.y = EndPoint.y + 20;
""}
""else
""{
"""EndPoint.x = EndPoint.x;
"""EndPoint.y = EndPoint.y;
""}
"}
"
"ScrollToPosition(EndPoint);
"InvalidateRect(NULL,TRUE);
"return CScrollView::OnMouseWheel(nFlags, zDelta, pt);
}

本文导航

MFC 总结 技巧

本文源自互联网,采用知识共享署名-非商业性使用 4.0 国际许可协议进行许可,
版权归原作者,如有问题请联系service@tsingfun.com (编辑:admin)
分享到: