CWnd的滚动条的问题。

triout 2003-07-17 03:00:29
一个类CMyWnd继承了CWnd,在CMyWnd中,设置了滚动条(HSROLL),当CMyWnd对象MyWnd中的内容超出高度时,希望HSROLL能起到相应的作用,该如何实现?
...全文
415 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
daview 2003-09-09
  • 打赏
  • 举报
回复
揭贴
triout 2003-07-24
  • 打赏
  • 举报
回复
应该不是NULL,没有检测。
思危 2003-07-23
  • 打赏
  • 举报
回复
pScrollBar为NULL吗?
triout 2003-07-23
  • 打赏
  • 举报
回复
up
triout 2003-07-21
  • 打赏
  • 举报
回复
up
triout 2003-07-20
  • 打赏
  • 举报
回复
up
mischaiwei 2003-07-18
  • 打赏
  • 举报
回复
CSrcollView
triout 2003-07-18
  • 打赏
  • 举报
回复
this->SetScrollRange(SB_VERT,nHeight,nTop,TRUE);
我已经指定了。
而且改成:
this->SetScrollRange(SB_VERT,0,nTop,TRUE);
也一样。
暗黑帝国 2003-07-18
  • 打赏
  • 举报
回复
如果是动态创建那要自己设置滚动条的范围SetScrollRange();
triout 2003-07-18
  • 打赏
  • 举报
回复
我在CMyWnd的自定义的Create代码:
int CMyWnd::Create(...)
{
...
int hr=CWnd::OnCreate(lpCreateStruct);
//此处添加了若干的EDIT、STATIC等子控件,已经超出CMyWnd的Height(CRect中定义的)
this->EnableScrollBar(SB_VERT,ESB_ENABLE_BOTH);
this->SetScrollRange(SB_VERT,nHeight,nTop,TRUE);
//这里nHeight为创建CMyWnd的高度,即CRect中指定的高度,nTop为CMyWnd中放置的内容的总高度。
}

消息映射:
BEGIN_MESSAGE_MAP(CDataTranPanel, CWnd)
//{{AFX_MSG_MAP(CMainFrame)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code !
ON_WM_CREATE()
ON_WM_VSCROLL()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

我的处理函数:

void CMyWnd::OnVScroll(UINT nSBCode,UINT nPos,CScrollBar* pScrollBar)
{
int nMinPos;
int nMaxPos;
int nLimit;
SCROLLINFO ScrollInfo;
//以下是报错语句
//还有后面的类似的凡是使用了pScrollBar的地方都会导致异常
pScrollBar->GetScrollInfo(&ScrollInfo);
nMinPos=ScrollInfo.nMin;
nMaxPos=ScrollInfo.nMax;
//pScrollBar->GetScrollRange((LPINT)&nMinPos, (LPINT)&nMaxPos);
//nLimit = pScrollBar->GetScrollLimit();
CWnd::OnVScroll(nSBCode, nPos, pScrollBar);
return;
if(nLimit<nMaxPos)
nMaxPos=nLimit;

int curpos = pScrollBar->GetScrollPos();
AfxMessageBox("ABC");

switch (nSBCode)
{
case SB_TOP: // Scroll to far left.
curpos = nMinPos;
break;

case SB_BOTTOM: // Scroll to far right.
curpos = nMaxPos;
break;

case SB_ENDSCROLL: // End scroll.
break;

case SB_LINEUP: // Scroll left.
if (curpos > nMinPos)
curpos-=10;
break;

case SB_LINEDOWN: // Scroll right.
if (curpos < nMaxPos)
curpos+=10;
break;

case SB_PAGEUP: // Scroll one page left.
/*{
// Get the page size.
SCROLLINFO info;
pScrollBar->GetScrollInfo(&info, SIF_ALL);

if (curpos > nMinPos)
curpos = max(nMinPos, curpos - (int) info.nPage);
}*/
break;

case SB_PAGEDOWN: // Scroll one page right.
/*{
// Get the page size.
SCROLLINFO info;
pScrollBar->GetScrollInfo(&info, SIF_ALL);

if (curpos < nMaxPos)
curpos = min(nMaxPos, curpos + (int) info.nPage);
}*/
break;

case SB_THUMBPOSITION: // Scroll to absolute position. nPos is the position
curpos = nPos; // of the scroll box at the end of the drag operation.
break;

case SB_THUMBTRACK: // Drag scroll box to specified position. nPos is the
curpos = nPos; // position that the scroll box has been dragged to.
break;
}
// Set the new position of the thumb (scroll box).
//pScrollBar->SetScrollPos(curpos);

CWnd::OnVScroll(nSBCode, nPos, pScrollBar);
}
Cline 2003-07-17
  • 打赏
  • 举报
回复
设置了滚动条(HSROLL),当CMyWnd对象MyWnd中的内容超出高度时

HSROLL<->高度
思危 2003-07-17
  • 打赏
  • 举报
回复
我要回家了,明天再说
思危 2003-07-17
  • 打赏
  • 举报
回复
判断大小并设置SCROLL,处理WM_HSCROLL消息

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧