vc 如何为VIEW添加滚动条

建立了一个多文档工程,请问如何向view类添加滚动条?
2024-12-02 19:58:27
推荐回答(1个)
回答1:

滚动条必须处理-_-!(不能偷懒)如下↓:
SetScrollRange(hDlg,SB_VERT,0,40,FALSE); // 多少行
SetScrollPos(hDlg, SB_VERT,0,TRUE); //起点行

其实就一个CASE
case WM_VSCROLL:
{
switch(LOWORD(wParam))
{
case SB_LINEDOWN: //通知码
nVScrollPos ++; //向下
break;
case SB_LINEUP:
nVScrollPos --;//向上
break;
}
if(nVScrollPos<0) // 。。。。。。。。。
nVScrollPos = 0;
else if(nVScrollPos>40)
nVScrollPos = 40;
SCROLLINFO si; // 又一结构体

===================================SCROLLINFO=====================================
typedef struct tagSCROLLINFO {
UINT cbSize; -- Specifies the size, in bytes, of this structure.
UINT fMask; -- Specifies the scroll bar parameters to set or retrieve(有6个参数类型)
int nMin; -- Specifies the minimum scrolling position
int nMax; -- Specifies the maximum scrolling position.
UINT nPage; -- Specifies the page size
int nPos; -- Specifies the position of the scroll box
int nTrackPos; -- Specifies the immediate position of a scroll box that the user is dragging.
} SCROLLINFO;
====================================================================================

ZeroMemory(&si, sizeof(SCROLLINFO));
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_TRACKPOS;

// Call GetScrollInfo to get current tracking
// position in si.nTrackPos

if (!GetScrollInfo(hDlg, SB_VERT, &si) )
break;

if(nVScrollPos!= si.nPos)
{
SetScrollPos(hDlg, SB_VERT,nVScrollPos,TRUE);
InvalidateRect(hDlg,NULL,TRUE); ============repaint
}
break;
}