各位高手,我想去掉或隐藏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分,多贴送分。

解决方案 »

  1.   

    用下面这个函数看看:
    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. 
      

  2.   

    再试试下面这个函数:
    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. 
      

  3.   

    ShowControlBar只能用在CFrameWnd或派生类中,在CTreeCtrl中好像不行吧。
      

  4.   

    问题我已解决。用这样的方法: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(二进制诗人) 和关心的各位。大家都有分:)