滑动条:

来源:互联网 发布:海拉尔二中分尸案 知乎 编辑:程序博客网 时间:2024/06/11 06:40

1.  GetScrollBarCtrl 

The CWnd implementation of this function simply returns NULL. Derived classes, such as CView, implement the described functionality.

在cwnd中是null,在view中才会有值

但可以直接用滑动条的函数,比如

GetScrollPos

http://blog.163.com/lvan100@yeah/blog/static/6811721420101176353748/

可参见



2. 可以在nc_paint中重绘




















/////////////////////////////////////////////


如果你试过用GetScrollBarCtrl()函数去获取对话框内自动的滚动条控件,那么你绝对是不能成功的。为什么呢?

MSDN 这样解释:

The CWnd implementation of this function simply returns NULL. (这个函数对于CWnd类只是简单的返回一个NULL值。)

Derived classes, such as CView, implement the described functionality.(除了一些如CView的类,才会实行函数声明的功能。)

呵呵!知道了吧。但是我们怎么操纵这样的滚动条呢?回答:直接操纵!即把对话框当做一个滚动条对象就ok了。

如下列代码:

BOOL C***Ctrl::OnInitDialog(){ CDialogEx::OnInitDialog();  SCROLLINFO sbinfo; sbinfo.fMask = SIF_ALL; sbinfo.nMax = 100; sbinfo.nMin = 0; sbinfo.nPage = 90; sbinfo.nPos = 0; SetScrollInfo(SB_VERT,&sbinfo,TRUE);  return TRUE;   
}
BOOL C***Ctrl::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt){ // TODO: 在此添加消息处理程序代码和/或调用默认值 int nflag = zDelta>0?1:-1; int nCurpos,nMin,nMax,nThumbWidth; SCROLLINFO siInfo; GetScrollInfo(SB_VERT,&siInfo); nCurpos = siInfo.nPos; nMin = siInfo.nMin; nMax = siInfo.nMax; nThumbWidth = siInfo.nPage; SetScrollPos(SB_VERT,nCurpos - nflag); int nScroll = nflag * 11; if (nCurpos+nThumbWidth < nMax && nCurpos !=0)  ScrollWindow(0,nScroll);   return CDialogEx::OnMouseWheel(nFlags, zDelta, pt);}

说实话,我也是写这篇文章的时候才真正读懂上面的两句引文。唉!