如何去掉或隐藏树视图控件的两个滚动条,但可响应消息滚动,难题挑战高手!!!300分

jeanswest 2003-05-21 06:41:55
各位高手,我想去掉或隐藏CTreeCtl的两个滚动条,但仍然可用按钮等手段触发消息让其滚动。当然不用CTreeCtrl控件,用SDK实现也可以。
本人发现若一开始用
DWORD dwStyle = TVS_NOSCROLL;来去掉滚动,
之后无法令滚动条响应滚动消息。
若一开始不用TVS_NOSCROLL,后面无法实现去掉两个滚动条,只能去掉一个,
垂直SB_VERT 或 水平SB_HORZ.我用过许多去滚动条的方法,比如:
ShowScrollBar(m_tree->m_hWnd, SB_HORZ, FALSE);
ShowScrollBar(m_tree->m_hWnd, SB_VERT, FALSE);
ShowScrollBar(m_tree->m_hWnd, SB_BOTH, FALSE);

tree->ModifyStyle(TVS_NOSCROLL, NULL, NULL);
tree->ModifyStyle(WS_HSCROLL, NULL, NULL);
tree->ModifyStyle(WS_VSCROLL, NULL, NULL);

m_tree->ModifyStyle(0, ~WS_HSCROLL, 0);
m_tree->ModifyStyle(0, ~WS_VSCROLL, 0);
m_tree->ModifyStyle(0, ~WS_HSCROLL | ~WS_VSCROLL, 0);

DWORD dwCurStyle = GetWindowLong(m_tree->m_hWnd, GWL_STYLE);
SetWindowLong(m_tree->m_hWnd, GWL_STYLE, dwCurStyle & ~WS_HSCROLL);

SetScrollRange(m_tree->m_hWnd, SB_HORZ, 0, 0, FALSE);

等等,都不行。
是否方法不对?或者要用其他的方法处理?请赐教。300分,多贴送分。
...全文
424 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
jeanswest 2003-05-26
  • 打赏
  • 举报
回复
问题我已解决。

用这样的方法:

ModifyStyle(hwndTV, TVS_NOSCROLL, 0, NULL);
::SendMessage(hwndTV, WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0), 0);
ModifyStyle(hwndTV, 0, TVS_NOSCROLL, NULL);
::ShowScrollBar(hwndTV, SB_BOTH, FALSE);

当然还是要感谢 cxjlw(老为) 、BinaryPoet(二进制诗人) 和关心的各位。大家都有分:)
jeanswest 2003-05-23
  • 打赏
  • 举报
回复
ShowControlBar只能用在CFrameWnd或派生类中,在CTreeCtrl中好像不行吧。
BinaryPoet 2003-05-23
  • 打赏
  • 举报
回复
ShowControlBar(SB_BOTH,FALSE)
jeanswest 2003-05-23
  • 打赏
  • 举报
回复
没有用。还有人知道吗?
cxjlw 2003-05-21
  • 打赏
  • 举报
回复
再试试下面这个函数:
CWnd::ShowScrollBarSee Also
CWnd Overview | Class Members | Hierarchy Chart | ShowScrollBar | CScrollBar::ShowScrollBar
Shows or hides a scroll bar.

void ShowScrollBar(
UINT nBar,
BOOL bShow = TRUE
);
Parameters
nBar
Specifies whether the scroll bar is a control or part of a window's nonclient area. If it is part of the nonclient area, nBar also indicates whether the scroll bar is positioned horizontally, vertically, or both. It must be one of the following:
SB_BOTH Specifies the horizontal and vertical scroll bars of the window.
SB_HORZ Specifies that the window is a horizontal scroll bar.
SB_VERT Specifies that the window is a vertical scroll bar.
bShow
Specifies whether Windows shows or hides the scroll bar. If this parameter is TRUE, the scroll bar is shown; otherwise the scroll bar is hidden.
cxjlxllw 2003-05-21
  • 打赏
  • 举报
回复
up
cxjlw 2003-05-21
  • 打赏
  • 举报
回复
用下面这个函数看看:
CWnd::EnableScrollBarCtrl See Also
CWnd Overview | Class Members | Hierarchy Chart | CWnd::GetScrollBarCtrl
Enables or disables the scroll bar for this window.

void EnableScrollBarCtrl(
int nBar,
BOOL bEnable = TRUE
);
Parameters
nBar
The scroll-bar identifier.
bEnable
Specifies whether the scroll bar is to be enabled or disabled.
cxjlw 2003-05-21
  • 打赏
  • 举报
回复
这个问题曾经有人问过,而且当时没有人能够准确回答。这个问题确实有些难度,而且比较古怪。为什么只能去掉一个呢?在我看来,你使尽了浑身解数,对一般人来说,也是如此。

你为什么要去掉滚动条呢?目的何在 ?

帮你up!

15,979

社区成员

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

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