怎么使Dialog带有滚动条

怎么使Dialog带有滚动条,第1张

void CXXDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)

{

// TODO: Add your message handler code here and/or call default

SCROLLINFO scrollinfo

GetScrollInfo(SB_VERT,&scrollinfo,SIF_ALL)

switch (nSBCode)

{

case SB_BOTTOM:

ScrollWindow(0,(scrollinfo.nPos-scrollinfo.nMax)*10)

scrollinfo.nPos = scrollinfo.nMax

SetScrollInfo(SB_VERT,&scrollinfo,SIF_ALL)

break

case SB_TOP:

ScrollWindow(0,(scrollinfo.nPos-scrollinfo.nMin)*10)

scrollinfo.nPos = scrollinfo.nMin

SetScrollInfo(SB_VERT,&scrollinfo,SIF_ALL)

break

case SB_LINEUP:

scrollinfo.nPos -= 1

if (scrollinfo.nPos<scrollinfo.nMin)

{

scrollinfo.nPos = scrollinfo.nMin

break

}

SetScrollInfo(SB_VERT,&scrollinfo,SIF_ALL)

ScrollWindow(0,10)

break

case SB_LINEDOWN:

scrollinfo.nPos += 1

if (scrollinfo.nPos>scrollinfo.nMax)

{

scrollinfo.nPos = scrollinfo.nMax

break

}

SetScrollInfo(SB_VERT,&scrollinfo,SIF_ALL)

ScrollWindow(0,-10)

break

case SB_PAGEUP:

scrollinfo.nPos -= 5

if (scrollinfo.nPos<scrollinfo.nMin)

{

scrollinfo.nPos = scrollinfo.nMin

break

}

SetScrollInfo(SB_VERT,&scrollinfo,SIF_ALL)

ScrollWindow(0,10*5)

break

case SB_PAGEDOWN:

scrollinfo.nPos += 5

if (scrollinfo.nPos>scrollinfo.nMax)

{

scrollinfo.nPos = scrollinfo.nMax

break

}

SetScrollInfo(SB_VERT,&scrollinfo,SIF_ALL)

ScrollWindow(0,-10*5)

break

case SB_ENDSCROLL:

// MessageBox("SB_ENDSCROLL")

break

case SB_THUMBPOSITION:

// ScrollWindow(0,(scrollinfo.nPos-nPos)*10)

// scrollinfo.nPos = nPos

// SetScrollInfo(SB_VERT,&scrollinfo,SIF_ALL)

break

case SB_THUMBTRACK:

ScrollWindow(0,(scrollinfo.nPos-nPos)*10)

scrollinfo.nPos = nPos

SetScrollInfo(SB_VERT,&scrollinfo,SIF_ALL)

break

}

CDialog::OnVScroll(nSBCode, nPos, pScrollBar)

}

void CXXDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)

{

// TODO: Add your message handler code here and/or call default

SCROLLINFO scrollinfo

GetScrollInfo(SB_HORZ,&scrollinfo,SIF_ALL)

switch (nSBCode)

{

case SB_LEFT:

ScrollWindow((scrollinfo.nPos-scrollinfo.nMin)*10,0)

scrollinfo.nPos = scrollinfo.nMin

SetScrollInfo(SB_HORZ,&scrollinfo,SIF_ALL)

break

case SB_RIGHT:

ScrollWindow((scrollinfo.nPos-scrollinfo.nMax)*10,0)

scrollinfo.nPos = scrollinfo.nMax

SetScrollInfo(SB_HORZ,&scrollinfo,SIF_ALL)

break

case SB_LINELEFT:

scrollinfo.nPos -= 1

if (scrollinfo.nPos<scrollinfo.nMin)

{

scrollinfo.nPos = scrollinfo.nMin

break

}

SetScrollInfo(SB_HORZ,&scrollinfo,SIF_ALL)

ScrollWindow(10,0)

break

case SB_LINERIGHT:

scrollinfo.nPos += 1

if (scrollinfo.nPos>scrollinfo.nMax)

{

scrollinfo.nPos = scrollinfo.nMax

break

}

SetScrollInfo(SB_HORZ,&scrollinfo,SIF_ALL)

ScrollWindow(-10,0)

break

case SB_PAGELEFT:

scrollinfo.nPos -= 5

if (scrollinfo.nPos<scrollinfo.nMin)

{

scrollinfo.nPos = scrollinfo.nMin

break

}

SetScrollInfo(SB_HORZ,&scrollinfo,SIF_ALL)

ScrollWindow(10*5,0)

break

case SB_PAGERIGHT:

scrollinfo.nPos += 5

if (scrollinfo.nPos>scrollinfo.nMax)

{

scrollinfo.nPos = scrollinfo.nMax

break

}

SetScrollInfo(SB_HORZ,&scrollinfo,SIF_ALL)

ScrollWindow(-10*5,0)

break

case SB_THUMBPOSITION:

break

case SB_THUMBTRACK:

ScrollWindow((scrollinfo.nPos-nPos)*10,0)

scrollinfo.nPos = nPos

SetScrollInfo(SB_HORZ,&scrollinfo,SIF_ALL)

break

case SB_ENDSCROLL:

break

}

CDialog::OnHScroll(nSBCode, nPos, pScrollBar)

}

在窗口界面编辑器里拖上去画出来就行了。

如果要纯代码生成的话,就在OnInitDialog里:

比如构造一个列表框CListBox

那么在全局区或窗体类里添加CListBox对象为成员变量

CListBox

m_listbox

然后调用Create方法

mlistbox.Create()具体参数怎么写看MSDN或百度


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11465583.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-16
下一篇 2023-05-16

发表评论

登录后才能评论

评论列表(0条)

保存